summaryrefslogtreecommitdiff
path: root/src/fe-common/core
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-03-17 01:52:43 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-03-17 01:52:43 +0000
commitc3da7fa8abe93ee39b8913959d6d66bf6b296ed8 (patch)
treef42a855808baa39844a1bff64fab42c9a9e3d1eb /src/fe-common/core
parentaa4a4d40727db29f43622cdfa7cc9eadbb5f839e (diff)
downloadirssi-c3da7fa8abe93ee39b8913959d6d66bf6b296ed8.zip
Hilighting updates. /HILIGHT -color, /SET hilight_color and /SET
hilight_act_color now use %codes for specifying color. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1402 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-common/core')
-rw-r--r--src/fe-common/core/fe-windows.h2
-rw-r--r--src/fe-common/core/formats.c56
-rw-r--r--src/fe-common/core/formats.h6
-rw-r--r--src/fe-common/core/hilight-text.c115
-rw-r--r--src/fe-common/core/hilight-text.h2
-rw-r--r--src/fe-common/core/printtext.c7
-rw-r--r--src/fe-common/core/window-activity.c22
7 files changed, 81 insertions, 129 deletions
diff --git a/src/fe-common/core/fe-windows.h b/src/fe-common/core/fe-windows.h
index 3f710a27..e27897e0 100644
--- a/src/fe-common/core/fe-windows.h
+++ b/src/fe-common/core/fe-windows.h
@@ -42,7 +42,7 @@ typedef struct {
int history_lines, history_over_counter;
int data_level; /* current data level */
- int hilight_color, hilight_bg_color; /* current hilight color */
+ char *hilight_color; /* current hilight color in %format */
time_t last_timestamp; /* When was last timestamp printed */
time_t last_line; /* When was last line printed */
diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c
index a11f959c..eb554973 100644
--- a/src/fe-common/core/formats.c
+++ b/src/fe-common/core/formats.c
@@ -31,6 +31,10 @@
#include "themes.h"
#include "translation.h"
+static const char *format_backs = "04261537";
+static const char *format_fores = "kbgcrmyw";
+static const char *format_boldfores = "KBGCRMYW";
+
static int signal_gui_print_text;
static int hide_text_style;
@@ -57,9 +61,6 @@ int format_find_tag(const char *module, const char *tag)
int format_expand_styles(GString *out, char format)
{
- static const char *backs = "04261537";
- static const char *fores = "kbgcrmyw";
- static const char *boldfores = "KBGCRMYW";
char *p;
switch (format) {
@@ -102,30 +103,30 @@ int format_expand_styles(GString *out, char format)
break;
default:
/* check if it's a background color */
- p = strchr(backs, format);
+ p = strchr(format_backs, format);
if (p != NULL) {
g_string_append_c(out, 4);
g_string_append_c(out, FORMAT_COLOR_NOCHANGE);
- g_string_append_c(out, (char) ((int) (p-backs)+'0'));
+ g_string_append_c(out, (char) ((int) (p-format_backs)+'0'));
break;
}
/* check if it's a foreground color */
if (format == 'p') format = 'm';
- p = strchr(fores, format);
+ p = strchr(format_fores, format);
if (p != NULL) {
g_string_append_c(out, 4);
- g_string_append_c(out, (char) ((int) (p-fores)+'0'));
+ g_string_append_c(out, (char) ((int) (p-format_fores)+'0'));
g_string_append_c(out, FORMAT_COLOR_NOCHANGE);
break;
}
/* check if it's a bold foreground color */
if (format == 'P') format = 'M';
- p = strchr(boldfores, format);
+ p = strchr(format_boldfores, format);
if (p != NULL) {
g_string_append_c(out, 4);
- g_string_append_c(out, (char) (8+(int) (p-boldfores)+'0'));
+ g_string_append_c(out, (char) (8+(int) (p-format_boldfores)+'0'));
g_string_append_c(out, FORMAT_COLOR_NOCHANGE);
break;
}
@@ -212,8 +213,7 @@ void format_create_dest(TEXT_DEST_REC *dest,
window_find_closest(server, target, level);
dest->hilight_priority = 0;
- dest->hilight_color = 0;
- dest->hilight_bg_color = 0;
+ dest->hilight_color = NULL;
}
/* Return length of text part in string (ie. without % codes) */
@@ -283,6 +283,40 @@ int format_real_length(const char *str, int len)
return (int) (str-start);
}
+char *format_string_expand(const char *text)
+{
+ GString *out;
+ char code, *ret;
+
+ g_return_val_if_fail(text != NULL, NULL);
+
+ out = g_string_new(NULL);
+
+ code = 0;
+ while (*text != '\0') {
+ if (code == '%') {
+ /* color code */
+ if (!format_expand_styles(out, *text)) {
+ g_string_append_c(out, '%');
+ g_string_append_c(out, '%');
+ g_string_append_c(out, *text);
+ }
+ code = 0;
+ } else {
+ if (*text == '%')
+ code = *text;
+ else
+ g_string_append_c(out, *text);
+ }
+
+ text++;
+ }
+
+ ret = out->str;
+ g_string_free(out, FALSE);
+ return ret;
+}
+
static char *format_get_text_args(TEXT_DEST_REC *dest,
const char *text, char **arglist)
{
diff --git a/src/fe-common/core/formats.h b/src/fe-common/core/formats.h
index 0dd46489..fde5be01 100644
--- a/src/fe-common/core/formats.h
+++ b/src/fe-common/core/formats.h
@@ -37,7 +37,7 @@ typedef struct {
int level;
int hilight_priority;
- int hilight_color, hilight_bg_color;
+ char *hilight_color;
} TEXT_DEST_REC;
int format_find_tag(const char *module, const char *tag);
@@ -49,6 +49,8 @@ int format_get_length(const char *str);
handles %codes. */
int format_real_length(const char *str, int len);
+char *format_string_expand(const char *text);
+
char *format_get_text(const char *module, WINDOW_REC *window,
void *server, const char *target,
int formatnum, ...);
@@ -96,7 +98,7 @@ char *strip_codes(const char *input);
/* send a fully parsed text string for GUI to print */
void format_send_to_gui(TEXT_DEST_REC *dest, const char *text);
-#define FORMAT_COLOR_NOCHANGE ('0'-1)
+#define FORMAT_COLOR_NOCHANGE ('0'-1) /* don't change this, at least hilighting depends this value */
#define FORMAT_STYLE_SPECIAL 0x60
#define FORMAT_STYLE_UNDERLINE (0x01 + FORMAT_STYLE_SPECIAL)
diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c
index da7b19a7..80ca2d03 100644
--- a/src/fe-common/core/hilight-text.c
+++ b/src/fe-common/core/hilight-text.c
@@ -161,51 +161,6 @@ static HILIGHT_REC *hilight_find(const char *text, char **channels)
return NULL;
}
-/* color name -> mirc color number */
-static int mirc_color_name(const char *name)
-{
- static const char *names[] = {
- "bla dbla", /* black */
- "blu dblu", /* blue */
- "gree dgree", /* green */
- "r dr br lr", /* red .. um.. only one of them. */
- "br dbr dy", /* brown / dark yello */
- "m p dm dp", /* magenta / purple */
- "o", /* orange */
- "y by", /* yellow */
- "bg lg", /* bright green */
- "c dc", /* cyan */
- "bc lc", /* bright cyan */
- "bb lb", /* bright blue */
- "bm bp lm lp", /* bright magenta/purple */
- "dgray dgrey", /* dark grey */
- "grey gray", /* grey */
- "w", /* white */
- NULL
- };
-
- const char *p, *pname;
- int n, ok;
-
- for (n = 0; names[n] != NULL; n++) {
- pname = name; ok = TRUE;
- for (p = names[n]; ; p++) {
- if (*p == ' ' || *p == '\0') {
- if (ok) return n+1;
- if (*p == '\0') break;
-
- ok = TRUE;
- pname = name;
- } else if (toupper((int) *p) == toupper((int) *pname))
- pname++;
- else
- ok = FALSE;
- }
- }
-
- return -1;
-}
-
static int hilight_match_text(HILIGHT_REC *rec, const char *text,
int *match_beg, int *match_end)
{
@@ -291,77 +246,35 @@ HILIGHT_REC *hilight_match(SERVER_REC *server, const char *channel,
return NULL;
}
-static int get_colors(const char *color, int *fg, int *bg)
+static char *hilight_get_act_color(HILIGHT_REC *rec)
{
- const char *p;
-
- if (!is_numeric(color, ','))
- return FALSE;
-
- *fg = atoi(color);
- *bg = -1;
-
- p = strchr(color, ',');
- if (p != NULL) {
- p++;
- if (!is_numeric(p, '\0'))
- return FALSE;
- *bg = atoi(p);
- }
+ g_return_val_if_fail(rec != NULL, NULL);
- return TRUE;
+ return g_strdup(rec->act_color != NULL ? rec->act_color :
+ rec->color != NULL ? rec->color :
+ settings_get_str("hilight_act_color"));
}
-char *hilight_get_color(HILIGHT_REC *rec, int activity)
+static char *hilight_get_color(HILIGHT_REC *rec)
{
const char *color;
- char number[MAX_INT_STRLEN];
- int colornum, fg, bg;
g_return_val_if_fail(rec != NULL, NULL);
- color = activity && rec->act_color != NULL ?
- rec->act_color : rec->color;
- if (color == NULL) {
- color = settings_get_str(activity ? "hilight_act_color" :
- "hilight_color");
- }
-
- if (isalpha((int) *color)) {
- /* color was specified with it's name - try to convert it */
- colornum = mirc_color_name(color);
- if (colornum <= 0) colornum = 16;
-
- ltoa(number, colornum);
- color = number;
- }
+ color = rec->color != NULL ? rec->color :
+ settings_get_str("hilight_color");
- if (get_colors(color, &fg, &bg)) {
- return bg == -1 ? g_strdup_printf("\003%02d", fg) :
- g_strdup_printf("\003%d,%02d", fg, bg);
- }
- return g_strdup(color);
+ return format_string_expand(color);
}
static void hilight_update_text_dest(TEXT_DEST_REC *dest, HILIGHT_REC *rec)
{
- char *color, *bgcolor;
-
dest->level |= MSGLEVEL_HILIGHT;
if (rec->priority > 0)
dest->hilight_priority = rec->priority;
- color = hilight_get_color(rec, TRUE);
- if (*color == 3) {
- dest->hilight_color = atoi(color+1);
- bgcolor = color+1;
- while (*bgcolor != ',' && *bgcolor != '\0')
- bgcolor++;
- dest->hilight_bg_color = *bgcolor != ',' ? -1 :
- atoi(bgcolor+1);
- }
- g_free(color);
+ dest->hilight_color = hilight_get_act_color(rec);
}
static void sig_print_text_stripped(TEXT_DEST_REC *dest, const char *str)
@@ -413,7 +326,7 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *str)
if (next_line_hilight == NULL)
return;
- color = hilight_get_color(next_line_hilight, FALSE);
+ color = hilight_get_color(next_line_hilight);
next_hilight_len = next_hilight_end-next_hilight_start;
if (!next_line_hilight->word) {
@@ -482,7 +395,7 @@ char *hilight_match_nick(SERVER_REC *server, const char *channel,
rec = hilight_match(server, channel, nick, address,
level, msg, NULL, NULL);
color = rec == NULL || !rec->nick ? NULL :
- hilight_get_color(rec, FALSE);
+ hilight_get_color(rec);
next_nick_hilight = rec;
return color;
@@ -747,8 +660,8 @@ static void read_settings(void)
void hilight_text_init(void)
{
- settings_add_str("lookandfeel", "hilight_color", "8");
- settings_add_str("lookandfeel", "hilight_act_color", "13");
+ settings_add_str("lookandfeel", "hilight_color", "%Y");
+ settings_add_str("lookandfeel", "hilight_act_color", "%M");
settings_add_str("lookandfeel", "hilight_level", "PUBLIC DCCMSGS");
next_nick_hilight = NULL;
diff --git a/src/fe-common/core/hilight-text.h b/src/fe-common/core/hilight-text.h
index 47629717..92093bb1 100644
--- a/src/fe-common/core/hilight-text.h
+++ b/src/fe-common/core/hilight-text.h
@@ -34,8 +34,6 @@ HILIGHT_REC *hilight_match(SERVER_REC *server, const char *channel,
int level, const char *str,
int *match_beg, int *match_end);
-char *hilight_get_color(HILIGHT_REC *rec, int activity);
-
char *hilight_match_nick(SERVER_REC *server, const char *channel,
const char *nick, const char *address,
int level, const char *msg);
diff --git a/src/fe-common/core/printtext.c b/src/fe-common/core/printtext.c
index 7ee65626..0b4c1d0d 100644
--- a/src/fe-common/core/printtext.c
+++ b/src/fe-common/core/printtext.c
@@ -391,6 +391,11 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *text)
signal_emit_id(signal_print_text_finished, 1, dest->window);
}
+static void sig_print_text_free(TEXT_DEST_REC *dest, const char *text)
+{
+ g_free_and_null(dest->hilight_color);
+}
+
void printtext_multiline(void *server, const char *target, int level,
const char *format, const char *text)
{
@@ -438,6 +443,7 @@ void printtext_init(void)
read_settings();
signal_add("print text", (SIGNAL_FUNC) sig_print_text);
+ signal_add_last("print text", (SIGNAL_FUNC) sig_print_text_free);
signal_add("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
}
@@ -445,6 +451,7 @@ void printtext_init(void)
void printtext_deinit(void)
{
signal_remove("print text", (SIGNAL_FUNC) sig_print_text);
+ signal_remove("print text", (SIGNAL_FUNC) sig_print_text_free);
signal_remove("gui dialog", (SIGNAL_FUNC) sig_gui_dialog);
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
}
diff --git a/src/fe-common/core/window-activity.c b/src/fe-common/core/window-activity.c
index c928a498..3e4cd80c 100644
--- a/src/fe-common/core/window-activity.c
+++ b/src/fe-common/core/window-activity.c
@@ -36,15 +36,15 @@ static char **hide_targets;
static int hide_level, msg_level, hilight_level;
static void window_activity(WINDOW_REC *window, int data_level,
- int hilight_color, int hilight_bg_color)
+ const char *hilight_color)
{
int old_data_level;
old_data_level = window->data_level;
if (data_level == 0 || window->data_level < data_level) {
window->data_level = data_level;
- window->hilight_color = hilight_color;
- window->hilight_bg_color = hilight_bg_color;
+ g_free_not_null(window->hilight_color);
+ window->hilight_color = g_strdup(hilight_color);
signal_emit("window hilight", 1, window);
}
@@ -53,15 +53,15 @@ static void window_activity(WINDOW_REC *window, int data_level,
}
static void window_item_activity(WI_ITEM_REC *item, int data_level,
- int hilight_color, int hilight_bg_color)
+ const char *hilight_color)
{
int old_data_level;
old_data_level = item->data_level;
if (data_level == 0 || item->data_level < data_level) {
item->data_level = data_level;
- item->hilight_color = hilight_color;
- item->hilight_bg_color = hilight_bg_color;
+ g_free_not_null(item->hilight_color);
+ item->hilight_color = g_strdup(hilight_color);
signal_emit("window item hilight", 1, item);
}
@@ -96,12 +96,10 @@ static void sig_hilight_text(TEXT_DEST_REC *dest, const char *msg)
item = window_item_find(dest->server, dest->target);
if (item != NULL) {
window_item_activity(item, data_level,
- dest->hilight_color,
- dest->hilight_bg_color);
+ dest->hilight_color);
}
}
- window_activity(dest->window, data_level,
- dest->hilight_color, dest->hilight_bg_color);
+ window_activity(dest->window, data_level, dest->hilight_color);
}
static void sig_dehilight_window(WINDOW_REC *window)
@@ -111,9 +109,9 @@ static void sig_dehilight_window(WINDOW_REC *window)
g_return_if_fail(window != NULL);
if (window->data_level != 0) {
- window_activity(window, 0, 0, 0);
+ window_activity(window, 0, NULL);
for (tmp = window->items; tmp != NULL; tmp = tmp->next)
- window_item_activity(tmp->data, 0, 0, 0);
+ window_item_activity(tmp->data, 0, NULL);
}
}