diff --git a/docs/formats.txt b/docs/formats.txt index 88f67b52..6b6cf354 100644 --- a/docs/formats.txt +++ b/docs/formats.txt @@ -1,5 +1,5 @@ - Irssi's colors that you can use in text formats etc. : + Irssi's colors that you can use in text formats, hilights, etc. : text text background --------------------------------------------------------------------- @@ -23,8 +23,8 @@ In .theme files %n works a bit differently. See default.theme for more information. - MIRC colors that you can use when writing text to channel and with - hilighting text: + + MIRC colors that you can use when writing text to channel: foreground (fg) background (bg) ------------------------------------------------------- diff --git a/docs/help/in/hilight.in b/docs/help/in/hilight.in index 0b57fd22..2d084fad 100644 --- a/docs/help/in/hilight.in +++ b/docs/help/in/hilight.in @@ -6,9 +6,8 @@ -word: must match to full words -nick: Hilight only the nick, not the whole line (default) -nonick: Hilight the whole line with the hilight color. - -color: Print the message with , it can be either - numeric MIRC color (see docs/formats.txt) or - a named english color + -color: Print the message with . color is in %code format + (see docs/formats.txt) -level: Match only for messages, default is publics,msgs,notices,actions -channels: Match only in @@ -18,8 +17,8 @@ Examples: Hilight lines that have "mynick" word: /HILIGHT mynick -Hilight lines that were written by nicks from *.fi - /HILIGHT -mask *!*@*.fi +Hilight lines that were written by nicks from *.fi with bold green + /HILIGHT -color %G -mask *!*@*.fi For regular expressions, see `man 7 regex`. diff --git a/src/core/window-item-rec.h b/src/core/window-item-rec.h index 134726c2..5c09a5b0 100644 --- a/src/core/window-item-rec.h +++ b/src/core/window-item-rec.h @@ -10,6 +10,6 @@ char *name; time_t createtime; int data_level; -int hilight_color, hilight_bg_color; +char *hilight_color; #undef STRUCT_SERVER_REC 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; + g_return_val_if_fail(rec != NULL, NULL); - 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); - } - - 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"); - } + color = rec->color != NULL ? rec->color : + settings_get_str("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; - } - - 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); } } diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c index b7db9d24..a11b6bbb 100644 --- a/src/fe-text/statusbar-items.c +++ b/src/fe-text/statusbar-items.c @@ -226,20 +226,14 @@ static char *get_activity_list(int normal, int hilight) g_string_append(str, "%W"); break; default: - /*FIXME:if (window->hilight_color > 0) { - int bg; - - bg = window->hilight_bg_color == -1 ? - sbar_color_background : - (window->hilight_bg_color << 4); - set_color(stdscr, bg | mirc_colors[window->hilight_color%16]); - g_string_append(str, "%M"); - } else */{ - g_string_append(str, "%M"); - } + g_string_append(str, window->hilight_color == NULL ? + "%M" : window->hilight_color); break; } - g_string_sprintfa(str, "%d", window->refnum); + g_string_sprintfa(str, "%d", window->refnum); + + /* make sure the background is returned to default */ + g_string_append(str, "%n"); } ret = str->len == 0 ? NULL : str->str; diff --git a/src/perl/perl-common.c b/src/perl/perl-common.c index 7ade85c9..02434d75 100644 --- a/src/perl/perl-common.c +++ b/src/perl/perl-common.c @@ -239,7 +239,7 @@ void perl_window_item_fill_hash(HV *hv, WI_ITEM_REC *item) hv_store(hv, "createtime", 10, newSViv(item->createtime), 0); hv_store(hv, "data_level", 8, newSViv(item->data_level), 0); - hv_store(hv, "hilight_color", 10, newSViv(item->hilight_color), 0); + hv_store(hv, "hilight_color", 10, new_pv(item->hilight_color), 0); } void perl_channel_fill_hash(HV *hv, CHANNEL_REC *channel) diff --git a/src/perl/perl-fe.c b/src/perl/perl-fe.c index 503db4b6..5584ca85 100644 --- a/src/perl/perl-fe.c +++ b/src/perl/perl-fe.c @@ -61,7 +61,7 @@ static void perl_window_fill_hash(HV *hv, WINDOW_REC *window) hv_store(hv, "level", 5, newSViv(window->level), 0); hv_store(hv, "data_level", 8, newSViv(window->data_level), 0); - hv_store(hv, "hilight_color", 10, newSViv(window->hilight_color), 0); + hv_store(hv, "hilight_color", 10, new_pv(window->hilight_color), 0); hv_store(hv, "last_timestamp", 14, newSViv(window->last_timestamp), 0); hv_store(hv, "last_line", 9, newSViv(window->last_line), 0); }