mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 03:33:12 +02:00
core: add variable ${highlight} in option weechat.look.buffer_time_format (issue #2079)
This commit is contained in:
@@ -3321,11 +3321,18 @@ config_weechat_init_options ()
|
||||
"strftime for date/time specifiers, extra specifiers are "
|
||||
"supported, see function util_strftimeval in Plugin API reference) "
|
||||
"(note: content is evaluated, so you can use colors with format "
|
||||
"\"${color:xxx}\", see /help eval); "
|
||||
"\"${color:xxx}\", see /help eval); variable \"${highlight}\" "
|
||||
"can be used in a condition to have a format specific to lines "
|
||||
"with highlight; "
|
||||
"for example time using grayscale: "
|
||||
"\"${color:252}%H${color:243}%M${color:237}%S\", "
|
||||
"the same with milliseconds: "
|
||||
"\"${color:252}%H${color:243}%M${color:237}%S.%.3\""),
|
||||
"\"${color:252}%H${color:243}%M${color:237}%S.%.3\", "
|
||||
"red background in case of highlight: "
|
||||
"\"${if:${highlight}?${color:,red}}%H:%M:%S\", "
|
||||
"red background in case of highlight with grayscale: "
|
||||
"${if:${highlight}?${color:yellow,124}%H${color:187}%M${color:181}%S.%.3:"
|
||||
"${color:252}%H${color:243}%M${color:237}%S.%.3}"),
|
||||
NULL, 0, 0, "%H:%M:%S", NULL, 0,
|
||||
NULL, NULL, NULL,
|
||||
&config_change_buffer_time_format, NULL, NULL,
|
||||
|
||||
+14
-4
@@ -390,12 +390,13 @@ gui_chat_get_word_info (struct t_gui_window *window,
|
||||
*/
|
||||
|
||||
char *
|
||||
gui_chat_get_time_string (time_t date, int date_usec)
|
||||
gui_chat_get_time_string (time_t date, int date_usec, int highlight)
|
||||
{
|
||||
char text_time[128], text_time2[(128*3)+16], text_time_char[2];
|
||||
char *text_with_color;
|
||||
int i, time_first_digit, time_last_digit, last_color;
|
||||
struct timeval tv;
|
||||
struct t_hashtable *extra_vars;
|
||||
|
||||
if (date == 0)
|
||||
return NULL;
|
||||
@@ -413,7 +414,15 @@ gui_chat_get_time_string (time_t date, int date_usec)
|
||||
|
||||
if (strstr (text_time, "${"))
|
||||
{
|
||||
text_with_color = eval_expression (text_time, NULL, NULL, NULL);
|
||||
extra_vars = hashtable_new (32,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
NULL, NULL);
|
||||
if (extra_vars)
|
||||
hashtable_set (extra_vars, "highlight", (highlight) ? "1" : "0");
|
||||
text_with_color = eval_expression (text_time, NULL, extra_vars, NULL);
|
||||
if (extra_vars)
|
||||
hashtable_free (extra_vars);
|
||||
if (text_with_color)
|
||||
{
|
||||
if (strcmp (text_time, text_with_color) != 0)
|
||||
@@ -510,7 +519,7 @@ gui_chat_get_time_length ()
|
||||
|
||||
length = 0;
|
||||
gettimeofday (&tv_now, NULL);
|
||||
text_time = gui_chat_get_time_string (tv_now.tv_sec, tv_now.tv_usec);
|
||||
text_time = gui_chat_get_time_string (tv_now.tv_sec, tv_now.tv_usec, 0);
|
||||
|
||||
if (text_time)
|
||||
{
|
||||
@@ -543,7 +552,8 @@ gui_chat_change_time_format ()
|
||||
free (ptr_line->data->str_time);
|
||||
ptr_line->data->str_time = gui_chat_get_time_string (
|
||||
ptr_line->data->date,
|
||||
ptr_line->data->date_usec);
|
||||
ptr_line->data->date_usec,
|
||||
ptr_line->data->highlight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -90,7 +90,8 @@ extern void gui_chat_get_word_info (struct t_gui_window *window,
|
||||
int *word_end_offset,
|
||||
int *word_length_with_spaces,
|
||||
int *word_length);
|
||||
extern char *gui_chat_get_time_string (time_t date, int date_usec);
|
||||
extern char *gui_chat_get_time_string (time_t date, int date_usec,
|
||||
int highlight);
|
||||
extern int gui_chat_get_time_length ();
|
||||
extern void gui_chat_change_time_format ();
|
||||
extern int gui_chat_buffer_valid (struct t_gui_buffer *buffer,
|
||||
|
||||
+34
-29
@@ -1528,7 +1528,6 @@ gui_line_new (struct t_gui_buffer *buffer, int y,
|
||||
new_line->data->date_usec = date_usec;
|
||||
new_line->data->date_printed = date_printed;
|
||||
new_line->data->date_usec_printed = date_usec_printed;
|
||||
new_line->data->str_time = gui_chat_get_time_string (date, date_usec);
|
||||
gui_line_tags_alloc (new_line->data, tags);
|
||||
new_line->data->refresh_needed = 0;
|
||||
new_line->data->prefix = (prefix) ?
|
||||
@@ -1540,6 +1539,8 @@ gui_line_new (struct t_gui_buffer *buffer, int y,
|
||||
gui_line_set_highlight (new_line, max_notify_level);
|
||||
if (new_line->data->highlight && (new_line->data->notify_level >= 0))
|
||||
new_line->data->notify_level = GUI_HOTLIST_HIGHLIGHT;
|
||||
new_line->data->str_time = gui_chat_get_time_string (
|
||||
date, date_usec, new_line->data->highlight);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1642,6 +1643,30 @@ gui_line_hook_update (struct t_gui_line *line,
|
||||
}
|
||||
}
|
||||
|
||||
ptr_value2 = hashtable_get (hashtable2, "notify_level");
|
||||
if (ptr_value2)
|
||||
{
|
||||
error = NULL;
|
||||
value = strtol (ptr_value2, &error, 10);
|
||||
if (error && !error[0] && (value >= -1) && (value <= GUI_HOTLIST_MAX))
|
||||
{
|
||||
notify_level_updated = 1;
|
||||
line->data->notify_level = value;
|
||||
}
|
||||
}
|
||||
|
||||
ptr_value2 = hashtable_get (hashtable2, "highlight");
|
||||
if (ptr_value2)
|
||||
{
|
||||
error = NULL;
|
||||
value = strtol (ptr_value2, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
highlight_updated = 1;
|
||||
line->data->highlight = (value) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
ptr_value2 = hashtable_get (hashtable2, "date");
|
||||
if (ptr_value2)
|
||||
{
|
||||
@@ -1654,7 +1679,8 @@ gui_line_hook_update (struct t_gui_line *line,
|
||||
free (line->data->str_time);
|
||||
line->data->str_time = gui_chat_get_time_string (
|
||||
line->data->date,
|
||||
line->data->date_usec);
|
||||
line->data->date_usec,
|
||||
line->data->highlight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1670,7 +1696,8 @@ gui_line_hook_update (struct t_gui_line *line,
|
||||
free (line->data->str_time);
|
||||
line->data->str_time = gui_chat_get_time_string (
|
||||
line->data->date,
|
||||
line->data->date_usec);
|
||||
line->data->date_usec,
|
||||
line->data->highlight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1710,30 +1737,6 @@ gui_line_hook_update (struct t_gui_line *line,
|
||||
gui_line_tags_alloc (line->data, ptr_value2);
|
||||
}
|
||||
|
||||
ptr_value2 = hashtable_get (hashtable2, "notify_level");
|
||||
if (ptr_value2)
|
||||
{
|
||||
error = NULL;
|
||||
value = strtol (ptr_value2, &error, 10);
|
||||
if (error && !error[0] && (value >= -1) && (value <= GUI_HOTLIST_MAX))
|
||||
{
|
||||
notify_level_updated = 1;
|
||||
line->data->notify_level = value;
|
||||
}
|
||||
}
|
||||
|
||||
ptr_value2 = hashtable_get (hashtable2, "highlight");
|
||||
if (ptr_value2)
|
||||
{
|
||||
error = NULL;
|
||||
value = strtol (ptr_value2, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
highlight_updated = 1;
|
||||
line->data->highlight = (value) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
ptr_value = hashtable_get (hashtable, "prefix");
|
||||
ptr_value2 = hashtable_get (hashtable2, "prefix");
|
||||
if (ptr_value2 && (!ptr_value || (strcmp (ptr_value, ptr_value2) != 0)))
|
||||
@@ -2218,7 +2221,8 @@ gui_line_hdata_line_data_update_cb (void *data,
|
||||
free (line_data->str_time);
|
||||
line_data->str_time = gui_chat_get_time_string (
|
||||
line_data->date,
|
||||
line_data->date_usec);
|
||||
line_data->date_usec,
|
||||
line_data->highlight);
|
||||
rc++;
|
||||
update_coords = 1;
|
||||
}
|
||||
@@ -2234,7 +2238,8 @@ gui_line_hdata_line_data_update_cb (void *data,
|
||||
free (line_data->str_time);
|
||||
line_data->str_time = gui_chat_get_time_string (
|
||||
line_data->date,
|
||||
line_data->date_usec);
|
||||
line_data->date_usec,
|
||||
line_data->highlight);
|
||||
rc++;
|
||||
update_coords = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user