diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2007-03-16 15:02:47 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2007-03-16 15:02:47 +0000 |
commit | 0f0f7511d2d087f66a66e45d5200183106b0ef63 (patch) | |
tree | 2705f896e9184af2bba362b844e5252f0d19845c /src/gui | |
parent | aa149dcfbc209a1addf40fdcfb826105d1940fbd (diff) | |
download | weechat-0f0f7511d2d087f66a66e45d5200183106b0ef63.zip |
Added new key (ctrl-S) for interactive and incremental search in buffer history (task #6628)
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/curses/gui-curses-input.c | 13 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-keyboard.c | 32 | ||||
-rw-r--r-- | src/gui/gui-action.c | 371 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 136 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 8 | ||||
-rw-r--r-- | src/gui/gui-keyboard.c | 15 | ||||
-rw-r--r-- | src/gui/gui.h | 5 |
7 files changed, 420 insertions, 160 deletions
diff --git a/src/gui/curses/gui-curses-input.c b/src/gui/curses/gui-curses-input.c index 0e1c1349e..fb715cf47 100644 --- a/src/gui/curses/gui-curses-input.c +++ b/src/gui/curses/gui-curses-input.c @@ -78,6 +78,9 @@ gui_input_get_prompt_length (t_gui_window *window, char *nick) char *pos, saved_char; int char_size, length; + if (window->buffer->text_search != TEXT_SEARCH_DISABLED) + return utf8_width_screen (_("Text search: ")); + length = 0; pos = cfg_look_input_format; while (pos && pos[0]) @@ -152,6 +155,16 @@ gui_input_draw_prompt (t_gui_window *window, char *nick) int char_size; wmove (GUI_CURSES(window)->win_input, 0, 0); + + if (window->buffer->text_search != TEXT_SEARCH_DISABLED) + { + gui_window_set_weechat_color (GUI_CURSES(window)->win_input, + COLOR_WIN_INPUT); + wprintw (GUI_CURSES(window)->win_input, "%s", + _("Text search: ")); + return; + } + pos = cfg_look_input_format; while (pos && pos[0]) { diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c index 891941b9e..e6e322297 100644 --- a/src/gui/curses/gui-curses-keyboard.c +++ b/src/gui/curses/gui-curses-keyboard.c @@ -49,8 +49,8 @@ gui_keyboard_default_bindings () gui_keyboard_bind ( /* RC */ "ctrl-J", "return"); gui_keyboard_bind ( /* tab */ "ctrl-I", "tab"); gui_keyboard_bind ( /* s-tab */ "meta2-Z", "tab_previous"); - gui_keyboard_bind ( /* basckp */ "ctrl-H", "backspace"); - gui_keyboard_bind ( /* basckp */ "ctrl-?", "backspace"); + gui_keyboard_bind ( /* basckpace */ "ctrl-H", "backspace"); + gui_keyboard_bind ( /* basckpace */ "ctrl-?", "backspace"); gui_keyboard_bind ( /* del */ "meta2-3~", "delete"); gui_keyboard_bind ( /* ^K */ "ctrl-K", "delete_end_line"); gui_keyboard_bind ( /* ^U */ "ctrl-U", "delete_beginning_line"); @@ -105,6 +105,7 @@ gui_keyboard_default_bindings () gui_keyboard_bind ( /* m-r */ "meta-r", "delete_line"); gui_keyboard_bind ( /* m-s */ "meta-s", "switch_server"); gui_keyboard_bind ( /* m-u */ "meta-u", "scroll_unread"); + gui_keyboard_bind ( /* ^S */ "ctrl-S", "search_text"); /* keys bound with commands */ gui_keyboard_bind ( /* m-left */ "meta-meta2-D", "/buffer -1"); @@ -174,7 +175,7 @@ void gui_keyboard_read () { int key, i, insert_ok; - char key_str[32], *key_utf; + char key_str[32], *key_utf, *input_old; i = 0; /* do not loop too much here (for example when big paste was made), @@ -272,6 +273,12 @@ gui_keyboard_read () /*gui_printf (gui_current_window->buffer, "gui_input_read: key = %s (%d)\n", key_str, key);*/ + if (gui_current_window->buffer->text_search != TEXT_SEARCH_DISABLED) + input_old = (gui_current_window->buffer->input_buffer) ? + strdup (gui_current_window->buffer->input_buffer) : strdup (""); + else + input_old = NULL; + if ((gui_keyboard_pressed (key_str) != 0) && (insert_ok)) { if (strcmp (key_str, "^^") == 0) @@ -292,6 +299,25 @@ gui_keyboard_read () break; } } + + /* incremental text search in buffer */ + if ((gui_current_window->buffer->text_search != TEXT_SEARCH_DISABLED) + && ((input_old == NULL) || (gui_current_window->buffer->input_buffer == NULL) + || (strcmp (input_old, gui_current_window->buffer->input_buffer) != 0))) + { + gui_current_window->start_line = NULL; + gui_current_window->start_line_pos = 0; + gui_current_window->buffer->text_search = TEXT_SEARCH_BACKWARD; + if (!gui_buffer_search_text (gui_current_window)) + { + gui_chat_draw (gui_current_window->buffer, 1); + gui_status_draw (gui_current_window->buffer, 1); + } + } + + if (input_old) + free (input_old); + i++; } } diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c index 2d008cb71..1b24b54eb 100644 --- a/src/gui/gui-action.c +++ b/src/gui/gui-action.c @@ -91,13 +91,15 @@ void gui_action_return (t_gui_window *window, char *args) { char *command; - + /* make C compiler happy */ (void) args; if (window->buffer->has_input) { - if (window->buffer->input_buffer_size > 0) + if (window->buffer->text_search != TEXT_SEARCH_DISABLED) + gui_buffer_search_stop (window); + else if (window->buffer->input_buffer_size > 0) { window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; @@ -133,7 +135,8 @@ gui_action_tab (t_gui_window *window, char *args) /* make C compiler happy */ (void) args; - if (window->buffer->has_input) + if (window->buffer->has_input + && (window->buffer->text_search == TEXT_SEARCH_DISABLED)) { completion_search (&(window->buffer->completion), 1, window->buffer->input_buffer, @@ -154,7 +157,8 @@ gui_action_tab_previous (t_gui_window *window, char *args) /* make C compiler happy */ (void) args; - if (window->buffer->has_input) + if (window->buffer->has_input + && (window->buffer->text_search == TEXT_SEARCH_DISABLED)) { completion_search (&(window->buffer->completion), -1, window->buffer->input_buffer, @@ -201,7 +205,7 @@ gui_action_backspace (t_gui_window *window, char *args) } /* - * gui_action_delete: delete key + * gui_action_delete: delete next char */ void @@ -685,53 +689,62 @@ gui_action_up (t_gui_window *window, char *args) } else if (window->buffer->has_input) { - if (window->buffer->ptr_history) + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) { - window->buffer->ptr_history = - window->buffer->ptr_history->next_history; - if (!window->buffer->ptr_history) + if (window->buffer->ptr_history) + { + window->buffer->ptr_history = + window->buffer->ptr_history->next_history; + if (!window->buffer->ptr_history) + window->buffer->ptr_history = + window->buffer->history; + } + else window->buffer->ptr_history = window->buffer->history; - } - else - window->buffer->ptr_history = - window->buffer->history; - if (window->buffer->ptr_history) - { - /* bash/readline like use of history */ - if (window->buffer->ptr_history->prev_history == NULL) + if (window->buffer->ptr_history) { - if (window->buffer->input_buffer_size > 0) + /* bash/readline like use of history */ + if (window->buffer->ptr_history->prev_history == NULL) { - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; - history_buffer_add (window->buffer, window->buffer->input_buffer); - history_global_add (window->buffer->input_buffer); + if (window->buffer->input_buffer_size > 0) + { + window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; + window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; + history_buffer_add (window->buffer, window->buffer->input_buffer); + history_global_add (window->buffer->input_buffer); + } } - } - else - { - if (window->buffer->input_buffer_size > 0) + else { - window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; - window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; - if (window->buffer->ptr_history->prev_history->text) - free(window->buffer->ptr_history->prev_history->text); - window->buffer->ptr_history->prev_history->text = strdup (window->buffer->input_buffer); + if (window->buffer->input_buffer_size > 0) + { + window->buffer->input_buffer[window->buffer->input_buffer_size] = '\0'; + window->buffer->input_buffer_color_mask[window->buffer->input_buffer_size] = '\0'; + if (window->buffer->ptr_history->prev_history->text) + free(window->buffer->ptr_history->prev_history->text); + window->buffer->ptr_history->prev_history->text = strdup (window->buffer->input_buffer); + } } + window->buffer->input_buffer_size = + strlen (window->buffer->ptr_history->text); + window->buffer->input_buffer_length = + utf8_strlen (window->buffer->ptr_history->text); + gui_input_optimize_size (window->buffer); + window->buffer->input_buffer_pos = + window->buffer->input_buffer_length; + window->buffer->input_buffer_1st_display = 0; + strcpy (window->buffer->input_buffer, + window->buffer->ptr_history->text); + gui_input_init_color_mask (window->buffer); + gui_input_draw (window->buffer, 0); } - window->buffer->input_buffer_size = - strlen (window->buffer->ptr_history->text); - window->buffer->input_buffer_length = - utf8_strlen (window->buffer->ptr_history->text); - gui_input_optimize_size (window->buffer); - window->buffer->input_buffer_pos = - window->buffer->input_buffer_length; - window->buffer->input_buffer_1st_display = 0; - strcpy (window->buffer->input_buffer, - window->buffer->ptr_history->text); - gui_input_init_color_mask (window->buffer); - gui_input_draw (window->buffer, 0); + } + else + { + /* search backward in buffer history */ + window->buffer->text_search = TEXT_SEARCH_BACKWARD; + (void) gui_buffer_search_text (window); } } } @@ -746,7 +759,8 @@ gui_action_up_global (t_gui_window *window, char *args) /* make C compiler happy */ (void) args; - if (window->buffer->has_input) + if (window->buffer->has_input + && (window->buffer->text_search == TEXT_SEARCH_DISABLED)) { if (history_global_ptr) { @@ -815,33 +829,42 @@ gui_action_down (t_gui_window *window, char *args) } else if (window->buffer->has_input) { - if (window->buffer->ptr_history) + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) { - window->buffer->ptr_history = - window->buffer->ptr_history->prev_history; - if (window->buffer->ptr_history) - { - window->buffer->input_buffer_size = - strlen (window->buffer->ptr_history->text); - window->buffer->input_buffer_length = - utf8_strlen (window->buffer->ptr_history->text); - } - else - { - window->buffer->input_buffer_size = 0; - window->buffer->input_buffer_length = 0; - } - gui_input_optimize_size (window->buffer); - window->buffer->input_buffer_pos = - window->buffer->input_buffer_length; - window->buffer->input_buffer_1st_display = 0; if (window->buffer->ptr_history) { - strcpy (window->buffer->input_buffer, - window->buffer->ptr_history->text); - gui_input_init_color_mask (window->buffer); + window->buffer->ptr_history = + window->buffer->ptr_history->prev_history; + if (window->buffer->ptr_history) + { + window->buffer->input_buffer_size = + strlen (window->buffer->ptr_history->text); + window->buffer->input_buffer_length = + utf8_strlen (window->buffer->ptr_history->text); + } + else + { + window->buffer->input_buffer_size = 0; + window->buffer->input_buffer_length = 0; + } + gui_input_optimize_size (window->buffer); + window->buffer->input_buffer_pos = + window->buffer->input_buffer_length; + window->buffer->input_buffer_1st_display = 0; + if (window->buffer->ptr_history) + { + strcpy (window->buffer->input_buffer, + window->buffer->ptr_history->text); + gui_input_init_color_mask (window->buffer); + } + gui_input_draw (window->buffer, 0); } - gui_input_draw (window->buffer, 0); + } + else + { + /* search forward in buffer history */ + window->buffer->text_search = TEXT_SEARCH_FORWARD; + (void) gui_buffer_search_text (window); } } } @@ -856,7 +879,8 @@ gui_action_down_global (t_gui_window *window, char *args) /* make C compiler happy */ (void) args; - if (window->buffer->has_input) + if (window->buffer->has_input + && (window->buffer->text_search == TEXT_SEARCH_DISABLED)) { if (history_global_ptr) { @@ -1053,21 +1077,24 @@ gui_action_jump_smart (t_gui_window *window, char *args) { /* make C compiler happy */ (void) args; - - if (hotlist) - { - if (!hotlist_initial_buffer) - hotlist_initial_buffer = window->buffer; - gui_window_switch_to_buffer (window, hotlist->buffer); - gui_window_redraw_buffer (window->buffer); - } - else + + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) { - if (hotlist_initial_buffer) + if (hotlist) { - gui_window_switch_to_buffer (window, hotlist_initial_buffer); + if (!hotlist_initial_buffer) + hotlist_initial_buffer = window->buffer; + gui_window_switch_to_buffer (window, hotlist->buffer); gui_window_redraw_buffer (window->buffer); - hotlist_initial_buffer = NULL; + } + else + { + if (hotlist_initial_buffer) + { + gui_window_switch_to_buffer (window, hotlist_initial_buffer); + gui_window_redraw_buffer (window->buffer); + hotlist_initial_buffer = NULL; + } } } } @@ -1081,20 +1108,23 @@ gui_action_jump_dcc (t_gui_window *window, char *args) { /* make C compiler happy */ (void) args; - - if (window->buffer->type == BUFFER_TYPE_DCC) + + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) { - if (gui_buffer_before_dcc) + if (window->buffer->type == BUFFER_TYPE_DCC) { - gui_window_switch_to_buffer (window, - gui_buffer_before_dcc); - gui_window_redraw_buffer (window->buffer); + if (gui_buffer_before_dcc) + { + gui_window_switch_to_buffer (window, + gui_buffer_before_dcc); + gui_window_redraw_buffer (window->buffer); + } + } + else + { + gui_buffer_before_dcc = window->buffer; + gui_buffer_switch_dcc (window); } - } - else - { - gui_buffer_before_dcc = window->buffer; - gui_buffer_switch_dcc (window); } } @@ -1107,20 +1137,23 @@ gui_action_jump_raw_data (t_gui_window *window, char *args) { /* make C compiler happy */ (void) args; - - if (window->buffer->type == BUFFER_TYPE_RAW_DATA) + + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) { - if (gui_buffer_before_raw_data) + if (window->buffer->type == BUFFER_TYPE_RAW_DATA) { - gui_window_switch_to_buffer (window, - gui_buffer_before_raw_data); - gui_window_redraw_buffer (window->buffer); + if (gui_buffer_before_raw_data) + { + gui_window_switch_to_buffer (window, + gui_buffer_before_raw_data); + gui_window_redraw_buffer (window->buffer); + } + } + else + { + gui_buffer_before_raw_data = window->buffer; + gui_buffer_switch_raw_data (window); } - } - else - { - gui_buffer_before_raw_data = window->buffer; - gui_buffer_switch_raw_data (window); } } @@ -1133,9 +1166,12 @@ gui_action_jump_last_buffer (t_gui_window *window, char *args) { /* make C compiler happy */ (void) args; - - if (last_gui_buffer) - gui_buffer_switch_by_number (window, last_gui_buffer->number); + + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) + { + if (last_gui_buffer) + gui_buffer_switch_by_number (window, last_gui_buffer->number); + } } /* @@ -1148,14 +1184,17 @@ gui_action_jump_server (t_gui_window *window, char *args) /* make C compiler happy */ (void) args; - if (SERVER(window->buffer)) + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) { - if (SERVER(window->buffer)->buffer != - window->buffer) + if (SERVER(window->buffer)) { - gui_window_switch_to_buffer (window, - SERVER(window->buffer)->buffer); - gui_window_redraw_buffer (window->buffer); + if (SERVER(window->buffer)->buffer != + window->buffer) + { + gui_window_switch_to_buffer (window, + SERVER(window->buffer)->buffer); + gui_window_redraw_buffer (window->buffer); + } } } } @@ -1173,34 +1212,37 @@ gui_action_jump_next_server (t_gui_window *window, char *args) /* make C compiler happy */ (void) args; - if (SERVER(window->buffer)) + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) { - ptr_server = SERVER(window->buffer)->next_server; - if (!ptr_server) - ptr_server = irc_servers; - while (ptr_server != SERVER(window->buffer)) + if (SERVER(window->buffer)) { - if (ptr_server->buffer) - break; - ptr_server = (ptr_server->next_server) ? - ptr_server->next_server : irc_servers; - } - if (ptr_server != SERVER(window->buffer)) - { - /* save current buffer */ - SERVER(window->buffer)->saved_buffer = window->buffer; - - /* come back to memorized chan if found */ - if (ptr_server->saved_buffer) - ptr_buffer = ptr_server->saved_buffer; - else - ptr_buffer = (ptr_server->channels) ? - ptr_server->channels->buffer : ptr_server->buffer; - if ((ptr_server->buffer == ptr_buffer) - && (ptr_buffer->all_servers)) - ptr_buffer->server = ptr_server; - gui_window_switch_to_buffer (window, ptr_buffer); - gui_window_redraw_buffer (window->buffer); + ptr_server = SERVER(window->buffer)->next_server; + if (!ptr_server) + ptr_server = irc_servers; + while (ptr_server != SERVER(window->buffer)) + { + if (ptr_server->buffer) + break; + ptr_server = (ptr_server->next_server) ? + ptr_server->next_server : irc_servers; + } + if (ptr_server != SERVER(window->buffer)) + { + /* save current buffer */ + SERVER(window->buffer)->saved_buffer = window->buffer; + + /* come back to memorized chan if found */ + if (ptr_server->saved_buffer) + ptr_buffer = ptr_server->saved_buffer; + else + ptr_buffer = (ptr_server->channels) ? + ptr_server->channels->buffer : ptr_server->buffer; + if ((ptr_server->buffer == ptr_buffer) + && (ptr_buffer->all_servers)) + ptr_buffer->server = ptr_server; + gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_redraw_buffer (window->buffer); + } } } } @@ -1231,12 +1273,13 @@ gui_action_scroll_previous_highlight (t_gui_window *window, char *args) /* make C compiler happy */ (void) args; - if (window->buffer->type == BUFFER_TYPE_STANDARD) + if ((window->buffer->type == BUFFER_TYPE_STANDARD) + && (window->buffer->text_search == TEXT_SEARCH_DISABLED)) { if (window->buffer->lines) { ptr_line = (window->start_line) ? - window->start_line->prev_line : window->buffer->last_line->prev_line; + window->start_line->prev_line : window->buffer->last_line; while (ptr_line) { if (ptr_line->line_with_highlight) @@ -1267,7 +1310,8 @@ gui_action_scroll_next_highlight (t_gui_window *window, char *args) /* make C compiler happy */ (void) args; - if (window->buffer->type == BUFFER_TYPE_STANDARD) + if ((window->buffer->type == BUFFER_TYPE_STANDARD) + && (window->buffer->text_search == TEXT_SEARCH_DISABLED)) { if (window->buffer->lines) { @@ -1300,19 +1344,22 @@ gui_action_scroll_unread (t_gui_window *window, char *args) { /* make C compiler happy */ (void) args; - - if (cfg_look_read_marker && - cfg_look_read_marker[0] && - (window->buffer->type == BUFFER_TYPE_STANDARD) && - window->buffer->last_read_line && - window->buffer->last_read_line != window->buffer->last_line) + + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) { - window->start_line = window->buffer->last_read_line->next_line; - window->start_line_pos = 0; - window->first_line_displayed = - (window->start_line == window->buffer->lines); - gui_chat_draw (window->buffer, 1); - gui_status_draw (window->buffer, 0); + if (cfg_look_read_marker && + cfg_look_read_marker[0] && + (window->buffer->type == BUFFER_TYPE_STANDARD) && + window->buffer->last_read_line && + window->buffer->last_read_line != window->buffer->last_line) + { + window->start_line = window->buffer->last_read_line->next_line; + window->start_line_pos = 0; + window->first_line_displayed = + (window->start_line == window->buffer->lines); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 0); + } } } @@ -1389,3 +1436,23 @@ gui_action_insert_string (t_gui_window *window, char *args) gui_input_draw (window->buffer, 0); } } + +/* + * gui_action_search_text: search text in buffer history + */ + +void +gui_action_search_text (t_gui_window *window, char *args) +{ + /* make C compiler happy */ + (void) args; + + if (window->buffer->type == BUFFER_TYPE_STANDARD) + { + /* toggle search */ + if (window->buffer->text_search == TEXT_SEARCH_DISABLED) + gui_buffer_search_start (window); + else + gui_buffer_search_stop (window); + } +} diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 423a70f3a..631287a19 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -207,6 +207,10 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type, new_buffer->ptr_history = NULL; new_buffer->num_history = 0; + /* text search */ + new_buffer->text_search = TEXT_SEARCH_DISABLED; + new_buffer->text_search_input = NULL; + /* add buffer to buffers queue */ new_buffer->prev_buffer = last_gui_buffer; if (gui_buffers) @@ -550,6 +554,9 @@ gui_buffer_free (t_gui_buffer *buffer, int switch_to_another) history_buffer_free (buffer); + if (buffer->text_search_input) + free (buffer->text_search_input); + /* remove buffer from buffers list */ if (buffer->prev_buffer) buffer->prev_buffer->next_buffer = buffer->next_buffer; @@ -631,6 +638,31 @@ gui_buffer_line_new (t_gui_buffer *buffer, time_t date) } /* + * gui_buffer_line_search: search for text in a line + */ + +int +gui_buffer_line_search (t_gui_line *line, char *text, int case_sensitive) +{ + char *data; + int rc; + + if (!text) + return 0; + + rc = 0; + data = (char *)gui_color_decode ((unsigned char *)line->data, 0); + if (data) + { + if ((case_sensitive && (strstr (data, text))) + || (!case_sensitive && (strcasestr (data, text)))) + rc = 1; + free (data); + } + return rc; +} + +/* * gui_buffer_merge_servers: merge server buffers in one buffer */ @@ -946,6 +978,107 @@ gui_buffer_move_to_number (t_gui_buffer *buffer, int number) } /* + * gui_buffer_search_start: start search in a buffer + */ + +void +gui_buffer_search_start (t_gui_window *window) +{ + window->buffer->text_search = TEXT_SEARCH_BACKWARD; + if (window->buffer->text_search_input) + { + free (window->buffer->text_search_input); + window->buffer->text_search_input = NULL; + } + if (window->buffer->input_buffer && window->buffer->input_buffer[0]) + window->buffer->text_search_input = + strdup (window->buffer->input_buffer); + gui_action_delete_line (window, NULL); + gui_status_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); +} + +/* + * gui_buffer_search_stop: stop search in a buffer + */ + +void +gui_buffer_search_stop (t_gui_window *window) +{ + window->buffer->text_search = TEXT_SEARCH_DISABLED; + gui_action_delete_line (window, NULL); + if (window->buffer->text_search_input) + { + gui_insert_string_input (window, window->buffer->text_search_input, -1); + free (window->buffer->text_search_input); + window->buffer->text_search_input = NULL; + } + window->start_line = NULL; + window->start_line_pos = 0; + gui_chat_draw (window->buffer, 0); + gui_status_draw (window->buffer, 1); + gui_input_draw (window->buffer, 1); +} + +/* + * gui_buffer_search_text: search text in a buffer + */ + +int +gui_buffer_search_text (t_gui_window *window) +{ + t_gui_line *ptr_line; + + if (window->buffer->text_search == TEXT_SEARCH_BACKWARD) + { + if (window->buffer->lines + && window->buffer->input_buffer && window->buffer->input_buffer[0]) + { + ptr_line = (window->start_line) ? + window->start_line->prev_line : window->buffer->last_line; + while (ptr_line) + { + if (gui_buffer_line_search (ptr_line, window->buffer->input_buffer, 0)) + { + window->start_line = ptr_line; + window->start_line_pos = 0; + window->first_line_displayed = + (window->start_line == window->buffer->lines); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 1); + return 1; + } + ptr_line = ptr_line->prev_line; + } + } + } + else if (window->buffer->text_search == TEXT_SEARCH_FORWARD) + { + if (window->buffer->lines + && window->buffer->input_buffer && window->buffer->input_buffer[0]) + { + ptr_line = (window->start_line) ? + window->start_line->next_line : window->buffer->lines->next_line; + while (ptr_line) + { + if (gui_buffer_line_search (ptr_line, window->buffer->input_buffer, 0)) + { + window->start_line = ptr_line; + window->start_line_pos = 0; + window->first_line_displayed = + (window->start_line == window->buffer->lines); + gui_chat_draw (window->buffer, 1); + gui_status_draw (window->buffer, 1); + return 1; + } + ptr_line = ptr_line->next_line; + } + } + } + return 0; +} + +/* * gui_buffer_print_log: print buffer infos in log (usually for crash dump) */ @@ -982,6 +1115,9 @@ gui_buffer_print_log (t_gui_buffer *buffer) weechat_log_printf (" history. . . . . . . . : 0x%X\n", buffer->history); weechat_log_printf (" last_history . . . . . : 0x%X\n", buffer->last_history); weechat_log_printf (" ptr_history. . . . . . : 0x%X\n", buffer->ptr_history); + weechat_log_printf (" num_history. . . . . . : %d\n", buffer->num_history); + weechat_log_printf (" text_search. . . . . . : %d\n", buffer->text_search); + weechat_log_printf (" text_search_input. . . : '%s'\n", buffer->text_search_input); weechat_log_printf (" prev_buffer. . . . . . : 0x%X\n", buffer->prev_buffer); weechat_log_printf (" next_buffer. . . . . . : 0x%X\n", buffer->next_buffer); weechat_log_printf ("\n"); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 75e364898..679e6c92c 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -51,6 +51,10 @@ #define NOTIFY_LEVEL_MAX 3 #define NOTIFY_LEVEL_DEFAULT NOTIFY_LEVEL_MAX +#define TEXT_SEARCH_DISABLED 0 +#define TEXT_SEARCH_BACKWARD 1 +#define TEXT_SEARCH_FORWARD 2 + /* buffer structures */ typedef struct t_gui_line t_gui_line; @@ -122,6 +126,10 @@ struct t_gui_buffer t_history *ptr_history; /* current command in history */ int num_history; /* number of commands in history */ + /* text search */ + int text_search; /* text search type */ + char *text_search_input; /* input saved before text search */ + /* link to previous/next buffer */ t_gui_buffer *prev_buffer; /* link to previous buffer */ t_gui_buffer *next_buffer; /* link to next buffer */ diff --git a/src/gui/gui-keyboard.c b/src/gui/gui-keyboard.c index db6f238ac..bf617011c 100644 --- a/src/gui/gui-keyboard.c +++ b/src/gui/gui-keyboard.c @@ -145,6 +145,8 @@ t_gui_key_function gui_key_functions[] = N_("grab a key") }, { "insert", gui_action_insert_string, N_("insert a string in command line") }, + { "search_text", gui_action_search_text, + N_("search text in buffer history") }, { NULL, NULL, NULL } }; @@ -580,11 +582,14 @@ gui_keyboard_pressed (char *key_str) else (void)(ptr_key->function)(gui_current_window, ptr_key->args); #ifdef PLUGINS - (void) plugin_keyboard_handler_exec ( - (ptr_key->command) ? - ptr_key->command : gui_keyboard_function_search_by_ptr (ptr_key->function), - buffer_before_key, - gui_current_window->buffer->input_buffer); + if (gui_current_window->buffer->text_search == TEXT_SEARCH_DISABLED) + { + (void) plugin_keyboard_handler_exec ( + (ptr_key->command) ? + ptr_key->command : gui_keyboard_function_search_by_ptr (ptr_key->function), + buffer_before_key, + gui_current_window->buffer->input_buffer); + } #endif if (buffer_before_key) free (buffer_before_key); diff --git a/src/gui/gui.h b/src/gui/gui.h index dacc950bd..3b24a1bb0 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -90,6 +90,7 @@ extern void gui_buffer_clear (t_gui_buffer *); extern void gui_buffer_clear_all (); extern void gui_buffer_free (t_gui_buffer *, int); extern t_gui_line *gui_buffer_line_new (t_gui_buffer *, time_t); +extern int gui_buffer_line_search (t_gui_line *, char *, int); extern void gui_buffer_merge_servers (t_gui_window *); extern void gui_buffer_split_server (t_gui_window *); extern void gui_buffer_switch_previous (t_gui_window *); @@ -98,6 +99,9 @@ extern void gui_buffer_switch_dcc (t_gui_window *); extern void gui_buffer_switch_raw_data (t_gui_window *); extern t_gui_buffer *gui_buffer_switch_by_number (t_gui_window *, int); extern void gui_buffer_move_to_number (t_gui_buffer *, int); +extern void gui_buffer_search_start (t_gui_window *); +extern void gui_buffer_search_stop (t_gui_window *); +extern int gui_buffer_search_text (t_gui_window *); extern void gui_buffer_print_log (t_gui_buffer *); /* panel */ @@ -157,6 +161,7 @@ extern void gui_action_infobar_clear (t_gui_window *, char *); extern void gui_action_refresh_screen (t_gui_window *, char *); extern void gui_action_grab_key (t_gui_window *, char *); extern void gui_action_insert_string (t_gui_window *, char *); +extern void gui_action_search_text (t_gui_window *, char *); /* key */ extern void gui_keyboard_init (); |