diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-06-27 17:15:26 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-06-27 17:15:26 +0200 |
commit | 50f8bf0043d3cd6f8bd5af9c2948d7058536dec2 (patch) | |
tree | 82e3c4b1091d241249e4a940d82cee36922420bf /src | |
parent | c38eac19e399be7ace5281005e19e3eaf1904073 (diff) | |
download | weechat-50f8bf0043d3cd6f8bd5af9c2948d7058536dec2.zip |
Add input bar item, add "hidden" flag for bars, fix some display bugs with bars
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-command.c | 178 | ||||
-rw-r--r-- | src/core/wee-utf8.c | 9 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-bar.c | 160 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-chat.c | 24 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-keyboard.c | 1 | ||||
-rw-r--r-- | src/gui/curses/gui-curses.h | 2 | ||||
-rw-r--r-- | src/gui/gtk/gui-gtk-chat.c | 4 | ||||
-rw-r--r-- | src/gui/gui-bar-item.c | 326 | ||||
-rw-r--r-- | src/gui/gui-bar-item.h | 8 | ||||
-rw-r--r-- | src/gui/gui-bar.c | 169 | ||||
-rw-r--r-- | src/gui/gui-bar.h | 9 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 1 | ||||
-rw-r--r-- | src/gui/gui-chat.c | 22 | ||||
-rw-r--r-- | src/gui/gui-chat.h | 1 | ||||
-rw-r--r-- | src/gui/gui-color.c | 30 | ||||
-rw-r--r-- | src/gui/gui-color.h | 57 | ||||
-rw-r--r-- | src/gui/gui-input.c | 109 | ||||
-rw-r--r-- | src/gui/gui-input.h | 2 | ||||
-rw-r--r-- | src/gui/gui-keyboard.c | 1 | ||||
-rw-r--r-- | src/gui/gui-window.c | 1 | ||||
-rw-r--r-- | src/plugins/scripts/lua/weechat-lua-api.c | 11 | ||||
-rw-r--r-- | src/plugins/scripts/perl/weechat-perl-api.c | 34 | ||||
-rw-r--r-- | src/plugins/scripts/python/weechat-python-api.c | 10 | ||||
-rw-r--r-- | src/plugins/scripts/ruby/weechat-ruby-api.c | 31 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 31 |
25 files changed, 931 insertions, 300 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 253aea0f5..f47b02b6a 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -58,42 +58,34 @@ /* - * command_bar: manage bars + * command_bar_list: list bars */ -int -command_bar (void *data, struct t_gui_buffer *buffer, - int argc, char **argv, char **argv_eol) +void +command_bar_list (int full) { - int type, position; - long number; - char *error, *str_type, *pos_condition, str_size[16]; struct t_gui_bar *ptr_bar; - struct t_gui_bar_item *ptr_item; + char str_size[16]; - /* make C compiler happy */ - (void) data; - (void) buffer; - - /* list of bars */ - if ((argc == 1) - || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) + if (gui_bars) { - if (gui_bars) + gui_chat_printf (NULL, ""); + gui_chat_printf (NULL, _("List of bars:")); + for (ptr_bar = gui_bars; ptr_bar; + ptr_bar = ptr_bar->next_bar) { - gui_chat_printf (NULL, ""); - gui_chat_printf (NULL, _("List of bars:")); - for (ptr_bar = gui_bars; ptr_bar; - ptr_bar = ptr_bar->next_bar) + snprintf (str_size, sizeof (str_size), + "%d", CONFIG_INTEGER(ptr_bar->size)); + if (full) { - snprintf (str_size, sizeof (str_size), - "%d", CONFIG_INTEGER(ptr_bar->size)); gui_chat_printf (NULL, - _(" %s%s%s: %s (cond: %s), %s, filling: %s, " - "%s: %s"), + _(" %s%s%s: %s%s%s (cond: %s), %s, " + "filling: %s, %s: %s"), GUI_COLOR(GUI_COLOR_CHAT_BUFFER), ptr_bar->name, GUI_COLOR(GUI_COLOR_CHAT), + (CONFIG_BOOLEAN(ptr_bar->hidden)) ? _("(hidden)") : "", + (CONFIG_BOOLEAN(ptr_bar->hidden)) ? " " : "", gui_bar_type_string[CONFIG_INTEGER(ptr_bar->type)], (CONFIG_STRING(ptr_bar->conditions) && CONFIG_STRING(ptr_bar->conditions)[0]) ? @@ -115,12 +107,59 @@ command_bar (void *data, struct t_gui_buffer *buffer, (CONFIG_INTEGER(ptr_bar->separator)) ? _(", with separator") : "", (ptr_bar->plugin) ? ptr_bar->plugin->name : "-"); - + } + else + { + gui_chat_printf (NULL, + " %s%s%s: %s%s%s, %s, %s: %s", + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + ptr_bar->name, + GUI_COLOR(GUI_COLOR_CHAT), + (CONFIG_BOOLEAN(ptr_bar->hidden)) ? _("(hidden)") : "", + (CONFIG_BOOLEAN(ptr_bar->hidden)) ? " " : "", + gui_bar_type_string[CONFIG_INTEGER(ptr_bar->type)], + gui_bar_position_string[CONFIG_INTEGER(ptr_bar->position)], + ((CONFIG_INTEGER(ptr_bar->position) == GUI_BAR_POSITION_BOTTOM) + || (CONFIG_INTEGER(ptr_bar->position) == GUI_BAR_POSITION_TOP)) ? + _("height") : _("width"), + (CONFIG_INTEGER(ptr_bar->size) == 0) ? _("auto") : str_size); } } - else - gui_chat_printf (NULL, _("No bar defined")); - + } + else + gui_chat_printf (NULL, _("No bar defined")); +} + +/* + * command_bar: manage bars + */ + +int +command_bar (void *data, struct t_gui_buffer *buffer, + int argc, char **argv, char **argv_eol) +{ + int type, position; + long number; + char *error, *str_type, *pos_condition; + struct t_gui_bar *ptr_bar; + struct t_gui_bar_item *ptr_item; + + /* make C compiler happy */ + (void) data; + (void) buffer; + + /* list of bars */ + if ((argc == 1) + || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) + { + command_bar_list (0); + return WEECHAT_RC_OK; + } + + /* full list of bars */ + if ((argc == 2) && (string_strcasecmp (argv[1], "listfull") == 0)) + { + command_bar_list (1); return WEECHAT_RC_OK; } @@ -203,7 +242,8 @@ command_bar (void *data, struct t_gui_buffer *buffer, if (error && !error[0]) { /* create bar */ - if (gui_bar_new (NULL, argv[2], "0", str_type, pos_condition, + if (gui_bar_new (NULL, argv[2], "0", "0", str_type, + (pos_condition) ? pos_condition : "", argv[4], ((position == GUI_BAR_POSITION_LEFT) || (position == GUI_BAR_POSITION_RIGHT)) ? @@ -297,6 +337,72 @@ command_bar (void *data, struct t_gui_buffer *buffer, return WEECHAT_RC_OK; } + + /* hide a bar */ + if (string_strcasecmp (argv[1], "hide") == 0) + { + if (argc < 3) + { + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "bar"); + return WEECHAT_RC_ERROR; + } + ptr_bar = gui_bar_search (argv[2]); + if (!ptr_bar) + { + gui_chat_printf (NULL, + _("%sError: unknown bar \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + return WEECHAT_RC_ERROR; + } + if (!CONFIG_BOOLEAN(ptr_bar->hidden)) + { + if (gui_bar_set (ptr_bar, "hidden", "1")) + { + gui_chat_printf (NULL, _("Bar \"%s\" is now hidden"), + ptr_bar->name); + } + } + + return WEECHAT_RC_OK; + } + + /* show a bar */ + if (string_strcasecmp (argv[1], "show") == 0) + { + if (argc < 3) + { + gui_chat_printf (NULL, + _("%sError: missing arguments for \"%s\" " + "command"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + "bar"); + return WEECHAT_RC_ERROR; + } + ptr_bar = gui_bar_search (argv[2]); + if (!ptr_bar) + { + gui_chat_printf (NULL, + _("%sError: unknown bar \"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + argv[2]); + return WEECHAT_RC_ERROR; + } + if (CONFIG_BOOLEAN(ptr_bar->hidden)) + { + if (gui_bar_set (ptr_bar, "hidden", "0")) + { + gui_chat_printf (NULL, _("Bar \"%s\" is now visible"), + ptr_bar->name); + } + } + + return WEECHAT_RC_OK; + } gui_chat_printf (NULL, _("%sError: unknown option for \"%s\" " @@ -2541,7 +2647,8 @@ command_init () N_("[add barname type[,cond1,cond2,...] position size " "separator item1,item2,...] | [del barname] | " "[set barname name|priority|condition|position|filling|" - "size|separator|items value] | [list] | [listitems]"), + "size|separator|items value] | [hide|show barname] | " + "[list] | [listitems]"), N_(" add: add a new bar\n" " barname: name of bar (must be unique)\n" " type: root: outside windows),\n" @@ -2561,10 +2668,14 @@ command_init () "item1,...: items for this bar\n" " del: delete a bar\n" " set: set a value for a bar property\n" + " hide: hide a bar\n" + " show: show an hidden bar\n" " list: list all bars\n" + " listfull: list all bars (verbose)\n" "listitems: list all bar items"), - "add|del|set|list|listitems %r name|priority|conditions|" - "position|filling|size|separator|items", + "add|del|set|hide|show|list|listfull|listitems %r " + "name|priority|conditions|position|filling|size|separator|" + "items", &command_bar, NULL); hook_command (NULL, "buffer", N_("manage buffers"), @@ -2686,8 +2797,7 @@ command_init () N_("[list [name]] | [listfull [name]] | [load filename] | " "[autoload] | [reload [name]] | [unload [name]]"), N_(" list: list loaded plugins\n" - "listfull: list loaded plugins with detailed info for " - "each plugin\n" + "listfull: list loaded plugins (verbose)\n" " load: load a plugin\n" "autoload: autoload plugins in system or user directory\n" " reload: reload one plugin (if no name given, unload " diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index 2b4108374..04894cb6a 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -386,22 +386,19 @@ utf8_char_size_screen (const char *string) } /* - * utf8_add_offset: moves forward N chars in an UTF-8 string + * utf8_add_offset: move forward N chars in an UTF-8 string */ char * utf8_add_offset (const char *string, int offset) { - int count; - if (!string) return NULL; - count = 0; - while (string && string[0] && (count < offset)) + while (string && string[0] && (offset > 0)) { string = utf8_next_char (string); - count++; + offset--; } return (char *)string; } diff --git a/src/gui/curses/gui-curses-bar.c b/src/gui/curses/gui-curses-bar.c index aa40a821b..22e681d3b 100644 --- a/src/gui/curses/gui-curses-bar.c +++ b/src/gui/curses/gui-curses-bar.c @@ -91,7 +91,8 @@ gui_bar_window_set_current_size (struct t_gui_bar *bar, int size) for (ptr_bar_win = GUI_CURSES(ptr_win)->bar_windows; ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window) { - ptr_bar_win->current_size = (size == 0) ? 1 : size; + if (ptr_bar_win->bar == bar) + ptr_bar_win->current_size = (size == 0) ? 1 : size; } } } @@ -117,25 +118,28 @@ gui_bar_window_get_size (struct t_gui_bar *bar, struct t_gui_window *window, /* stop before bar */ if (bar && (ptr_bar_window->bar == bar)) return total_size; - - if ((CONFIG_INTEGER(ptr_bar_window->bar->type) != GUI_BAR_TYPE_ROOT) - && (CONFIG_INTEGER(ptr_bar_window->bar->position) == (int)position)) + + if (!CONFIG_BOOLEAN(ptr_bar_window->bar->hidden)) { - switch (position) + if ((CONFIG_INTEGER(ptr_bar_window->bar->type) != GUI_BAR_TYPE_ROOT) + && (CONFIG_INTEGER(ptr_bar_window->bar->position) == (int)position)) { - case GUI_BAR_POSITION_BOTTOM: - case GUI_BAR_POSITION_TOP: - total_size += ptr_bar_window->height; - break; - case GUI_BAR_POSITION_LEFT: - case GUI_BAR_POSITION_RIGHT: - total_size += ptr_bar_window->width; - break; - case GUI_BAR_NUM_POSITIONS: - break; + switch (position) + { + case GUI_BAR_POSITION_BOTTOM: + case GUI_BAR_POSITION_TOP: + total_size += ptr_bar_window->height; + break; + case GUI_BAR_POSITION_LEFT: + case GUI_BAR_POSITION_RIGHT: + total_size += ptr_bar_window->width; + break; + case GUI_BAR_NUM_POSITIONS: + break; + } + if (CONFIG_INTEGER(ptr_bar_window->bar->separator)) + total_size++; } - if (CONFIG_INTEGER(ptr_bar_window->bar->separator)) - total_size++; } } return total_size; @@ -202,10 +206,10 @@ gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window, y1 = window->win_y; x2 = x1 + window->win_width - 1; y2 = y1 + window->win_height - 1; + add_bottom = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_BOTTOM); + add_top = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_TOP); add_left = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_LEFT); add_right = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_RIGHT); - add_top = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_TOP); - add_bottom = gui_bar_window_get_size (bar_window->bar, window, GUI_BAR_POSITION_BOTTOM); } else { @@ -237,13 +241,13 @@ gui_bar_window_calculate_pos_size (struct t_gui_bar_window *bar_window, bar_window->x = x1 + add_left; bar_window->y = y1 + add_top; bar_window->width = bar_window->current_size; - bar_window->height = y2 - add_top - add_bottom - y1 + 1; + bar_window->height = y2 - y1 + 1 - add_top - add_bottom; break; case GUI_BAR_POSITION_RIGHT: bar_window->x = x2 - add_right - bar_window->current_size + 1; bar_window->y = y1 + add_top; bar_window->width = bar_window->current_size; - bar_window->height = y2 - y1 + 1; + bar_window->height = y2 - y1 + 1 - add_top - add_bottom; break; case GUI_BAR_NUM_POSITIONS: break; @@ -397,6 +401,8 @@ gui_bar_window_new (struct t_gui_bar *bar, struct t_gui_window *window) new_bar_window->y = 0; new_bar_window->width = 1; new_bar_window->height = 1; + new_bar_window->cursor_x = -1; + new_bar_window->cursor_y = -1; new_bar_window->current_size = (CONFIG_INTEGER(bar->size) == 0) ? 1 : CONFIG_INTEGER(bar->size); @@ -425,6 +431,9 @@ gui_bar_window_recreate_bar_windows (struct t_gui_bar *bar) struct t_gui_window *ptr_win; struct t_gui_bar_window *ptr_bar_win; + if (CONFIG_BOOLEAN(bar->hidden)) + return; + if (CONFIG_INTEGER(bar->type) == GUI_BAR_TYPE_ROOT) { gui_bar_window_calculate_pos_size (bar->bar_window, NULL); @@ -574,7 +583,8 @@ gui_bar_window_add_missing_bars (struct t_gui_window *window) void gui_bar_window_print_string (struct t_gui_bar_window *bar_window, - int *x, int *y, const char *string) + int *x, int *y, + const char *string) { int weechat_color, size_on_screen, fg, bg; char str_fg[3], str_bg[3], utf_char[16], *next_char, *output; @@ -583,7 +593,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window, return; wmove (bar_window->win_bar, *y, *x); - + gui_window_set_custom_color_fg_bg (bar_window->win_bar, CONFIG_COLOR(bar_window->bar->color_fg), CONFIG_COLOR(bar_window->bar->color_bg)); @@ -595,7 +605,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window, string++; switch (string[0]) { - case 'F': /* fg color */ + case GUI_COLOR_FG_CHAR: /* fg color */ if (string[1] && string[2]) { str_fg[0] = string[1]; @@ -607,7 +617,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window, string += 3; } break; - case 'B': /* bg color */ + case GUI_COLOR_BG_CHAR: /* bg color */ if (string[1] && string[2]) { str_bg[0] = string[1]; @@ -619,7 +629,7 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window, string += 3; } break; - case '*': /* fg + bg color */ + case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */ if (string[1] && string[2] && (string[3] == ',') && string[4] && string[5]) { @@ -636,24 +646,35 @@ gui_bar_window_print_string (struct t_gui_bar_window *bar_window, string += 6; } break; - case 'b': /* bar color */ + case GUI_COLOR_BAR_CHAR: /* bar color */ switch (string[1]) { - case 'f': /* bar foreground */ + case GUI_COLOR_BAR_FG_CHAR: + /* bar foreground */ gui_window_set_custom_color_fg (bar_window->win_bar, CONFIG_INTEGER(bar_window->bar->color_fg)); string += 2; break; - case 'd': /* bar delimiter */ + case GUI_COLOR_BAR_DELIM_CHAR: + /* bar delimiter */ gui_window_set_custom_color_fg (bar_window->win_bar, CONFIG_INTEGER(bar_window->bar->color_delim)); string += 2; break; - case 'b': /* bar background */ + case GUI_COLOR_BAR_BG_CHAR: + /* bar background */ gui_window_set_custom_color_bg (bar_window->win_bar, CONFIG_INTEGER(bar_window->bar->color_bg)); string += 2; break; + case GUI_COLOR_BAR_MOVE_CURSOR_CHAR: + /* move cursor to current position on screen */ + getyx (bar_window->win_bar, + bar_window->cursor_y, bar_window->cursor_x); + bar_window->cursor_x += bar_window->x; + bar_window->cursor_y += bar_window->y; + string += 2; + break; default: string++; break; @@ -720,11 +741,26 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, int x, y, i, items_count, num_lines, line; char *content, *item_value, *item_value2, **items; char space_with_reinit_color[32]; - int content_length, length, max_length, optimal_number_of_lines; + int length_reinit_color, content_length, length, length_on_screen; + int max_length, optimal_number_of_lines, chars_available; if (!gui_init_ok) return; + snprintf (space_with_reinit_color, + sizeof (space_with_reinit_color), + "%c%c%02d,%02d ", + GUI_COLOR_COLOR_CHAR, + GUI_COLOR_FG_BG_CHAR, + CONFIG_COLOR(bar_window->bar->color_fg), + CONFIG_COLOR(bar_window->bar->color_bg)); + length_reinit_color = strlen (space_with_reinit_color); + + /* these values will be overwritten later (by gui_bar_window_print_string) + if cursor has to move somewhere in bar window */ + bar_window->cursor_x = -1; + bar_window->cursor_y = -1; + if (CONFIG_INTEGER(bar_window->bar->size) == 0) { content = NULL; @@ -733,19 +769,13 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, { item_value = gui_bar_item_get_value (bar_window->bar->items_array[i], bar_window->bar, window, - 0, 0); + 0, 0, 0); if (item_value) { if (item_value[0]) { if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_HORIZONTAL) { - snprintf (space_with_reinit_color, - sizeof (space_with_reinit_color), - "%c*%02d,%02d ", - GUI_COLOR_COLOR_CHAR, - CONFIG_COLOR(bar_window->bar->color_fg), - CONFIG_COLOR(bar_window->bar->color_bg)); item_value2 = string_replace (item_value, "\n", space_with_reinit_color); } @@ -760,11 +790,11 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, } else { - content_length += 1 + + content_length += length_reinit_color + strlen ((item_value2) ? item_value2 : item_value); content = realloc (content, content_length); if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_HORIZONTAL) - strcat (content, " "); + strcat (content, space_with_reinit_color); else strcat (content, "\n"); strcat (content, @@ -793,14 +823,22 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, optimal_number_of_lines = 0; for (line = 0; line < items_count; line++) { - length = gui_chat_strlen_screen (items[line]); - if (length > max_length) - max_length = length; + length_on_screen = gui_chat_strlen_screen (items[line]); + + length = strlen (items[line]); + if ((length >= 3) + && (items[line][length - 3] == GUI_COLOR_COLOR_CHAR) + && (items[line][length - 2] == GUI_COLOR_BAR_CHAR) + && (items[line][length - 1] == GUI_COLOR_BAR_MOVE_CURSOR_CHAR)) + length_on_screen++; - if (length % bar_window->width == 0) - num_lines = length / bar_window->width; + if (length_on_screen > max_length) + max_length = length_on_screen; + + if (length_on_screen % bar_window->width == 0) + num_lines = length_on_screen / bar_window->width; else - num_lines = (length / bar_window->width) + 1; + num_lines = (length_on_screen / bar_window->width) + 1; if (num_lines == 0) num_lines = 1; optimal_number_of_lines += num_lines; @@ -874,22 +912,21 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, for (i = 0; i < bar_window->bar->items_count; i++) { + chars_available = + ((bar_window->height - y - 1) * bar_window->width) + /* next lines */ + (bar_window->width - x - 1); /* chars on current line */ + item_value = gui_bar_item_get_value (bar_window->bar->items_array[i], bar_window->bar, window, bar_window->width, - bar_window->height); + bar_window->height, + chars_available); if (item_value) { if (item_value[0]) { if (CONFIG_INTEGER(bar_window->bar->filling) == GUI_BAR_FILLING_HORIZONTAL) { - snprintf (space_with_reinit_color, - sizeof (space_with_reinit_color), - "%c*%02d,%02d ", - GUI_COLOR_COLOR_CHAR, - CONFIG_COLOR(bar_window->bar->color_fg), - CONFIG_COLOR(bar_window->bar->color_bg)); item_value2 = string_replace (item_value, "\n", space_with_reinit_color); } @@ -911,8 +948,10 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, y++; } else + { gui_bar_window_print_string (bar_window, &x, &y, - " "); + space_with_reinit_color); + } } if (item_value2) free (item_value2); @@ -923,6 +962,14 @@ gui_bar_window_draw (struct t_gui_bar_window *bar_window, } } } + + /* move cursor if it was asked in an item content (input_text does that + to move cursor in user input text) */ + if (window && (gui_current_window == window) + && (bar_window->cursor_x >= 0) && (bar_window->cursor_y >= 0)) + { + move (bar_window->cursor_y, bar_window->cursor_x); + } wnoutrefresh (bar_window->win_bar); @@ -973,6 +1020,9 @@ gui_bar_draw (struct t_gui_bar *bar) struct t_gui_window *ptr_win; struct t_gui_bar_window *ptr_bar_win; + if (CONFIG_BOOLEAN(bar->hidden)) + return; + if (bar->bar_window) { /* root bar */ @@ -1009,6 +1059,8 @@ gui_bar_window_print_log (struct t_gui_bar_window *bar_window) log_printf (" y . . . . . . . . : %d", bar_window->y); log_printf (" width . . . . . . : %d", bar_window->width); log_printf (" height. . . . . . : %d", bar_window->height); + log_printf (" cursor_x. . . . . : %d", bar_window->cursor_x); + log_printf (" cursor_y. . . . . : %d", bar_window->cursor_y); log_printf (" current_size. . . : %d", bar_window->current_size); log_printf (" win_bar . . . . . : 0x%x", bar_window->win_bar); log_printf (" win_separator . . : 0x%x", bar_window->win_separator); diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c index 1b9c3fe88..bd20dca1b 100644 --- a/src/gui/curses/gui-curses-chat.c +++ b/src/gui/curses/gui-curses-chat.c @@ -263,7 +263,7 @@ gui_chat_string_next_char (struct t_gui_window *window, string++; switch (string[0]) { - case 'F': + case GUI_COLOR_FG_CHAR: /* fg color */ if (string[1] && string[2]) { if (apply_style) @@ -278,7 +278,7 @@ gui_chat_string_next_char (struct t_gui_window *window, string += 3; } break; - case 'B': + case GUI_COLOR_BG_CHAR: /* bg color */ if (string[1] && string[2]) { if (apply_style) @@ -293,7 +293,7 @@ gui_chat_string_next_char (struct t_gui_window *window, string += 3; } break; - case '*': + case GUI_COLOR_FG_BG_CHAR: /* fg + bg color */ if (string[1] && string[2] && (string[3] == ',') && string[4] && string[5]) { @@ -313,6 +313,20 @@ gui_chat_string_next_char (struct t_gui_window *window, string += 6; } break; + case GUI_COLOR_BAR_CHAR: /* bar color */ + switch (string[1]) + { + case GUI_COLOR_BAR_FG_CHAR: + case GUI_COLOR_BAR_DELIM_CHAR: + case GUI_COLOR_BAR_BG_CHAR: + case GUI_COLOR_BAR_MOVE_CURSOR_CHAR: + string += 2; + break; + default: + string++; + break; + } + break; default: if (isdigit (string[0]) && isdigit (string[1])) { @@ -330,7 +344,7 @@ gui_chat_string_next_char (struct t_gui_window *window, break; } break; - case GUI_COLOR_SET_CHAR: + case GUI_COLOR_SET_WEECHAT_CHAR: string++; switch (string[0]) { @@ -358,7 +372,7 @@ gui_chat_string_next_char (struct t_gui_window *window, break; } break; - case GUI_COLOR_REMOVE_CHAR: + case GUI_COLOR_REMOVE_WEECHAT_CHAR: string++; switch (string[0]) { diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c index 0f689c1e8..4eeaede59 100644 --- a/src/gui/curses/gui-curses-keyboard.c +++ b/src/gui/curses/gui-curses-keyboard.c @@ -297,6 +297,7 @@ gui_keyboard_flush () key_str, -1); if (gui_current_window->buffer->completion) gui_completion_stop (gui_current_window->buffer->completion, 0); + gui_input_text_changed_signal (); input_draw = 1; } diff --git a/src/gui/curses/gui-curses.h b/src/gui/curses/gui-curses.h index 20a9c1c46..92e815ea9 100644 --- a/src/gui/curses/gui-curses.h +++ b/src/gui/curses/gui-curses.h @@ -43,6 +43,8 @@ struct t_gui_bar_window struct t_gui_bar *bar; /* pointer to bar */ int x, y; /* position of window */ int width, height; /* window size */ + int cursor_x, cursor_y; /* use to move cursor on screen (for */ + /* input_text item) */ WINDOW *win_bar; /* bar Curses window */ int current_size; /* current size (width or height) */ WINDOW *win_separator; /* separator (optional) */ diff --git a/src/gui/gtk/gui-gtk-chat.c b/src/gui/gtk/gui-gtk-chat.c index 271a8a811..5366d1ebc 100644 --- a/src/gui/gtk/gui-gtk-chat.c +++ b/src/gui/gtk/gui-gtk-chat.c @@ -224,7 +224,7 @@ gui_chat_string_next_char (struct t_gui_window *window, } } break; - case GUI_COLOR_SET_CHAR: + case GUI_COLOR_SET_WEECHAT_CHAR: string++; switch (string[0]) { @@ -249,7 +249,7 @@ gui_chat_string_next_char (struct t_gui_window *window, break; } break; - case GUI_COLOR_REMOVE_CHAR: + case GUI_COLOR_REMOVE_WEECHAT_CHAR: string++; switch (string[0]) { diff --git a/src/gui/gui-bar-item.c b/src/gui/gui-bar-item.c index a936a0e1c..8f16cad16 100644 --- a/src/gui/gui-bar-item.c +++ b/src/gui/gui-bar-item.c @@ -32,10 +32,12 @@ #include "../core/wee-hook.h" #include "../core/wee-log.h" #include "../core/wee-string.h" +#include "../core/wee-utf8.h" #include "../plugins/plugin.h" #include "gui-bar-item.h" #include "gui-bar.h" #include "gui-buffer.h" +#include "gui-chat.h" #include "gui-color.h" #include "gui-completion.h" #include "gui-filter.h" @@ -46,8 +48,9 @@ struct t_gui_bar_item *gui_bar_items = NULL; /* first bar item */ struct t_gui_bar_item *last_gui_bar_item = NULL; /* last bar item */ char *gui_bar_item_names[GUI_BAR_NUM_ITEMS] = -{ "time", "buffer_count", "buffer_plugin", "buffer_name", "buffer_filter", - "nicklist_count", "scroll", "hotlist", "completion" +{ "input_prompt", "input_text", "time", "buffer_count", "buffer_plugin", + "buffer_name", "buffer_filter", "nicklist_count", "scroll", "hotlist", + "completion" }; struct t_gui_bar_item_hook *gui_bar_item_hooks = NULL; struct t_hook *gui_bar_item_timer = NULL; @@ -76,6 +79,70 @@ gui_bar_item_search (const char *name) } /* + * gui_bar_item_valid_char_name: return 1 if char is valid for item name + * (any letter, digit, "-" or "_") + * return 0 otherwise + */ + +int +gui_bar_item_valid_char_name (char c) +{ + return (((c >= 'a') && (c <= 'z')) + || ((c >= 'A') && (c <= 'Z')) + || ((c >= '0') && (c <= '9')) + || (c == '-') + || (c == '_')) ? + 1 : 0; +} + +/* + * gui_bar_item_string_get_item_start: return pointer to beginning of item name + * (string may contain special delimiters + * at beginning, which are ignored) + */ + +const char * +gui_bar_item_string_get_item_start (const char *string) +{ + while (string && string[0]) + { + if (gui_bar_item_valid_char_name (string[0])) + break; + string++; + } + if (string && string[0]) + return string; + + return NULL; +} + +/* + * gui_bar_item_string_is_item: return 1 if string is item (string may contain + * special delimiters at beginning and end of + * string, which are ignored) + */ + +int +gui_bar_item_string_is_item (const char *string, const char *name) +{ + const char *item_start; + int length; + + item_start = gui_bar_item_string_get_item_start (string); + if (!item_start) + return 0; + + length = strlen (name); + if (strncmp (item_start, name, length) == 0) + { + if (!gui_bar_item_valid_char_name (item_start[length])) + return 1; + } + + return 0; +} + +/* * gui_bar_item_search_with_plugin: search a bar item for a plugin */ @@ -99,20 +166,93 @@ gui_bar_item_search_with_plugin (struct t_weechat_plugin *plugin, const char *na } /* - * gui_bar_item_valid_char_name: return 1 if char is valid for item name - * (any letter, digit, "-" or "_") - * return 0 otherwise + * gui_bar_item_input_text_update_for_display: update input text item for + * display: + * - scroll if needed, to see only + * the end of input + * - insert "move cursor" id to + * move cursor to good position */ -int -gui_bar_item_valid_char_name (char c) +char * +gui_bar_item_input_text_update_for_display (const char *item_content, + struct t_gui_window *window, + int chars_available) { - return (((c >= 'a') && (c <= 'z')) - || ((c >= 'A') && (c <= 'Z')) - || ((c >= '0') && (c <= '9')) - || (c == '-') - || (c == '_')) ? - 1 : 0; + char *buf, str_cursor[16]; + const char *pos_cursor, *ptr_start; + int diff, buf_pos; + int length, length_screen_before_cursor, length_screen_after_cursor; + int total_length_screen; + + snprintf (str_cursor, sizeof (str_cursor), "%c%c%c", + GUI_COLOR_COLOR_CHAR, + GUI_COLOR_BAR_CHAR, + GUI_COLOR_BAR_MOVE_CURSOR_CHAR); + + ptr_start = item_content; + + pos_cursor = gui_chat_string_add_offset (item_content, + window->buffer->input_buffer_pos); + + /* if bar size is fixed (chars_available > 0), then truncate it at + beginning if needed */ + if (chars_available > 0) + { + length_screen_before_cursor = -1; + length_screen_after_cursor = -1; + if (pos_cursor && (pos_cursor > item_content)) + { + buf = string_strndup (item_content, pos_cursor - item_content); + if (buf) + { + length_screen_before_cursor = gui_chat_strlen_screen (buf); + length_screen_after_cursor = gui_chat_strlen_screen (pos_cursor + strlen (str_cursor)); + free (buf); + } + } + if ((length_screen_before_cursor < 0) || (length_screen_after_cursor < 0)) + { + length_screen_before_cursor = gui_chat_strlen_screen (item_content); + length_screen_after_cursor = 0; + } + + total_length_screen = length_screen_before_cursor + length_screen_after_cursor; + + diff = length_screen_before_cursor - chars_available; + if (diff > 0) + { + ptr_start = gui_chat_string_add_offset (item_content, diff); + if (pos_cursor && (ptr_start > pos_cursor)) + ptr_start = pos_cursor; + } + } + + /* insert "move cursor" id in string and return it */ + length = 16 + strlen (ptr_start); + buf = malloc (length); + if (buf) + { + buf[0] = '\0'; + buf_pos = 0; + + if (!pos_cursor) + pos_cursor = ptr_start; + + /* add beginning of buffer */ + if (pos_cursor != ptr_start) + { + memmove (buf, ptr_start, pos_cursor - ptr_start); + buf_pos = buf_pos + (pos_cursor - ptr_start); + } + /* add "move cursor here" identifier in string */ + snprintf (buf + buf_pos, length - buf_pos, "%s", + str_cursor); + /* add end of buffer */ + strcat (buf, pos_cursor); + } + + return buf; } /* @@ -128,11 +268,12 @@ gui_bar_item_valid_char_name (char c) char * gui_bar_item_get_value (const char *name, struct t_gui_bar *bar, struct t_gui_window *window, - int width, int height) + int width, int height, + int chars_available) { const char *ptr, *start, *end; char *prefix, *item_name, *suffix; - char *item_value, delimiter_color[32], bar_color[32]; + char *item_value, *item_value2, delimiter_color[32], bar_color[32]; char *result; int valid_char, length; struct t_gui_bar_item *ptr_item; @@ -180,30 +321,48 @@ gui_bar_item_get_value (const char *name, struct t_gui_bar *bar, ptr_item, window, width, height); - if (!item_value || !item_value[0]) + if (window + && (strncmp (item_name, + gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT], + strlen (gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT])) == 0)) { if (prefix) + chars_available -= gui_chat_strlen_screen (prefix); + + item_value2 = gui_bar_item_input_text_update_for_display ( + (item_value) ? item_value : "", + window, + chars_available); + + if (item_value2) { - free (prefix); - prefix = NULL; - } - if (suffix) - { - free (suffix); - suffix = NULL; + if (item_value) + free (item_value); + item_value = item_value2; } } } } - else - item_value = strdup (item_name); + if (!item_value || !item_value[0]) + { + if (prefix) + { + free (prefix); + prefix = NULL; + } + if (suffix) + { + free (suffix); + suffix = NULL; + } + } } length = 0; if (prefix) length += 64 + strlen (prefix) + 1; /* color + prefix + color */ if (item_value && item_value[0]) - length += strlen (item_value) + 1; + length += strlen (item_value) + 16 + 1; /* length + "move cursor" id */ if (suffix) length += 32 + strlen (suffix) + 1; /* color + suffix */ @@ -218,12 +377,14 @@ gui_bar_item_get_value (const char *name, struct t_gui_bar *bar, if (prefix || suffix) { snprintf (delimiter_color, sizeof (delimiter_color), - "%cF%02d", + "%c%c%02d", GUI_COLOR_COLOR_CHAR, + GUI_COLOR_FG_CHAR, CONFIG_COLOR(bar->color_delim)); snprintf (bar_color, sizeof (bar_color), - "%cF%02d", + "%c%c%02d", GUI_COLOR_COLOR_CHAR, + GUI_COLOR_FG_CHAR, CONFIG_COLOR(bar->color_fg)); } snprintf (result, length, @@ -302,25 +463,15 @@ gui_bar_item_new (struct t_weechat_plugin *plugin, const char *name, int gui_bar_contains_item (struct t_gui_bar *bar, const char *name) { - int i, length; - char *ptr; + int i; if (!bar || !name || !name[0]) return 0; - length = strlen (name); - for (i = 0; i < bar->items_count; i++) { /* skip non letters chars at beginning (prefix) */ - ptr = bar->items_array[i]; - while (ptr && ptr[0]) - { - if (gui_bar_item_valid_char_name (ptr[0])) - break; - ptr++; - } - if (ptr && ptr[0] && (strncmp (ptr, name, length) == 0)) + if (gui_bar_item_string_is_item (bar->items_array[i], name)) return 1; } @@ -339,8 +490,11 @@ gui_bar_item_update (const char *name) for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { - if (gui_bar_contains_item (ptr_bar, name)) + if (!CONFIG_BOOLEAN(ptr_bar->hidden) + && gui_bar_contains_item (ptr_bar, name)) + { gui_bar_draw (ptr_bar); + } } } @@ -403,6 +557,68 @@ gui_bar_item_free_all_plugin (struct t_weechat_plugin *plugin) } /* + * gui_bar_item_default_input_prompt: default item for input prompt + */ + +char * +gui_bar_item_default_input_prompt (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width, int max_height) +{ + char *buf; + int length; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) max_width; + (void) max_height; + + if (!window) + window = gui_current_window; + + if (!window->buffer->input_nick) + return NULL; + + length = strlen (window->buffer->input_nick); + if (length == 0) + return NULL; + + length += 64 + 1; + buf = malloc (length); + if (buf) + { + snprintf (buf, length, "%s%s", + gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_input_nick))), + window->buffer->input_nick); + } + + return buf; +} + +/* + * gui_bar_item_default_input_text: default item for input text + */ + +char * +gui_bar_item_default_input_text (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width, int max_height) +{ + /* make C compiler happy */ + (void) data; + (void) item; + (void) max_width; + (void) max_height; + + if (!window) + window = gui_current_window; + + return (window->buffer->input_buffer) ? + strdup (window->buffer->input_buffer) : NULL; +} + +/* * gui_bar_item_default_time: default item for time */ @@ -501,10 +717,10 @@ gui_bar_item_default_buffer_name (void *data, struct t_gui_bar_item *item, snprintf (buf, sizeof (buf), "%s%d%s:%s%s%s/%s%s", gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_number))), window->buffer->number, - GUI_COLOR_BAR_DELIM, + GUI_COLOR_CUSTOM_BAR_DELIM, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_category))), window->buffer->category, - GUI_COLOR_BAR_DELIM, + GUI_COLOR_CUSTOM_BAR_DELIM, gui_color_get_custom (gui_color_get_name (CONFIG_COLOR(config_color_status_name))), window->buffer->name); @@ -664,9 +880,9 @@ gui_bar_item_default_hotlist (void *data, struct t_gui_bar_item *item, { names_count++; - strcat (buf, GUI_COLOR_BAR_DELIM); + strcat (buf, GUI_COLOR_CUSTOM_BAR_DELIM); strcat (buf, ":"); - strcat (buf, GUI_COLOR_BAR_FG); + strcat (buf, GUI_COLOR_CUSTOM_BAR_FG); if (CONFIG_INTEGER(config_look_hotlist_names_length) == 0) snprintf (format, sizeof (format) - 1, "%%s"); else @@ -720,11 +936,11 @@ gui_bar_item_default_completion (void *data, struct t_gui_bar_item *item, for (ptr_item = gui_completion_partial_list; ptr_item; ptr_item = ptr_item->next_item) { - strcat (buf, GUI_COLOR_BAR_FG); + strcat (buf, GUI_COLOR_CUSTOM_BAR_FG); strcat (buf, ptr_item->word); if (ptr_item->count > 0) { - strcat (buf, GUI_COLOR_BAR_DELIM); + strcat (buf, GUI_COLOR_CUSTOM_BAR_DELIM); strcat (buf, "("); snprintf (number_str, sizeof (number_str), "%d", ptr_item->count); @@ -817,6 +1033,22 @@ gui_bar_item_hook (const char *signal, const char *item) void gui_bar_item_init () { + /* input prompt */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT], + &gui_bar_item_default_input_prompt, NULL); + gui_bar_item_hook ("input_prompt_changed", + gui_bar_item_names[GUI_BAR_ITEM_INPUT_PROMPT]); + + /* input text */ + gui_bar_item_new (NULL, + gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT], + &gui_bar_item_default_input_text, NULL); + gui_bar_item_hook ("input_text_changed", + gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]); + gui_bar_item_hook ("input_text_cursor_moved", + gui_bar_item_names[GUI_BAR_ITEM_INPUT_TEXT]); + /* time */ gui_bar_item_new (NULL, gui_bar_item_names[GUI_BAR_ITEM_TIME], diff --git a/src/gui/gui-bar-item.h b/src/gui/gui-bar-item.h index 364127e22..a34e6083c 100644 --- a/src/gui/gui-bar-item.h +++ b/src/gui/gui-bar-item.h @@ -22,7 +22,9 @@ enum t_gui_bar_item_weechat { - GUI_BAR_ITEM_TIME = 0, + GUI_BAR_ITEM_INPUT_PROMPT = 0, + GUI_BAR_ITEM_INPUT_TEXT, + GUI_BAR_ITEM_TIME, GUI_BAR_ITEM_BUFFER_COUNT, GUI_BAR_ITEM_BUFFER_PLUGIN, GUI_BAR_ITEM_BUFFER_NAME, @@ -61,6 +63,7 @@ struct t_gui_bar_item_hook extern struct t_gui_bar_item *gui_bar_items; extern struct t_gui_bar_item *last_gui_bar_item; +extern char *gui_bar_item_names[]; /* functions */ @@ -68,7 +71,8 @@ extern struct t_gui_bar_item *gui_bar_item_search (const char *name); extern char *gui_bar_item_get_value (const char *name, struct t_gui_bar *bar, struct t_gui_window *window, - int width, int height); + int width, int height, + int chars_available); extern struct t_gui_bar_item *gui_bar_item_new (struct t_weechat_plugin *plugin, const char *name, char *(*build_callback)(void *data, diff --git a/src/gui/gui-bar.c b/src/gui/gui-bar.c index ed8b79fe4..8338615c3 100644 --- a/src/gui/gui-bar.c +++ b/src/gui/gui-bar.c @@ -39,8 +39,8 @@ char *gui_bar_option_string[GUI_BAR_NUM_OPTIONS] = -{ "priority", "type", "conditions", "position", "filling", "size", "size_max", - "color_fg", "color_delim", "color_bg", "separator", "items" }; +{ "hidden", "priority", "type", "conditions", "position", "filling", "size", + "size_max", "color_fg", "color_delim", "color_bg", "separator", "items" }; char *gui_bar_type_string[GUI_BAR_NUM_TYPES] = { "root", "window" }; char *gui_bar_position_string[GUI_BAR_NUM_POSITIONS] = @@ -230,13 +230,16 @@ gui_bar_root_get_size (struct t_gui_bar *bar, enum t_gui_bar_position position) { if (bar && (ptr_bar == bar)) return total_size; - - if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT) - && (CONFIG_INTEGER(ptr_bar->position) == (int)position)) + + if (!CONFIG_BOOLEAN(ptr_bar->hidden)) { - total_size += gui_bar_window_get_current_size (ptr_bar->bar_window); - if (CONFIG_INTEGER(ptr_bar->separator)) - total_size++; + if ((CONFIG_INTEGER(ptr_bar->type) == GUI_BAR_TYPE_ROOT) + && (CONFIG_INTEGER(ptr_bar->position) == (int)position)) + { + total_size += gui_bar_window_get_current_size (ptr_bar->bar_window); + if (CONFIG_INTEGER(ptr_bar->separator)) + total_size++; + } } } return total_size; @@ -337,6 +340,44 @@ gui_bar_config_check_type (void *data, struct t_config_option *option, } /* + * gui_bar_config_change_hidden: callback when "hidden" flag is changed + */ + +void +gui_bar_config_change_hidden (void *data, struct t_config_option *option) +{ + struct t_gui_bar *ptr_bar; + struct t_gui_window *ptr_win; + + /* make C compiler happy */ + (void) data; + + ptr_bar = gui_bar_search_with_option_name (option->name); + if (ptr_bar) + { + /* free bar windows */ + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + gui_bar_free_bar_windows (ptr_bar); + } + + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) + { + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) + { + if (!CONFIG_BOOLEAN(ptr_bar->hidden) + && (CONFIG_INTEGER(ptr_bar->type) != GUI_BAR_TYPE_ROOT)) + { + gui_bar_window_new (ptr_bar, ptr_win); + } + } + } + } + + gui_window_refresh_needed = 1; +} + +/* * gui_bar_config_change_priority: callback when priority is changed */ @@ -380,8 +421,11 @@ gui_bar_config_change_priority (void *data, struct t_config_option *option) { for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { - if (CONFIG_INTEGER(ptr_bar->type) != GUI_BAR_TYPE_ROOT) + if (!CONFIG_BOOLEAN(ptr_bar->hidden) + && (CONFIG_INTEGER(ptr_bar->type) != GUI_BAR_TYPE_ROOT)) + { gui_bar_window_new (ptr_bar, ptr_win); + } } } } @@ -436,7 +480,7 @@ gui_bar_config_change_position (void *data, struct t_config_option *option) (void) data; ptr_bar = gui_bar_search_with_option_name (option->name); - if (ptr_bar) + if (ptr_bar && !CONFIG_BOOLEAN(ptr_bar->hidden)) gui_bar_refresh (ptr_bar); gui_window_refresh_needed = 1; @@ -455,7 +499,7 @@ gui_bar_config_change_filling (void *data, struct t_config_option *option) (void) data; ptr_bar = gui_bar_search_with_option_name (option->name); - if (ptr_bar) + if (ptr_bar && !CONFIG_BOOLEAN(ptr_bar->hidden)) gui_bar_refresh (ptr_bar); gui_window_refresh_needed = 1; @@ -515,8 +559,9 @@ gui_bar_config_check_size (void *data, struct t_config_option *option, ((CONFIG_INTEGER(ptr_bar->size) == 0) || (new_value > CONFIG_INTEGER(ptr_bar->size)))) { - if (!gui_bar_check_size_add (ptr_bar, - new_value - CONFIG_INTEGER(ptr_bar->size))) + if (!CONFIG_BOOLEAN(ptr_bar->hidden) + && !gui_bar_check_size_add (ptr_bar, + new_value - CONFIG_INTEGER(ptr_bar->size))) return 0; } @@ -574,7 +619,7 @@ gui_bar_config_change_color (void *data, struct t_config_option *option) (void) data; ptr_bar = gui_bar_search_with_option_name (option->name); - if (ptr_bar) + if (ptr_bar && !CONFIG_BOOLEAN(ptr_bar->hidden)) gui_bar_refresh (ptr_bar); } @@ -591,7 +636,7 @@ gui_bar_config_change_separator (void *data, struct t_config_option *option) (void) data; ptr_bar = gui_bar_search_with_option_name (option->name); - if (ptr_bar) + if (ptr_bar && !CONFIG_BOOLEAN(ptr_bar->hidden)) gui_bar_refresh (ptr_bar); } @@ -624,8 +669,9 @@ gui_bar_config_change_items (void *data, struct t_config_option *option) ptr_bar->items_count = 0; ptr_bar->items_array = NULL; } - - gui_bar_draw (ptr_bar); + + if (!CONFIG_BOOLEAN(ptr_bar->hidden)) + gui_bar_draw (ptr_bar); } } @@ -646,6 +692,8 @@ gui_bar_set_name (struct t_gui_bar *bar, const char *name) option_name = malloc (length); if (option_name) { + snprintf (option_name, length, "%s.hidden", name); + config_file_option_rename (bar->hidden, option_name); snprintf (option_name, length, "%s.priority", name); config_file_option_rename (bar->priority, option_name); snprintf (option_name, length, "%s.type", name); @@ -811,16 +859,19 @@ gui_bar_set (struct t_gui_bar *bar, const char *property, const char *value) gui_bar_set_name (bar, value); return 1; } + else if (string_strcasecmp (property, "hidden") == 0) + { + config_file_option_set (bar->hidden, value, 1); + return 1; + } else if (string_strcasecmp (property, "priority") == 0) { gui_bar_set_priority (bar, value); - gui_window_refresh_needed = 1; return 1; } else if (string_strcasecmp (property, "conditions") == 0) { config_file_option_set (bar->conditions, value, 1); - gui_window_refresh_needed = 1; return 1; } else if (string_strcasecmp (property, "position") == 0) @@ -904,6 +955,14 @@ gui_bar_create_option (const char *bar_name, int index_option, const char *value switch (index_option) { + case GUI_BAR_OPTION_HIDDEN: + ptr_option = config_file_new_option ( + weechat_config_file, weechat_config_section_bar, + option_name, "boolean", + N_("true if bar is hidden, false if it is displayed"), + NULL, 0, 0, value, + NULL, NULL, &gui_bar_config_change_hidden, NULL, NULL, NULL); + break; case GUI_BAR_OPTION_PRIORITY: ptr_option = config_file_new_option ( weechat_config_file, weechat_config_section_bar, @@ -1038,6 +1097,9 @@ gui_bar_create_option_temp (struct t_gui_bar *temp_bar, int index_option, { switch (index_option) { + case GUI_BAR_OPTION_HIDDEN: + temp_bar->hidden = new_option; + break; case GUI_BAR_OPTION_PRIORITY: temp_bar->priority = new_option; break; @@ -1092,7 +1154,8 @@ gui_bar_alloc (const char *name) { new_bar->plugin = NULL; new_bar->name = strdup (name); - new_bar->priority = 0; + new_bar->hidden = NULL; + new_bar->priority = NULL; new_bar->type = NULL; new_bar->conditions = NULL; new_bar->position = NULL; @@ -1122,6 +1185,7 @@ gui_bar_alloc (const char *name) struct t_gui_bar * gui_bar_new_with_options (struct t_weechat_plugin *plugin, const char *name, + struct t_config_option *hidden, struct t_config_option *priority, struct t_config_option *type, struct t_config_option *conditions, @@ -1143,6 +1207,7 @@ gui_bar_new_with_options (struct t_weechat_plugin *plugin, const char *name, if (new_bar) { new_bar->plugin = plugin; + new_bar->hidden = hidden; new_bar->priority = priority; new_bar->type = type; new_bar->conditions = conditions; @@ -1209,14 +1274,15 @@ gui_bar_new_with_options (struct t_weechat_plugin *plugin, const char *name, struct t_gui_bar * gui_bar_new (struct t_weechat_plugin *plugin, const char *name, - const char *priority, const char *type, const char *conditions, - const char *position, const char *filling, const char *size, - const char *size_max, const char *color_fg, - const char *color_delim, const char *color_bg, - const char *separators, const char *items) + const char *hidden, const char *priority, const char *type, + const char *conditions, const char *position, + const char *filling, const char *size, const char *size_max, + const char *color_fg, const char *color_delim, + const char *color_bg, const char *separators, const char *items) { - struct t_config_option *option_priority, *option_type, *option_conditions; - struct t_config_option *option_position, *option_filling, *option_size; + struct t_config_option *option_hidden, *option_priority, *option_type; + struct t_config_option *option_conditions, *option_position; + struct t_config_option *option_filling, *option_size; struct t_config_option *option_size_max, *option_color_fg; struct t_config_option *option_color_delim, *option_color_bg; struct t_config_option *option_separator, *option_items; @@ -1237,6 +1303,8 @@ gui_bar_new (struct t_weechat_plugin *plugin, const char *name, if (gui_bar_search_position (position) < 0) return NULL; + option_hidden = gui_bar_create_option (name, GUI_BAR_OPTION_HIDDEN, + hidden); option_priority = gui_bar_create_option (name, GUI_BAR_OPTION_PRIORITY, priority); option_type = gui_bar_create_option (name, GUI_BAR_OPTION_TYPE, @@ -1262,15 +1330,17 @@ gui_bar_new (struct t_weechat_plugin *plugin, const char *name, "on" : "off"); option_items = gui_bar_create_option (name, GUI_BAR_OPTION_ITEMS, items); - new_bar = gui_bar_new_with_options (plugin, name, option_priority, - option_type,option_conditions, - option_position, option_filling, - option_size, option_size_max, - option_color_fg, option_color_delim, - option_color_bg, option_separator, - option_items); + new_bar = gui_bar_new_with_options (plugin, name, option_hidden, + option_priority, option_type, + option_conditions, option_position, + option_filling, option_size, + option_size_max, option_color_fg, + option_color_delim, option_color_bg, + option_separator, option_items); if (!new_bar) { + if (option_hidden) + config_file_option_free (option_hidden); if (option_priority) config_file_option_free (option_priority); if (option_type) @@ -1312,6 +1382,10 @@ gui_bar_use_temp_bars () for (ptr_temp_bar = gui_temp_bars; ptr_temp_bar; ptr_temp_bar = ptr_temp_bar->next_bar) { + if (!ptr_temp_bar->hidden) + ptr_temp_bar->hidden = gui_bar_create_option (ptr_temp_bar->name, + GUI_BAR_OPTION_HIDDEN, + "0"); if (!ptr_temp_bar->priority) ptr_temp_bar->priority = gui_bar_create_option (ptr_temp_bar->name, GUI_BAR_OPTION_PRIORITY, @@ -1373,14 +1447,17 @@ gui_bar_use_temp_bars () GUI_BAR_OPTION_ITEMS, ""); - if (ptr_temp_bar->priority && ptr_temp_bar->type - && ptr_temp_bar->conditions && ptr_temp_bar->position - && ptr_temp_bar->filling && ptr_temp_bar->size - && ptr_temp_bar->size_max && ptr_temp_bar->color_fg - && ptr_temp_bar->color_delim && ptr_temp_bar->color_bg - && ptr_temp_bar->separator && ptr_temp_bar->items) + if (ptr_temp_bar->hidden && ptr_temp_bar->priority + && ptr_temp_bar->type && ptr_temp_bar->conditions + && ptr_temp_bar->position && ptr_temp_bar->filling + && ptr_temp_bar->size && ptr_temp_bar->size_max + && ptr_temp_bar->color_fg && ptr_temp_bar->color_delim + && ptr_temp_bar->color_bg && ptr_temp_bar->separator + && ptr_temp_bar->items) { - gui_bar_new_with_options (NULL, ptr_temp_bar->name, + gui_bar_new_with_options (NULL, + ptr_temp_bar->name, + ptr_temp_bar->hidden, ptr_temp_bar->priority, ptr_temp_bar->type, ptr_temp_bar->conditions, @@ -1396,6 +1473,11 @@ gui_bar_use_temp_bars () } else { + if (ptr_temp_bar->hidden) + { + config_file_option_free (ptr_temp_bar->hidden); + ptr_temp_bar->hidden = NULL; + } if (ptr_temp_bar->priority) { config_file_option_free (ptr_temp_bar->priority); @@ -1484,7 +1566,7 @@ gui_bar_update (const char *name) for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { - if (strcmp (ptr_bar->name, name) == 0) + if (!CONFIG_BOOLEAN(ptr_bar->hidden) && (strcmp (ptr_bar->name, name) == 0)) gui_bar_draw (ptr_bar); } } @@ -1518,6 +1600,8 @@ gui_bar_free (struct t_gui_bar *bar) /* free data */ if (bar->name) free (bar->name); + if (bar->hidden) + config_file_option_free (bar->hidden); if (bar->priority) config_file_option_free (bar->priority); if (bar->type) @@ -1599,6 +1683,7 @@ gui_bar_print_log () log_printf ("[bar (addr:0x%x)]", ptr_bar); log_printf (" plugin . . . . . . . . : 0x%x", ptr_bar->plugin); log_printf (" name . . . . . . . . . : '%s'", ptr_bar->name); + log_printf (" hidden . . . . . . . . : %d", CONFIG_INTEGER(ptr_bar->hidden)); log_printf (" priority . . . . . . . : %d", CONFIG_INTEGER(ptr_bar->priority)); log_printf (" type . . . . . . . . . : %d (%s)", CONFIG_INTEGER(ptr_bar->type), diff --git a/src/gui/gui-bar.h b/src/gui/gui-bar.h index e7a176536..e394a97c6 100644 --- a/src/gui/gui-bar.h +++ b/src/gui/gui-bar.h @@ -25,7 +25,8 @@ struct t_gui_window; enum t_gui_bar_option { - GUI_BAR_OPTION_PRIORITY = 0, + GUI_BAR_OPTION_HIDDEN = 0, + GUI_BAR_OPTION_PRIORITY, GUI_BAR_OPTION_TYPE, GUI_BAR_OPTION_CONDITIONS, GUI_BAR_OPTION_POSITION, @@ -72,6 +73,7 @@ struct t_gui_bar /* user choices */ struct t_weechat_plugin *plugin; /* plugin */ char *name; /* bar name */ + struct t_config_option *hidden; /* true if bar is hidden */ struct t_config_option *priority; /* bar priority */ struct t_config_option *type; /* type (root or window) */ struct t_config_option *conditions; /* conditions for display */ @@ -121,8 +123,9 @@ extern void gui_bar_create_option_temp (struct t_gui_bar *temp_bar, int index_option, const char *value); extern struct t_gui_bar *gui_bar_alloc (const char *name); extern struct t_gui_bar *gui_bar_new (struct t_weechat_plugin *plugin, - const char *name, const char *priority, - const char *type, const char *conditions, + const char *name, const char *hidden, + const char *priority, const char *type, + const char *conditions, const char *position, const char *filling, const char *size, const char *size_max, diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 5302686f8..34778fb00 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -600,6 +600,7 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, { gui_input_delete_line (buffer); gui_input_insert_string (buffer, value, 0); + gui_input_text_changed_signal (); gui_buffer_ask_input_refresh (buffer, 1); } } diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index b68e10079..be0091fa1 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -137,6 +137,28 @@ gui_chat_strlen_screen (const char *string) } /* + * gui_chat_string_add_offset: move forward N chars in a string, skipping all + * formatting chars (like colors,..) + */ + +char * +gui_chat_string_add_offset (const char *string, int offset) +{ + while (string && string[0] && (offset > 0)) + { + string = gui_chat_string_next_char (NULL, + (unsigned char *)string, + 0); + if (string) + { + string = utf8_next_char (string); + offset--; + } + } + return (char *)string; +} + +/* * gui_chat_string_real_pos: get real position in string * (ignoring color/bold/.. chars) */ diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index cc4181188..30c7c6894 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -51,6 +51,7 @@ extern int gui_chat_time_length; extern void gui_chat_prefix_build_empty (); extern void gui_chat_prefix_build (); extern int gui_chat_strlen_screen (const char *string); +extern char *gui_chat_string_add_offset (const char *string, int offset); extern int gui_chat_string_real_pos (const char *string, int pos); extern void gui_chat_get_word_info (struct t_gui_window *window, const char *data, int *word_start_offset, diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c index 48f849ae4..920771bd7 100644 --- a/src/gui/gui-color.c +++ b/src/gui/gui-color.c @@ -125,47 +125,53 @@ gui_color_get_custom (const char *color_name) { snprintf (color[index_color], sizeof (color[index_color]), "%s%s", - GUI_COLOR_SET_STR, + GUI_COLOR_SET_WEECHAT_STR, GUI_COLOR_ATTR_BOLD_STR); } else if (string_strcasecmp (color_name, "reverse") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%s%s", - GUI_COLOR_SET_STR, + GUI_COLOR_SET_WEECHAT_STR, GUI_COLOR_ATTR_REVERSE_STR); } else if (string_strcasecmp (color_name, "italic") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%s%s", - GUI_COLOR_SET_STR, + GUI_COLOR_SET_WEECHAT_STR, GUI_COLOR_ATTR_ITALIC_STR); } else if (string_strcasecmp (color_name, "underline") == 0) { snprintf (color[index_color], sizeof (color[index_color]), "%s%s", - GUI_COLOR_SET_STR, + GUI_COLOR_SET_WEECHAT_STR, GUI_COLOR_ATTR_UNDERLINE_STR); } else if (string_strcasecmp (color_name, "bar_fg") == 0) { snprintf (color[index_color], sizeof (color[index_color]), - "%cbf", - GUI_COLOR_COLOR_CHAR); + "%c%c%c", + GUI_COLOR_COLOR_CHAR, + GUI_COLOR_BAR_CHAR, + GUI_COLOR_BAR_FG_CHAR); } else if (string_strcasecmp (color_name, "bar_delim") == 0) { snprintf (color[index_color], sizeof (color[index_color]), - "%cbd", - GUI_COLOR_COLOR_CHAR); + "%c%c%c", + GUI_COLOR_COLOR_CHAR, + GUI_COLOR_BAR_CHAR, + GUI_COLOR_BAR_DELIM_CHAR); } else if (string_strcasecmp (color_name, "bar_bg") == 0) { snprintf (color[index_color], sizeof (color[index_color]), - "%cbb", - GUI_COLOR_COLOR_CHAR); + "%c%c%c", + GUI_COLOR_COLOR_CHAR, + GUI_COLOR_BAR_CHAR, + GUI_COLOR_BAR_BG_CHAR); } else { @@ -256,8 +262,8 @@ gui_color_decode (const unsigned char *string) break; } break; - case GUI_COLOR_SET_CHAR: - case GUI_COLOR_REMOVE_CHAR: + case GUI_COLOR_SET_WEECHAT_CHAR: + case GUI_COLOR_REMOVE_WEECHAT_CHAR: string++; if (string[0]) string++; diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h index f943dd7a5..41937d083 100644 --- a/src/gui/gui-color.h +++ b/src/gui/gui-color.h @@ -96,30 +96,47 @@ enum t_gui_color_enum /* WeeChat internal color attributes (should never be in protocol messages) */ -#define GUI_COLOR_COLOR_CHAR '\x19' -#define GUI_COLOR_COLOR_STR "\x19" -#define GUI_COLOR_SET_CHAR '\x1A' -#define GUI_COLOR_SET_STR "\x1A" -#define GUI_COLOR_REMOVE_CHAR '\x1B' -#define GUI_COLOR_REMOVE_STR "\x1B" -#define GUI_COLOR_RESET_CHAR '\x1C' -#define GUI_COLOR_RESET_STR "\x1C" - -#define GUI_COLOR_ATTR_BOLD_CHAR '\x01' -#define GUI_COLOR_ATTR_BOLD_STR "\x01" -#define GUI_COLOR_ATTR_REVERSE_CHAR '\x02' -#define GUI_COLOR_ATTR_REVERSE_STR "\x02" -#define GUI_COLOR_ATTR_ITALIC_CHAR '\x03' -#define GUI_COLOR_ATTR_ITALIC_STR "\x03" -#define GUI_COLOR_ATTR_UNDERLINE_CHAR '\x04' -#define GUI_COLOR_ATTR_UNDERLINE_STR "\x04" +#define GUI_COLOR_COLOR_CHAR '\x19' +#define GUI_COLOR_COLOR_STR "\x19" +#define GUI_COLOR_SET_WEECHAT_CHAR '\x1A' +#define GUI_COLOR_SET_WEECHAT_STR "\x1A" +#define GUI_COLOR_REMOVE_WEECHAT_CHAR '\x1B' +#define GUI_COLOR_REMOVE_WEECHAT_STR "\x1B" +#define GUI_COLOR_RESET_CHAR '\x1C' +#define GUI_COLOR_RESET_STR "\x1C" + +#define GUI_COLOR_ATTR_BOLD_CHAR '\x01' +#define GUI_COLOR_ATTR_BOLD_STR "\x01" +#define GUI_COLOR_ATTR_REVERSE_CHAR '\x02' +#define GUI_COLOR_ATTR_REVERSE_STR "\x02" +#define GUI_COLOR_ATTR_ITALIC_CHAR '\x03' +#define GUI_COLOR_ATTR_ITALIC_STR "\x03" +#define GUI_COLOR_ATTR_UNDERLINE_CHAR '\x04' +#define GUI_COLOR_ATTR_UNDERLINE_STR "\x04" #define GUI_COLOR(color) ((gui_color[color]) ? gui_color[color]->string : "") #define GUI_NO_COLOR GUI_COLOR_RESET_STR -#define GUI_COLOR_BAR_FG (gui_color_get_custom ("bar_fg")) -#define GUI_COLOR_BAR_DELIM (gui_color_get_custom ("bar_delim")) -#define GUI_COLOR_BAR_BG (gui_color_get_custom ("bar_bg")) +#define GUI_COLOR_CUSTOM_BAR_FG (gui_color_get_custom ("bar_fg")) +#define GUI_COLOR_CUSTOM_BAR_DELIM (gui_color_get_custom ("bar_delim")) +#define GUI_COLOR_CUSTOM_BAR_BG (gui_color_get_custom ("bar_bg")) + +#define GUI_COLOR_FG_CHAR 'F' +#define GUI_COLOR_FG_STR "F" +#define GUI_COLOR_BG_CHAR 'B' +#define GUI_COLOR_BG_STR "B" +#define GUI_COLOR_FG_BG_CHAR '*' +#define GUI_COLOR_FG_BG_STR "*" +#define GUI_COLOR_BAR_CHAR 'b' +#define GUI_COLOR_BAR_STR "b" +#define GUI_COLOR_BAR_FG_CHAR 'F' +#define GUI_COLOR_BAR_FG_STR "F" +#define GUI_COLOR_BAR_DELIM_CHAR 'D' +#define GUI_COLOR_BAR_DELIM_STR "D" +#define GUI_COLOR_BAR_BG_CHAR 'B' +#define GUI_COLOR_BAR_BG_STR "B" +#define GUI_COLOR_BAR_MOVE_CURSOR_CHAR '#' +#define GUI_COLOR_BAR_MOVE_CURSOR_STR "#" /* color structure */ diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index a14d749c9..1c6c069f8 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -28,6 +28,7 @@ #include "../core/weechat.h" #include "../core/wee-config.h" +#include "../core/wee-hook.h" #include "../core/wee-input.h" #include "../core/wee-string.h" #include "../core/wee-utf8.h" @@ -47,6 +48,36 @@ char *gui_input_clipboard = NULL; /* clipboard content */ /* + * gui_input_prompt_changed_signal: send signal "input_prompt_changed" + */ + +void +gui_input_prompt_changed_signal () +{ + hook_signal_send ("input_prompr_changed", WEECHAT_HOOK_SIGNAL_STRING, NULL); +} + +/* + * gui_input_text_changed_signal: send signal "input_text_changed" + */ + +void +gui_input_text_changed_signal () +{ + hook_signal_send ("input_text_changed", WEECHAT_HOOK_SIGNAL_STRING, NULL); +} + +/* + * gui_input_text_cursor_moved_signal: send signal "input_text_cursor_moved" + */ + +void +gui_input_text_cursor_moved_signal () +{ + hook_signal_send ("input_text_cursor_moved", WEECHAT_HOOK_SIGNAL_STRING, NULL); +} + +/* * gui_input_optimize_size: optimize input buffer size by adding * or deleting data block (predefined size) */ @@ -285,7 +316,9 @@ gui_input_clipboard_paste () gui_input_insert_string (gui_current_window->buffer, gui_input_clipboard, -1); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_draw (gui_current_window->buffer, 0); + + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } @@ -321,7 +354,8 @@ gui_input_return () gui_completion_stop (gui_current_window->buffer->completion, 1); gui_current_window->buffer->ptr_history = NULL; gui_input_optimize_size (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); input_data (gui_current_window->buffer, command); free (command); } @@ -440,7 +474,8 @@ gui_input_complete (struct t_gui_buffer *buffer) buffer->completion->position++; } } - gui_input_draw (buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } @@ -461,6 +496,7 @@ gui_input_complete_next () utf8_real_pos (gui_current_window->buffer->input_buffer, gui_current_window->buffer->input_buffer_pos)); gui_input_complete (gui_current_window->buffer); + gui_input_text_changed_signal (); } } @@ -481,6 +517,7 @@ gui_input_complete_previous () utf8_real_pos (gui_current_window->buffer->input_buffer, gui_current_window->buffer->input_buffer_pos)); gui_input_complete (gui_current_window->buffer); + gui_input_text_changed_signal (); } } @@ -500,7 +537,7 @@ gui_input_search_text () { gui_current_window->buffer->text_search_exact ^= 1; gui_window_search_restart (gui_current_window); - gui_input_draw (gui_current_window->buffer, 1); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); } } } @@ -532,8 +569,9 @@ gui_input_delete_previous_char () gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; gui_current_window->buffer->input_buffer_color_mask[gui_current_window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); gui_completion_stop (gui_current_window->buffer->completion, 1); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } } @@ -564,8 +602,9 @@ gui_input_delete_next_char () gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; gui_current_window->buffer->input_buffer_color_mask[gui_current_window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); gui_completion_stop (gui_current_window->buffer->completion, 1); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } } @@ -624,8 +663,9 @@ gui_input_delete_previous_word () gui_current_window->buffer->input_buffer_color_mask[gui_current_window->buffer->input_buffer_size] = '\0'; gui_current_window->buffer->input_buffer_pos -= length_deleted; gui_input_optimize_size (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); gui_completion_stop (gui_current_window->buffer->completion, 1); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } } @@ -664,8 +704,9 @@ gui_input_delete_next_word () gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; gui_current_window->buffer->input_buffer_color_mask[gui_current_window->buffer->input_buffer_size] = '\0'; gui_input_optimize_size (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); gui_completion_stop (gui_current_window->buffer->completion, 1); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } @@ -701,8 +742,9 @@ gui_input_delete_beginning_of_line () gui_current_window->buffer->input_buffer_color_mask[gui_current_window->buffer->input_buffer_size] = '\0'; gui_current_window->buffer->input_buffer_pos = 0; gui_input_optimize_size (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); gui_completion_stop (gui_current_window->buffer->completion, 1); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } } @@ -734,8 +776,9 @@ gui_input_delete_end_of_line (const char *args) gui_current_window->buffer->input_buffer_size = strlen (gui_current_window->buffer->input_buffer); gui_current_window->buffer->input_buffer_length = utf8_strlen (gui_current_window->buffer->input_buffer); gui_input_optimize_size (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); gui_completion_stop (gui_current_window->buffer->completion, 1); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } @@ -755,7 +798,8 @@ gui_input_delete_line () gui_current_window->buffer->input_buffer_pos = 0; gui_input_optimize_size (gui_current_window->buffer); gui_completion_stop (gui_current_window->buffer->completion, 1); - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } @@ -800,8 +844,10 @@ gui_input_transpose_chars () gui_current_window->buffer->input_buffer_pos++; - gui_input_draw (gui_current_window->buffer, 0); gui_completion_stop (gui_current_window->buffer->completion, 1); + + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } } @@ -818,7 +864,9 @@ gui_input_move_beginning_of_line () if (gui_current_window->buffer->input_buffer_pos > 0) { gui_current_window->buffer->input_buffer_pos = 0; - gui_input_draw (gui_current_window->buffer, 0); + + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_cursor_moved_signal (); } } } @@ -837,7 +885,9 @@ gui_input_move_end_of_line () { gui_current_window->buffer->input_buffer_pos = gui_current_window->buffer->input_buffer_length; - gui_input_draw (gui_current_window->buffer, 0); + + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_cursor_moved_signal (); } } } @@ -854,7 +904,9 @@ gui_input_move_previous_char () if (gui_current_window->buffer->input_buffer_pos > 0) { gui_current_window->buffer->input_buffer_pos--; - gui_input_draw (gui_current_window->buffer, 0); + + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_cursor_moved_signal (); } } } @@ -872,7 +924,9 @@ gui_input_move_next_char () gui_current_window->buffer->input_buffer_length) { gui_current_window->buffer->input_buffer_pos++; - gui_input_draw (gui_current_window->buffer, 0); + + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_cursor_moved_signal (); } } } @@ -913,7 +967,8 @@ gui_input_move_previous_word () else gui_current_window->buffer->input_buffer_pos = 0; - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_cursor_moved_signal (); } } } @@ -958,7 +1013,8 @@ gui_input_move_next_word () utf8_pos (gui_current_window->buffer->input_buffer, utf8_prev_char (gui_current_window->buffer->input_buffer, pos) - gui_current_window->buffer->input_buffer); - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_cursor_moved_signal (); } } } @@ -1020,8 +1076,9 @@ gui_input_history_previous () strcpy (gui_current_window->buffer->input_buffer, gui_current_window->buffer->ptr_history->text); gui_input_init_color_mask (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); } + gui_input_text_changed_signal (); } else { @@ -1069,7 +1126,7 @@ gui_input_history_next () gui_current_window->buffer->ptr_history->text); gui_input_init_color_mask (gui_current_window->buffer); } - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); } else { @@ -1085,9 +1142,10 @@ gui_input_history_next () gui_input_optimize_size (gui_current_window->buffer); gui_current_window->buffer->input_buffer_pos = 0; gui_current_window->buffer->input_buffer_1st_display = 0; - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); } } + gui_input_text_changed_signal (); } else { @@ -1130,7 +1188,8 @@ gui_input_history_global_previous () strcpy (gui_current_window->buffer->input_buffer, history_global_ptr->text); gui_input_init_color_mask (gui_current_window->buffer); - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } } @@ -1171,7 +1230,8 @@ gui_input_history_global_next () history_global_ptr->text); gui_input_init_color_mask (gui_current_window->buffer); } - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); } } } @@ -1346,7 +1406,8 @@ gui_input_insert (const char *args) { args2 = string_convert_hex_chars (args); gui_input_insert_string (gui_current_window->buffer, (args2) ? args2 : args, -1); - gui_input_draw (gui_current_window->buffer, 0); + gui_buffer_ask_input_refresh (gui_current_window->buffer, 1); + gui_input_text_changed_signal (); if (args2) free (args2); } diff --git a/src/gui/gui-input.h b/src/gui/gui-input.h index 148cda6e5..d8d5fe796 100644 --- a/src/gui/gui-input.h +++ b/src/gui/gui-input.h @@ -28,6 +28,8 @@ extern char *gui_input_clipboard; /* input functions */ +extern void gui_input_prompt_changed_signal (); +extern void gui_input_text_changed_signal (); extern void gui_input_optimize_size (struct t_gui_buffer *buffer); extern void gui_input_init_color_mask (struct t_gui_buffer *buffer); extern void gui_input_move (struct t_gui_buffer *buffer, char *target, diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index 35541f3d6..5c8b027af 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -116,6 +116,7 @@ gui_keyboard_grab_end () if (gui_current_window->buffer->completion) gui_completion_stop (gui_current_window->buffer->completion, 1); gui_input_draw (gui_current_window->buffer, 0); + gui_input_text_changed_signal (); } free (expanded_key); } diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 90ad30893..47defd485 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -867,6 +867,7 @@ gui_window_search_stop (struct t_gui_window *window) { gui_input_insert_string (window->buffer, window->buffer->text_search_input, -1); + gui_input_text_changed_signal (); free (window->buffer->text_search_input); window->buffer->text_search_input = NULL; } diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 57be59a0b..2bce09a6d 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -4037,8 +4037,8 @@ weechat_lua_api_bar_search (lua_State *L) static int weechat_lua_api_bar_new (lua_State *L) { - const char *name, *priority, *type, *conditions, *position, *filling; - const char *size, *size_max, *color_fg, *color_delim, *color_bg; + const char *name, *hidden, *priority, *type, *conditions, *position; + const char *filling, *size, *size_max, *color_fg, *color_delim, *color_bg; const char *separator, *items; char *result; int n; @@ -4053,6 +4053,7 @@ weechat_lua_api_bar_new (lua_State *L) } name = NULL; + hidden = NULL; priority = NULL; type = NULL; conditions = NULL; @@ -4068,13 +4069,14 @@ weechat_lua_api_bar_new (lua_State *L) n = lua_gettop (lua_current_interpreter); - if (n < 13) + if (n < 14) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new"); LUA_RETURN_EMPTY; } - name = lua_tostring (lua_current_interpreter, -13); + name = lua_tostring (lua_current_interpreter, -14); + hidden = lua_tostring (lua_current_interpreter, -13); priority = lua_tostring (lua_current_interpreter, -12); type = lua_tostring (lua_current_interpreter, -11); conditions = lua_tostring (lua_current_interpreter, -10); @@ -4089,6 +4091,7 @@ weechat_lua_api_bar_new (lua_State *L) items = lua_tostring (lua_current_interpreter, -1); result = script_ptr2str (weechat_bar_new (name, + hidden, priority, type, conditions, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index 47a9c6a9a..aa0a6e0b6 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -3353,9 +3353,9 @@ static XS (XS_weechat_bar_search) static XS (XS_weechat_bar_new) { - char *result, *name, *priority, *type, *conditions, *position, *filling; - char *size, *size_max, *color_fg, *color_delim, *color_bg, *separator; - char *bar_items; + char *result, *name, *hidden, *priority, *type, *conditions, *position; + char *filling, *size, *size_max, *color_fg, *color_delim, *color_bg; + char *separator, *bar_items; dXSARGS; /* make C compiler happy */ @@ -3367,26 +3367,28 @@ static XS (XS_weechat_bar_new) PERL_RETURN_EMPTY; } - if (items < 13) + if (items < 14) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new"); PERL_RETURN_EMPTY; } name = SvPV (ST (0), PL_na); - priority = SvPV (ST (1), PL_na); - type = SvPV (ST (2), PL_na); - conditions = SvPV (ST (3), PL_na); - position = SvPV (ST (4), PL_na); - filling = SvPV (ST (5), PL_na); - size = SvPV (ST (6), PL_na); - size_max = SvPV (ST (7), PL_na); - color_fg = SvPV (ST (8), PL_na); - color_delim = SvPV (ST (9), PL_na); - color_bg = SvPV (ST (10), PL_na); - separator = SvPV (ST (11), PL_na); - bar_items = SvPV (ST (12), PL_na); + hidden = SvPV (ST (1), PL_na); + priority = SvPV (ST (2), PL_na); + type = SvPV (ST (3), PL_na); + conditions = SvPV (ST (4), PL_na); + position = SvPV (ST (5), PL_na); + filling = SvPV (ST (6), PL_na); + size = SvPV (ST (7), PL_na); + size_max = SvPV (ST (8), PL_na); + color_fg = SvPV (ST (9), PL_na); + color_delim = SvPV (ST (10), PL_na); + color_bg = SvPV (ST (11), PL_na); + separator = SvPV (ST (12), PL_na); + bar_items = SvPV (ST (13), PL_na); result = script_ptr2str (weechat_bar_new (name, + hidden, priority, type, conditions, diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index 484e3b850..acff1681e 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -3565,9 +3565,9 @@ weechat_python_api_bar_search (PyObject *self, PyObject *args) static PyObject * weechat_python_api_bar_new (PyObject *self, PyObject *args) { - char *name, *priority, *type, *conditions, *position, *filling, *size; - char *size_max, *color_fg, *color_delim, *color_bg, *separator, *items; - char *result; + char *name, *hidden, *priority, *type, *conditions, *position, *filling; + char *size, *size_max, *color_fg, *color_delim, *color_bg, *separator; + char *items, *result; PyObject *object; /* make C compiler happy */ @@ -3580,6 +3580,7 @@ weechat_python_api_bar_new (PyObject *self, PyObject *args) } name = NULL; + hidden = NULL; priority = NULL; type = NULL; conditions = NULL; @@ -3593,7 +3594,7 @@ weechat_python_api_bar_new (PyObject *self, PyObject *args) separator = NULL; items = NULL; - if (!PyArg_ParseTuple (args, "sssssssssssss", &name, &priority, + if (!PyArg_ParseTuple (args, "ssssssssssssss", &name, &hidden, &priority, &conditions, &type, &position, &filling, &size, &size_max, &color_fg, &color_delim, &color_bg, &separator, &items)) @@ -3603,6 +3604,7 @@ weechat_python_api_bar_new (PyObject *self, PyObject *args) } result = script_ptr2str (weechat_bar_new (name, + hidden, priority, type, conditions, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index 0b68e7038..72d61b803 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -4093,15 +4093,15 @@ weechat_ruby_api_bar_search (VALUE class, VALUE name) */ static VALUE -weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type, - VALUE conditions, VALUE position, VALUE filling, - VALUE size, VALUE size_max, VALUE color_fg, - VALUE color_delim, VALUE color_bg, VALUE separator, - VALUE items) +weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE hidden, + VALUE priority, VALUE type, VALUE conditions, + VALUE position, VALUE filling, VALUE size, + VALUE size_max, VALUE color_fg, VALUE color_delim, + VALUE color_bg, VALUE separator, VALUE items) { - char *c_name, *c_priority, *c_type, *c_conditions, *c_position, *c_filling; - char *c_size, *c_size_max, *c_color_fg, *c_color_delim, *c_color_bg; - char *c_separator, *c_items; + char *c_name, *c_hidden, *c_priority, *c_type, *c_conditions, *c_position; + char *c_filling, *c_size, *c_size_max, *c_color_fg, *c_color_delim; + char *c_color_bg, *c_separator, *c_items; char *result; VALUE return_value; @@ -4115,6 +4115,7 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type, } c_name = NULL; + c_hidden = NULL; c_priority = NULL; c_type = NULL; c_conditions = NULL; @@ -4128,16 +4129,18 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type, c_separator = NULL; c_items = NULL; - if (NIL_P (name) || NIL_P (priority) || NIL_P (type) || NIL_P (conditions) - || NIL_P (position) || NIL_P (filling) || NIL_P (size) - || NIL_P (size_max) || NIL_P (color_fg) || NIL_P (color_delim) - || NIL_P (color_bg) || NIL_P (separator) || NIL_P (items)) + if (NIL_P (name) || NIL_P (hidden) || NIL_P (priority) || NIL_P (type) + || NIL_P (conditions) || NIL_P (position) || NIL_P (filling) + || NIL_P (size) || NIL_P (size_max) || NIL_P (color_fg) + || NIL_P (color_delim) || NIL_P (color_bg) || NIL_P (separator) + || NIL_P (items)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("bar_new"); RUBY_RETURN_EMPTY; } Check_Type (name, T_STRING); + Check_Type (hidden, T_STRING); Check_Type (priority, T_STRING); Check_Type (type, T_STRING); Check_Type (conditions, T_STRING); @@ -4152,6 +4155,7 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type, Check_Type (items, T_STRING); c_name = STR2CSTR (name); + c_hidden = STR2CSTR (hidden); c_priority = STR2CSTR (priority); c_type = STR2CSTR (type); c_conditions = STR2CSTR (conditions); @@ -4166,6 +4170,7 @@ weechat_ruby_api_bar_new (VALUE class, VALUE name, VALUE priority, VALUE type, c_items = STR2CSTR (items); result = script_ptr2str (weechat_bar_new (c_name, + c_hidden, c_priority, c_type, c_conditions, @@ -4798,7 +4803,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "bar_item_update", &weechat_ruby_api_bar_item_update, 1); rb_define_module_function (ruby_mWeechat, "bar_item_remove", &weechat_ruby_api_bar_item_remove, 1); rb_define_module_function (ruby_mWeechat, "bar_search", &weechat_ruby_api_bar_search, 1); - rb_define_module_function (ruby_mWeechat, "bar_new", &weechat_ruby_api_bar_new, 13); + rb_define_module_function (ruby_mWeechat, "bar_new", &weechat_ruby_api_bar_new, 14); rb_define_module_function (ruby_mWeechat, "bar_set", &weechat_ruby_api_bar_set, 3); rb_define_module_function (ruby_mWeechat, "bar_update", &weechat_ruby_api_bar_update, 1); rb_define_module_function (ruby_mWeechat, "bar_remove", &weechat_ruby_api_bar_remove, 1); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 904773b8b..149affa1b 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -424,13 +424,18 @@ struct t_weechat_plugin struct t_gui_bar *(*bar_search) (const char *name); struct t_gui_bar *(*bar_new) (struct t_weechat_plugin *plugin, const char *name, - const char *priority, const char *type, + const char *hidden, + const char *priority, + const char *type, const char *condition, - const char *position, const char *filling, + const char *position, + const char *filling, const char *size, - const char *size_max, const char *color_fg, + const char *size_max, + const char *color_fg, const char *color_delim, - const char *color_bg, const char *separator, + const char *color_bg, + const char *separator, const char *items); int (*bar_set) (struct t_gui_bar *bar, const char *property, const char *value); @@ -856,14 +861,16 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->bar_item_remove(__item) #define weechat_bar_search(__name) \ weechat_plugin->bar_search(__name) -#define weechat_bar_new(__name, __priority, __type, __condition, \ - __position, __filling, __size, __size_max, \ - __color_fg, __color_delim, __color_bg, \ - __separator, __items) \ - weechat_plugin->bar_new(weechat_plugin, __name, __priority, __type, \ - __condition, __position, __filling, __size, \ - __size_max, __color_fg, __color_delim, \ - __color_bg, __separator, __items) +#define weechat_bar_new(__name, __hidden, __priority, __type, \ + __condition, __position, __filling, __size, \ + __size_max, __color_fg, __color_delim, \ + __color_bg, \ + __separator, __items) \ + weechat_plugin->bar_new(weechat_plugin, __name, __hidden, \ + __priority, __type, __condition, \ + __position, __filling, __size, __size_max, \ + __color_fg, __color_delim, __color_bg, \ + __separator, __items) #define weechat_bar_set(__bar, __property, __value) \ weechat_plugin->bar_set(__bar, __property, __value) #define weechat_bar_update(__name) \ |