forked from PsychoticNinja/irssi
store the hilight result in the meta table and apply it during the "gui render line text" signal
This commit is contained in:
parent
8d314eadf1
commit
5953b675b9
@ -323,6 +323,71 @@ void hilight_update_text_dest(TEXT_DEST_REC *dest, HILIGHT_REC *rec)
|
|||||||
|
|
||||||
static void hilight_print(int index, HILIGHT_REC *rec);
|
static void hilight_print(int index, HILIGHT_REC *rec);
|
||||||
|
|
||||||
|
static void sig_render_line_text(TEXT_DEST_REC *dest, GString *str, LINE_INFO_META_REC *meta)
|
||||||
|
{
|
||||||
|
char *color, *tmp, *tmp2;
|
||||||
|
|
||||||
|
if (meta == NULL || meta->hash == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
color = g_hash_table_lookup(meta->hash, "hilight-color");
|
||||||
|
|
||||||
|
if ((tmp = g_hash_table_lookup(meta->hash, "hilight-line")) != NULL) {
|
||||||
|
/* hilight whole line */
|
||||||
|
|
||||||
|
tmp = strip_codes(str->str);
|
||||||
|
|
||||||
|
color = format_string_expand(
|
||||||
|
color != NULL ? color : settings_get_str("hilight_color"), NULL);
|
||||||
|
|
||||||
|
g_string_truncate(str, 0);
|
||||||
|
g_string_append(str, color);
|
||||||
|
g_string_append(str, tmp);
|
||||||
|
|
||||||
|
g_free(color);
|
||||||
|
g_free(tmp);
|
||||||
|
} else if ((tmp = g_hash_table_lookup(meta->hash, "hilight-start")) != NULL &&
|
||||||
|
(tmp2 = g_hash_table_lookup(meta->hash, "hilight-end")) != NULL) {
|
||||||
|
/* hilight part of the line */
|
||||||
|
int hilight_start, hilight_end;
|
||||||
|
int pos, color_pos, color_len;
|
||||||
|
char *middle;
|
||||||
|
GString *str2;
|
||||||
|
|
||||||
|
hilight_start = atoi(tmp);
|
||||||
|
hilight_end = atoi(tmp2);
|
||||||
|
|
||||||
|
/* start of the line */
|
||||||
|
pos = strip_real_length(str->str, hilight_start, NULL, NULL);
|
||||||
|
|
||||||
|
str2 = g_string_new_len(str->str, pos);
|
||||||
|
|
||||||
|
/* color */
|
||||||
|
color = format_string_expand(
|
||||||
|
color != NULL ? color : settings_get_str("hilight_color"), NULL);
|
||||||
|
g_string_append(str2, color);
|
||||||
|
g_free(color);
|
||||||
|
|
||||||
|
/* middle of the line, stripped */
|
||||||
|
middle = strip_codes(str->str + pos);
|
||||||
|
g_string_append_len(str2, middle, hilight_end - hilight_start);
|
||||||
|
g_free(middle);
|
||||||
|
|
||||||
|
/* end of the line */
|
||||||
|
pos = strip_real_length(str->str, hilight_end, &color_pos, &color_len);
|
||||||
|
if (color_pos > 0) {
|
||||||
|
g_string_append_len(str2, str->str + color_pos, color_len);
|
||||||
|
} else {
|
||||||
|
/* no colors in line, change back to default */
|
||||||
|
g_string_append_c(str2, 4);
|
||||||
|
g_string_append_c(str2, FORMAT_STYLE_DEFAULTS);
|
||||||
|
}
|
||||||
|
g_string_append(str2, str->str + pos);
|
||||||
|
|
||||||
|
g_string_assign(str, g_string_free(str2, FALSE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void sig_print_text(TEXT_DEST_REC *dest, const char *text,
|
static void sig_print_text(TEXT_DEST_REC *dest, const char *text,
|
||||||
const char *stripped)
|
const char *stripped)
|
||||||
{
|
{
|
||||||
@ -372,38 +437,47 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *text,
|
|||||||
char *tmp = strip_codes(text);
|
char *tmp = strip_codes(text);
|
||||||
newstr = g_strconcat(color, tmp, NULL);
|
newstr = g_strconcat(color, tmp, NULL);
|
||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
|
|
||||||
|
format_dest_meta_stash(dest, "hilight-line", "\001");
|
||||||
} else {
|
} else {
|
||||||
/* hilight part of the line */
|
/* hilight part of the line */
|
||||||
GString *tmp;
|
GString *str;
|
||||||
char *middle;
|
char *middle, *tmp;
|
||||||
int pos, color_pos, color_len;
|
int pos, color_pos, color_len;
|
||||||
|
|
||||||
/* start of the line */
|
/* start of the line */
|
||||||
pos = strip_real_length(text, hilight_start, NULL, NULL);
|
pos = strip_real_length(text, hilight_start, NULL, NULL);
|
||||||
tmp = g_string_new_len(text, pos);
|
str = g_string_new_len(text, pos);
|
||||||
|
|
||||||
/* color */
|
/* color */
|
||||||
g_string_append(tmp, color);
|
g_string_append(str, color);
|
||||||
|
|
||||||
/* middle of the line, stripped */
|
/* middle of the line, stripped */
|
||||||
middle = strip_codes(text + pos);
|
middle = strip_codes(text + pos);
|
||||||
g_string_append_len(tmp, middle, hilight_len);
|
g_string_append_len(str, middle, hilight_len);
|
||||||
g_free(middle);
|
g_free(middle);
|
||||||
|
|
||||||
/* end of the line */
|
/* end of the line */
|
||||||
pos = strip_real_length(text, hilight_end,
|
pos = strip_real_length(text, hilight_end,
|
||||||
&color_pos, &color_len);
|
&color_pos, &color_len);
|
||||||
if (color_pos > 0) {
|
if (color_pos > 0) {
|
||||||
g_string_append_len(tmp, text + color_pos, color_len);
|
g_string_append_len(str, text + color_pos, color_len);
|
||||||
} else {
|
} else {
|
||||||
/* no colors in line, change back to default */
|
/* no colors in line, change back to default */
|
||||||
g_string_append_c(tmp, 4);
|
g_string_append_c(str, 4);
|
||||||
g_string_append_c(tmp, FORMAT_STYLE_DEFAULTS);
|
g_string_append_c(str, FORMAT_STYLE_DEFAULTS);
|
||||||
}
|
}
|
||||||
g_string_append(tmp, text + pos);
|
g_string_append(str, text + pos);
|
||||||
|
|
||||||
newstr = tmp->str;
|
newstr = str->str;
|
||||||
g_string_free(tmp, FALSE);
|
g_string_free(str, FALSE);
|
||||||
|
|
||||||
|
format_dest_meta_stash(dest, "hilight-start",
|
||||||
|
tmp = g_strdup_printf("%d", hilight_start));
|
||||||
|
g_free(tmp);
|
||||||
|
format_dest_meta_stash(dest, "hilight-end",
|
||||||
|
tmp = g_strdup_printf("%d", hilight_end));
|
||||||
|
g_free(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
signal_emit("print text", 3, dest, newstr, stripped);
|
signal_emit("print text", 3, dest, newstr, stripped);
|
||||||
@ -721,6 +795,7 @@ void hilight_text_init(void)
|
|||||||
read_hilight_config();
|
read_hilight_config();
|
||||||
|
|
||||||
signal_add_first("print text", (SIGNAL_FUNC) sig_print_text);
|
signal_add_first("print text", (SIGNAL_FUNC) sig_print_text);
|
||||||
|
signal_add("gui render line text", (SIGNAL_FUNC) sig_render_line_text);
|
||||||
signal_add("setup reread", (SIGNAL_FUNC) read_hilight_config);
|
signal_add("setup reread", (SIGNAL_FUNC) read_hilight_config);
|
||||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||||
|
|
||||||
@ -735,6 +810,7 @@ void hilight_text_deinit(void)
|
|||||||
nickmatch_deinit(nickmatch);
|
nickmatch_deinit(nickmatch);
|
||||||
|
|
||||||
signal_remove("print text", (SIGNAL_FUNC) sig_print_text);
|
signal_remove("print text", (SIGNAL_FUNC) sig_print_text);
|
||||||
|
signal_remove("gui render line text", (SIGNAL_FUNC) sig_render_line_text);
|
||||||
signal_remove("setup reread", (SIGNAL_FUNC) read_hilight_config);
|
signal_remove("setup reread", (SIGNAL_FUNC) read_hilight_config);
|
||||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
TEXT_BUFFER_REC *color_buf;
|
TEXT_BUFFER_REC *color_buf;
|
||||||
gboolean scrollback_format;
|
gboolean scrollback_format;
|
||||||
gboolean show_server_time;
|
gboolean show_server_time;
|
||||||
|
int signal_gui_render_line_text;
|
||||||
|
|
||||||
#if GLIB_CHECK_VERSION(2, 56, 0)
|
#if GLIB_CHECK_VERSION(2, 56, 0)
|
||||||
/* nothing */
|
/* nothing */
|
||||||
@ -363,7 +364,7 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line, gboolean
|
|||||||
int formatnum;
|
int formatnum;
|
||||||
TEXT_BUFFER_FORMAT_REC *format_rec;
|
TEXT_BUFFER_FORMAT_REC *format_rec;
|
||||||
LINE_INFO_META_REC *meta;
|
LINE_INFO_META_REC *meta;
|
||||||
char *str;
|
char *tmp2;
|
||||||
|
|
||||||
curr = line;
|
curr = line;
|
||||||
line = NULL;
|
line = NULL;
|
||||||
@ -396,6 +397,8 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line, gboolean
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (text != NULL && *text != '\0') {
|
if (text != NULL && *text != '\0') {
|
||||||
|
GString *str;
|
||||||
|
|
||||||
reference_time = curr->info.time;
|
reference_time = curr->info.time;
|
||||||
if (show_server_time && meta != NULL && meta->server_time != 0) {
|
if (show_server_time && meta != NULL && meta->server_time != 0) {
|
||||||
current_time = meta->server_time;
|
current_time = meta->server_time;
|
||||||
@ -403,18 +406,27 @@ char *textbuffer_line_get_text(TEXT_BUFFER_REC *buffer, LINE_REC *line, gboolean
|
|||||||
current_time = curr->info.time;
|
current_time = curr->info.time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str = g_string_new(text);
|
||||||
|
signal_emit_id(signal_gui_render_line_text, 3, &dest, str, meta);
|
||||||
|
if (g_strcmp0(text, str->str) == 0) {
|
||||||
|
g_string_free(str, TRUE);
|
||||||
|
} else {
|
||||||
|
g_free(text);
|
||||||
|
text = g_string_free(str, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
tmp = format_get_level_tag(theme, &dest);
|
tmp = format_get_level_tag(theme, &dest);
|
||||||
str = !theme->info_eol ? format_add_linestart(text, tmp) :
|
tmp2 = !theme->info_eol ? format_add_linestart(text, tmp) :
|
||||||
format_add_lineend(text, tmp);
|
format_add_lineend(text, tmp);
|
||||||
g_free_not_null(tmp);
|
g_free_not_null(tmp);
|
||||||
g_free_not_null(text);
|
g_free_not_null(text);
|
||||||
text = str;
|
text = tmp2;
|
||||||
tmp = format_get_line_start(theme, &dest, current_time);
|
tmp = format_get_line_start(theme, &dest, current_time);
|
||||||
str = !theme->info_eol ? format_add_linestart(text, tmp) :
|
tmp2 = !theme->info_eol ? format_add_linestart(text, tmp) :
|
||||||
format_add_lineend(text, tmp);
|
format_add_lineend(text, tmp);
|
||||||
g_free_not_null(tmp);
|
g_free_not_null(tmp);
|
||||||
g_free_not_null(text);
|
g_free_not_null(text);
|
||||||
text = str;
|
text = tmp2;
|
||||||
/* str = g_strconcat(text, "\n", NULL); */
|
/* str = g_strconcat(text, "\n", NULL); */
|
||||||
/* g_free(text); */
|
/* g_free(text); */
|
||||||
|
|
||||||
@ -447,6 +459,8 @@ static void read_settings(void)
|
|||||||
|
|
||||||
void textbuffer_formats_init(void)
|
void textbuffer_formats_init(void)
|
||||||
{
|
{
|
||||||
|
signal_gui_render_line_text = signal_get_uniq_id("gui render line text");
|
||||||
|
|
||||||
settings_add_bool("lookandfeel", "scrollback_format", TRUE);
|
settings_add_bool("lookandfeel", "scrollback_format", TRUE);
|
||||||
settings_add_bool("lookandfeel", "show_server_time", FALSE);
|
settings_add_bool("lookandfeel", "show_server_time", FALSE);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user