diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-12-07 19:43:19 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-12-07 19:43:19 +0100 |
commit | b6662ee3cf9f3401e8af58fb14d0b33a88906b67 (patch) | |
tree | 1764b7811ecfd75556832391db8e9dd9abf18391 /src/gui | |
parent | f7d719f8fdda73c9ef4ea1aa020e1767585c78a8 (diff) | |
download | weechat-b6662ee3cf9f3401e8af58fb14d0b33a88906b67.zip |
Add color support in option weechat.look.buffer_time_format
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-main.c | 2 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 41 | ||||
-rw-r--r-- | src/gui/gui-chat.h | 1 | ||||
-rw-r--r-- | src/gui/gui-color.c | 76 | ||||
-rw-r--r-- | src/gui/gui-color.h | 1 |
5 files changed, 120 insertions, 1 deletions
diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index 051408d35..2ca5469e6 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -112,7 +112,7 @@ gui_main_init () gui_input_clipboard = NULL; /* get time length */ - gui_chat_time_length = util_get_time_length (CONFIG_STRING(config_look_buffer_time_format)); + gui_chat_time_length = gui_chat_get_time_length (); /* init bar items */ gui_bar_item_init (); diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index c2568271a..ca5f02e5d 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -289,6 +289,7 @@ char * gui_chat_get_time_string (time_t date) { 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 tm *local_time; @@ -302,6 +303,17 @@ gui_chat_get_time_string (time_t date) local_time) == 0) return NULL; + if (strstr (text_time, "${")) + { + text_with_color = gui_color_string_replace_colors (text_time); + if (text_with_color) + { + if (strcmp (text_time, text_with_color) != 0) + return text_with_color; + free (text_with_color); + } + } + time_first_digit = -1; time_last_digit = -1; i = 0; @@ -373,6 +385,35 @@ gui_chat_get_time_string (time_t date) } /* + * gui_chat_get_time_length: calculates time length with a time format + * (format can include color codes with format ${name}) + */ + +int +gui_chat_get_time_length () +{ + time_t date; + char *text_time; + int length; + + if (!CONFIG_STRING(config_look_buffer_time_format) + || !CONFIG_STRING(config_look_buffer_time_format)[0]) + return 0; + + length = 0; + date = time (NULL); + text_time = gui_chat_get_time_string (date); + + if (text_time) + { + length = gui_chat_strlen_screen (text_time); + free (text_time); + } + + return length; +} + +/* * gui_chat_change_time_format: change time format for all lines of all buffers */ diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index 0f6ed04b7..57d74337d 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -67,6 +67,7 @@ extern void gui_chat_get_word_info (struct t_gui_window *window, int *word_length_with_spaces, int *word_length); extern char *gui_chat_get_time_string (time_t date); +extern int gui_chat_get_time_length (); extern void gui_chat_change_time_format (); extern char *gui_chat_build_string_prefix_message (struct t_gui_line *line); extern void gui_chat_printf_date_tags (struct t_gui_buffer *buffer, diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c index 5e170d214..99c8bc065 100644 --- a/src/gui/gui-color.c +++ b/src/gui/gui-color.c @@ -348,6 +348,82 @@ gui_color_decode (const char *string, const char *replacement) } /* + * gui_color_string_replace_colors: replace colors in string with color codes + * colors are using format: ${name} where name + * is a color name + */ + +char * +gui_color_string_replace_colors (const char *string) +{ + int length, length_color, index_string, index_result; + char *result, *color_name; + const char *pos_end_name, *ptr_color; + + if (!string) + return NULL; + + length = strlen (string) + 1; + result = malloc (length); + if (result) + { + index_string = 0; + index_result = 0; + while (string[index_string]) + { + if ((string[index_string] == '\\') + && (string[index_string + 1] == '$')) + { + index_string++; + result[index_result++] = string[index_string++]; + } + else if ((string[index_string] == '$') + && (string[index_string + 1] == '{')) + { + pos_end_name = strchr (string + index_string + 2, '}'); + if (pos_end_name) + { + color_name = string_strndup (string + index_string + 2, + pos_end_name - (string + index_string + 2)); + if (color_name) + { + ptr_color = gui_color_get_custom (color_name); + if (ptr_color) + { + length_color = strlen (ptr_color); + length += length_color; + result = realloc (result, length); + if (!result) + { + free (color_name); + return NULL; + } + strcpy (result + index_result, ptr_color); + index_result += length_color; + index_string += pos_end_name - string - + index_string + 1; + } + else + result[index_result++] = string[index_string++]; + + free (color_name); + } + else + result[index_result++] = string[index_string++]; + } + else + result[index_result++] = string[index_string++]; + } + else + result[index_result++] = string[index_string++]; + } + result[index_result] = '\0'; + } + + return result; +} + +/* * gui_color_free: free a color */ diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h index 4b0263591..0d8872b19 100644 --- a/src/gui/gui-color.h +++ b/src/gui/gui-color.h @@ -131,6 +131,7 @@ extern struct t_gui_color *gui_color[]; extern const char *gui_color_search_config (const char *color_name); extern const char *gui_color_get_custom (const char *color_name); extern char *gui_color_decode (const char *string, const char *replacement); +extern char *gui_color_string_replace_colors (const char *string); extern void gui_color_free (struct t_gui_color *color); /* color functions (GUI dependent) */ |