diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2013-08-25 09:39:59 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2013-08-25 09:39:59 +0200 |
commit | 03b6b4c1cf77f1fccb92295c4528406245382c69 (patch) | |
tree | de390f78d7132a9b6aef4c5eaca39ca259486124 /src | |
parent | 73f2c2c48833568f0eb21b73ca8fed5603643d93 (diff) | |
download | weechat-03b6b4c1cf77f1fccb92295c4528406245382c69.zip |
core: display day change message dynamically (do not store it as a line in buffer) (task #12775)
Changes in options:
- rename option weechat.look.day_change_time_format to weechat.look.day_change_message
(color codes are allowed in this option)
- new option weechat.color.chat_day_change.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-config.c | 56 | ||||
-rw-r--r-- | src/core/wee-config.h | 3 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-chat.c | 173 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-color.c | 1 | ||||
-rw-r--r-- | src/gui/gui-color.h | 1 | ||||
-rw-r--r-- | src/plugins/logger/logger.c | 43 |
6 files changed, 179 insertions, 98 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c index e06a945e3..f7da1470b 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -99,7 +99,7 @@ struct t_config_option *config_look_color_real_white; struct t_config_option *config_look_command_chars; struct t_config_option *config_look_confirm_quit; struct t_config_option *config_look_day_change; -struct t_config_option *config_look_day_change_time_format; +struct t_config_option *config_look_day_change_message; struct t_config_option *config_look_eat_newline_glitch; struct t_config_option *config_look_emphasized_attributes; struct t_config_option *config_look_highlight; @@ -170,6 +170,7 @@ struct t_config_option *config_color_chat; struct t_config_option *config_color_chat_bg; struct t_config_option *config_color_chat_buffer; struct t_config_option *config_color_chat_channel; +struct t_config_option *config_color_chat_day_change; struct t_config_option *config_color_chat_delimiters; struct t_config_option *config_color_chat_inactive_buffer; struct t_config_option *config_color_chat_inactive_window; @@ -776,7 +777,9 @@ config_change_plugin_extension (void *data, struct t_config_option *option) } /* - * Displays message "Day changed to xxx". + * Timer called each minute: checks if the day has changed, and if yes: + * - refreshes screen (if needed) + * - sends signal "day_changed" */ int @@ -785,8 +788,7 @@ config_day_change_timer_cb (void *data, int remaining_calls) struct timeval tv_time; struct tm *local_time; int new_mday; - char text_time[256], *text_time2; - struct t_gui_buffer *ptr_buffer; + char str_time[256]; /* make C compiler happy */ (void) data; @@ -801,30 +803,16 @@ config_day_change_timer_cb (void *data, int remaining_calls) { if (CONFIG_BOOLEAN(config_look_day_change)) { - strftime (text_time, sizeof (text_time), - CONFIG_STRING(config_look_day_change_time_format), - local_time); - text_time2 = string_iconv_to_internal (NULL, text_time); - gui_add_hotlist = 0; - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->type == GUI_BUFFER_TYPE_FORMATTED) - { - gui_chat_printf (ptr_buffer, - _("\t\tDay changed to %s"), - (text_time2) ? - text_time2 : text_time); - } - } - if (text_time2) - free (text_time2); - gui_add_hotlist = 1; + /* + * refresh all windows so that the message with new day will be + * displayed + */ + gui_window_ask_refresh (1); } /* send signal "day_changed" */ - strftime (text_time, sizeof (text_time), "%Y-%m-%d", local_time); - hook_signal_send ("day_changed", WEECHAT_HOOK_SIGNAL_STRING, text_time); + strftime (str_time, sizeof (str_time), "%Y-%m-%d", local_time); + hook_signal_send ("day_changed", WEECHAT_HOOK_SIGNAL_STRING, str_time); } config_day_change_old_day = new_mday; @@ -2079,13 +2067,13 @@ config_weechat_init_options () weechat_config_file, ptr_section, "day_change", "boolean", N_("display special message when day changes"), - NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - config_look_day_change_time_format = config_file_new_option ( + NULL, 0, 0, "on", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); + config_look_day_change_message = config_file_new_option ( weechat_config_file, ptr_section, - "day_change_time_format", "string", - N_("time format for date displayed when day changed (see man strftime " - "for date/time specifiers)"), - NULL, 0, 0, "%a, %d %b %Y", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); + "day_change_message", "string", + N_("message displayed when the day has changed (see man strftime for " + "date/time specifiers) (note: content is evaluated, see /help eval)"), + NULL, 0, 0, "-- %a, %d %b %Y --", NULL, 0, NULL, NULL, &config_change_buffers, NULL, NULL, NULL); config_look_eat_newline_glitch = config_file_new_option ( weechat_config_file, ptr_section, "eat_newline_glitch", "boolean", @@ -2567,6 +2555,12 @@ config_weechat_init_options () N_("text color for channel names"), NULL, GUI_COLOR_CHAT_CHANNEL, 0, "white", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); + config_color_chat_day_change = config_file_new_option ( + weechat_config_file, ptr_section, + "chat_day_change", "color", + N_("text color for message displayed when the day has changed"), + NULL, GUI_COLOR_CHAT_DAY_CHANGE, 0, "cyan", NULL, 0, + NULL, NULL, &config_change_color, NULL, NULL, NULL); config_color_chat_delimiters = config_file_new_option ( weechat_config_file, ptr_section, "chat_delimiters", "color", diff --git a/src/core/wee-config.h b/src/core/wee-config.h index cddfc1aa0..a3d13ec03 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -116,7 +116,7 @@ extern struct t_config_option *config_look_color_real_white; extern struct t_config_option *config_look_command_chars; extern struct t_config_option *config_look_confirm_quit; extern struct t_config_option *config_look_day_change; -extern struct t_config_option *config_look_day_change_time_format; +extern struct t_config_option *config_look_day_change_message; extern struct t_config_option *config_look_eat_newline_glitch; extern struct t_config_option *config_look_emphasized_attributes; extern struct t_config_option *config_look_highlight; @@ -185,6 +185,7 @@ extern struct t_config_option *config_color_chat; extern struct t_config_option *config_color_chat_bg; extern struct t_config_option *config_color_chat_buffer; extern struct t_config_option *config_color_chat_channel; +extern struct t_config_option *config_color_chat_day_change; extern struct t_config_option *config_color_chat_delimiters; extern struct t_config_option *config_color_chat_inactive_buffer; extern struct t_config_option *config_color_chat_inactive_window; diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index b62dc52ff..497e743b6 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -25,9 +25,11 @@ #include <stdlib.h> #include <string.h> +#include <time.h> #include "../../core/weechat.h" #include "../../core/wee-config.h" +#include "../../core/wee-eval.h" #include "../../core/wee-hook.h" #include "../../core/wee-string.h" #include "../../core/wee-utf8.h" @@ -178,31 +180,31 @@ gui_chat_display_horizontal_line (struct t_gui_window *window, int simulate) int x, size_on_screen; char *read_marker_string, *default_string = "- "; - if (!simulate) + if (simulate) + return; + + gui_window_coords_init_line (window, window->win_chat_cursor_y); + if (CONFIG_INTEGER(config_look_read_marker) == CONFIG_LOOK_READ_MARKER_LINE) { - gui_window_coords_init_line (window, window->win_chat_cursor_y); - if (CONFIG_INTEGER(config_look_read_marker) == CONFIG_LOOK_READ_MARKER_LINE) + read_marker_string = CONFIG_STRING(config_look_read_marker_string); + if (!read_marker_string || !read_marker_string[0]) + read_marker_string = default_string; + size_on_screen = utf8_strlen_screen (read_marker_string); + gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat, + GUI_COLOR_CHAT_READ_MARKER); + wmove (GUI_WINDOW_OBJECTS(window)->win_chat, + window->win_chat_cursor_y, window->win_chat_cursor_x); + wclrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat); + x = 0; + while (x < gui_chat_get_real_width (window)) { - read_marker_string = CONFIG_STRING(config_look_read_marker_string); - if (!read_marker_string || !read_marker_string[0]) - read_marker_string = default_string; - size_on_screen = utf8_strlen_screen (read_marker_string); - gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat, - GUI_COLOR_CHAT_READ_MARKER); - wmove (GUI_WINDOW_OBJECTS(window)->win_chat, - window->win_chat_cursor_y, window->win_chat_cursor_x); - wclrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat); - x = 0; - while (x < gui_chat_get_real_width (window)) - { - mvwprintw (GUI_WINDOW_OBJECTS(window)->win_chat, - window->win_chat_cursor_y, x, - "%s", read_marker_string); - x += size_on_screen; - } + mvwprintw (GUI_WINDOW_OBJECTS(window)->win_chat, + window->win_chat_cursor_y, x, + "%s", read_marker_string); + x += size_on_screen; } - window->win_chat_cursor_x = window->win_chat_width; } + window->win_chat_cursor_x = window->win_chat_width; } /* @@ -586,6 +588,44 @@ gui_chat_display_word (struct t_gui_window *window, } /* + * Displays a message when the day has changed. + */ + +void +gui_chat_display_day_changed (struct t_gui_window *window, + struct tm *date, int simulate) +{ + char message[1024], *message_with_color; + + if (simulate) + return; + + message_with_color = NULL; + + /* build the message to display */ + strftime (message, sizeof (message), + CONFIG_STRING(config_look_day_change_message), date); + + if (strstr (message, "${")) + message_with_color = eval_expression (message, NULL, NULL, NULL); + + /* display the message */ + gui_window_coords_init_line (window, window->win_chat_cursor_y); + gui_window_set_weechat_color (GUI_WINDOW_OBJECTS(window)->win_chat, + GUI_COLOR_CHAT_DAY_CHANGE); + wmove (GUI_WINDOW_OBJECTS(window)->win_chat, + window->win_chat_cursor_y, window->win_chat_cursor_x); + wclrtoeol (GUI_WINDOW_OBJECTS(window)->win_chat); + gui_chat_display_word_raw (window, NULL, + (message_with_color) ? message_with_color : message, + 0, simulate, 0, 0); + window->win_chat_cursor_x = window->win_chat_width; + + if (message_with_color) + free (message_with_color); +} + +/* * Displays time, buffer name (for merged buffers) and prefix for a line. */ @@ -1120,11 +1160,15 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, int count, int simulate) { int num_lines, x, y, lines_displayed, line_align; - int read_marker_x, read_marker_y, marker_line; + int read_marker_x, read_marker_y; int word_start_offset, word_end_offset; int word_length_with_spaces, word_length; char *ptr_data, *ptr_end_offset, *next_char; char *ptr_style, *message_with_tags, *message_with_search; + struct t_gui_line *ptr_prev_line, *ptr_next_line; + struct tm local_time, local_time2; + struct timeval tv_time; + time_t *ptr_time; if (!line) return 0; @@ -1149,6 +1193,34 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, gui_window_current_emphasis = 0; } + /* display message before first line of buffer if date is not today */ + if ((line->data->date != 0) && CONFIG_BOOLEAN(config_look_day_change)) + { + ptr_time = NULL; + ptr_prev_line = gui_line_get_prev_displayed (line); + if (ptr_prev_line) + { + while (ptr_prev_line && (ptr_prev_line->data->date == 0)) + { + ptr_prev_line = gui_line_get_prev_displayed (ptr_prev_line); + } + } + if (!ptr_prev_line) + { + gettimeofday (&tv_time, NULL); + localtime_r (&tv_time.tv_sec, &local_time); + localtime_r (&line->data->date, &local_time2); + if ((local_time.tm_mday != local_time2.tm_mday) + || (local_time.tm_mon != local_time2.tm_mon) + || (local_time.tm_year != local_time2.tm_year)) + { + gui_chat_display_day_changed (window, &local_time2, simulate); + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + } + } + } + /* calculate marker position (maybe not used for this line!) */ if (window->buffer->time_for_each_line && line->data->str_time) read_marker_x = x + gui_chat_strlen_screen (line->data->str_time); @@ -1158,8 +1230,6 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, lines_displayed = 0; - marker_line = gui_chat_marker_for_line (window->buffer, line); - /* display time and prefix */ gui_chat_display_time_to_prefix (window, line, num_lines, count, &lines_displayed, simulate); @@ -1189,12 +1259,8 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, } } - if (!line->data->message || !line->data->message[0]) - { - gui_chat_display_new_line (window, num_lines, count, - &lines_displayed, simulate); - } - else + /* display message */ + if (line->data->message && line->data->message[0]) { message_with_tags = (gui_chat_display_tags) ? gui_chat_build_string_message_tags (line) : NULL; @@ -1306,8 +1372,53 @@ gui_chat_display_line (struct t_gui_window *window, struct t_gui_line *line, if (message_with_search) free (message_with_search); } + else + { + /* no message */ + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + } + + /* display message if day has changed after this line */ + if ((line->data->date != 0) && CONFIG_BOOLEAN(config_look_day_change)) + { + ptr_time = NULL; + ptr_next_line = gui_line_get_next_displayed (line); + if (ptr_next_line) + { + while (ptr_next_line && (ptr_next_line->data->date == 0)) + { + ptr_next_line = gui_line_get_next_displayed (ptr_next_line); + } + } + if (ptr_next_line) + { + /* get time of next line */ + ptr_time = &ptr_next_line->data->date; + } + else + { + /* it was the last line => compare with current system time */ + gettimeofday (&tv_time, NULL); + ptr_time = &tv_time.tv_sec; + } + if (ptr_time && (*ptr_time != 0)) + { + localtime_r (&line->data->date, &local_time); + localtime_r (ptr_time, &local_time2); + if ((local_time.tm_mday != local_time2.tm_mday) + || (local_time.tm_mon != local_time2.tm_mon) + || (local_time.tm_year != local_time2.tm_year)) + { + gui_chat_display_day_changed (window, &local_time2, simulate); + gui_chat_display_new_line (window, num_lines, count, + &lines_displayed, simulate); + } + } + } - if (marker_line) + /* display read marker (after line) */ + if (gui_chat_marker_for_line (window->buffer, line)) { gui_chat_display_horizontal_line (window, simulate); gui_chat_display_new_line (window, num_lines, count, diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index 91bf38089..95e9321fc 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -1435,6 +1435,7 @@ gui_color_init_weechat () gui_color_build (GUI_COLOR_CHAT_NICK_PREFIX, CONFIG_COLOR(config_color_chat_nick_prefix), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_CHAT_NICK_SUFFIX, CONFIG_COLOR(config_color_chat_nick_suffix), CONFIG_COLOR(config_color_chat_bg)); gui_color_build (GUI_COLOR_EMPHASIS, CONFIG_COLOR(config_color_emphasized), CONFIG_COLOR(config_color_emphasized_bg)); + gui_color_build (GUI_COLOR_CHAT_DAY_CHANGE, CONFIG_COLOR(config_color_chat_day_change), CONFIG_COLOR(config_color_chat_bg)); /* * define old nick colors for compatibility on /upgrade with previous diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h index e480c72e2..5b0e032d4 100644 --- a/src/gui/gui-color.h +++ b/src/gui/gui-color.h @@ -81,6 +81,7 @@ enum t_gui_color_enum GUI_COLOR_CHAT_NICK_PREFIX, GUI_COLOR_CHAT_NICK_SUFFIX, GUI_COLOR_EMPHASIS, + GUI_COLOR_CHAT_DAY_CHANGE, /* number of colors */ GUI_COLOR_NUM_COLORS, diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index 183905b6a..8be65132a 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -928,23 +928,15 @@ logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines) { const char *charset; struct t_logger_line *last_lines, *ptr_lines; - char *pos_message, *pos_tab, *error, *message, text_time[256], *text_time2; - struct timeval tv_time; - struct tm *local_time; + char *pos_message, *pos_tab, *error, *message; time_t datetime, time_now; struct tm tm_line; - int num_lines, old_mday, old_mon, old_year; + int num_lines; charset = weechat_info_get ("charset_terminal", ""); weechat_buffer_set (buffer, "print_hooks_enabled", "0"); - gettimeofday (&tv_time, NULL); - local_time = localtime (&tv_time.tv_sec); - old_mday = local_time->tm_mday; - old_mon = local_time->tm_mon; - old_year = local_time->tm_year; - num_lines = 0; last_lines = logger_tail_file (filename, lines); ptr_lines = last_lines; @@ -968,27 +960,7 @@ logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines) weechat_config_string (logger_config_file_time_format), &tm_line); if (error && !error[0] && (tm_line.tm_year > 0)) - { datetime = mktime (&tm_line); - if ((tm_line.tm_mday != old_mday) - || (tm_line.tm_mon != old_mon) - || (tm_line.tm_year != old_year)) - { - strftime (text_time, sizeof (text_time), - weechat_config_string (weechat_config_get ("weechat.look.day_change_time_format")), - &tm_line); - text_time2 = weechat_iconv_to_internal (NULL, text_time); - weechat_printf_tags (buffer, - "no_highlight,notify_none,logger_backlog_date", - _("\t\tDay changed to %s"), - (text_time2) ? text_time2 : text_time); - if (text_time2) - free (text_time2); - old_mday = tm_line.tm_mday; - old_mon = tm_line.tm_mon; - old_year = tm_line.tm_year; - } - } pos_message[0] = '\t'; } pos_message = (pos_message && (datetime != 0)) ? @@ -1019,11 +991,12 @@ logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines) logger_tail_free (last_lines); if (num_lines > 0) { - weechat_printf_tags (buffer, "no_highlight,notify_none,logger_backlog_end", - _("%s===\t%s========== End of backlog (%d lines) =========="), - weechat_color (weechat_config_string (logger_config_color_backlog_end)), - weechat_color (weechat_config_string (logger_config_color_backlog_end)), - num_lines); + weechat_printf_date_tags (buffer, datetime, + "no_highlight,notify_none,logger_backlog_end", + _("%s===\t%s========== End of backlog (%d lines) =========="), + weechat_color (weechat_config_string (logger_config_color_backlog_end)), + weechat_color (weechat_config_string (logger_config_color_backlog_end)), + num_lines); weechat_buffer_set (buffer, "unread", ""); } weechat_buffer_set (buffer, "print_hooks_enabled", "1"); |