summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2007-03-20 10:18:25 +0000
committerSebastien Helleu <flashcode@flashtux.org>2007-03-20 10:18:25 +0000
commit7f0e0b5eeacf93c11fc0db3e5fa211c80920298c (patch)
tree0b3d2db24cec6f0da65c018ed37acf0e1c9419ce /src/gui
parent25bfda26e952947b31c5307362459bc547162c48 (diff)
downloadweechat-7f0e0b5eeacf93c11fc0db3e5fa211c80920298c.zip
Added case-sensitive search in buffer, display marker for each line matching search
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/curses/gui-curses-chat.c30
-rw-r--r--src/gui/curses/gui-curses-input.c10
-rw-r--r--src/gui/curses/gui-curses-keyboard.c11
-rw-r--r--src/gui/gui-action.c6
-rw-r--r--src/gui/gui-buffer.c118
-rw-r--r--src/gui/gui-buffer.h1
-rw-r--r--src/gui/gui.h1
7 files changed, 110 insertions, 67 deletions
diff --git a/src/gui/curses/gui-curses-chat.c b/src/gui/curses/gui-curses-chat.c
index 4cc32ed0c..f0821cea1 100644
--- a/src/gui/curses/gui-curses-chat.c
+++ b/src/gui/curses/gui-curses-chat.c
@@ -812,14 +812,30 @@ gui_chat_display_line (t_gui_window *window, t_gui_line *line, int count,
}
else
{
- /* display read marker if needed */
- if (cfg_look_read_marker && cfg_look_read_marker[0] &&
- window->buffer->last_read_line &&
- (window->buffer->last_read_line == line->prev_line))
+ if (cfg_look_read_marker && cfg_look_read_marker[0])
{
- gui_chat_set_weechat_color (window, COLOR_WIN_CHAT_READ_MARKER);
- mvwprintw (GUI_CURSES(window)->win_chat, read_marker_y, read_marker_x,
- "%c", cfg_look_read_marker[0]);
+ /* display marker if line is matching user search */
+ if (window->buffer->text_search != TEXT_SEARCH_DISABLED)
+ {
+ if (gui_buffer_line_search (line, window->buffer->input_buffer,
+ window->buffer->text_search_exact))
+ {
+ gui_chat_set_weechat_color (window, COLOR_WIN_CHAT_READ_MARKER);
+ mvwprintw (GUI_CURSES(window)->win_chat, read_marker_y, read_marker_x,
+ "%c", cfg_look_read_marker[0]);
+ }
+ }
+ else
+ {
+ /* display read marker if needed */
+ if (window->buffer->last_read_line &&
+ (window->buffer->last_read_line == line->prev_line))
+ {
+ gui_chat_set_weechat_color (window, COLOR_WIN_CHAT_READ_MARKER);
+ mvwprintw (GUI_CURSES(window)->win_chat, read_marker_y, read_marker_x,
+ "%c", cfg_look_read_marker[0]);
+ }
+ }
}
}
diff --git a/src/gui/curses/gui-curses-input.c b/src/gui/curses/gui-curses-input.c
index fb715cf47..2c10a0d14 100644
--- a/src/gui/curses/gui-curses-input.c
+++ b/src/gui/curses/gui-curses-input.c
@@ -79,7 +79,12 @@ gui_input_get_prompt_length (t_gui_window *window, char *nick)
int char_size, length;
if (window->buffer->text_search != TEXT_SEARCH_DISABLED)
- return utf8_width_screen (_("Text search: "));
+ {
+ if (window->buffer->text_search_exact)
+ return utf8_width_screen (_("Text search (exact): "));
+ else
+ return utf8_width_screen (_("Text search: "));
+ }
length = 0;
pos = cfg_look_input_format;
@@ -161,7 +166,8 @@ gui_input_draw_prompt (t_gui_window *window, char *nick)
gui_window_set_weechat_color (GUI_CURSES(window)->win_input,
COLOR_WIN_INPUT);
wprintw (GUI_CURSES(window)->win_input, "%s",
- _("Text search: "));
+ (window->buffer->text_search_exact) ?
+ _("Text search (exact): ") : _("Text search: "));
return;
}
diff --git a/src/gui/curses/gui-curses-keyboard.c b/src/gui/curses/gui-curses-keyboard.c
index 94e1ec84b..4d2ac79ae 100644
--- a/src/gui/curses/gui-curses-keyboard.c
+++ b/src/gui/curses/gui-curses-keyboard.c
@@ -304,16 +304,7 @@ gui_keyboard_read ()
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);
- }
- }
+ gui_buffer_search_restart (gui_current_window);
if (input_old)
free (input_old);
diff --git a/src/gui/gui-action.c b/src/gui/gui-action.c
index 1b24b54eb..49aba7900 100644
--- a/src/gui/gui-action.c
+++ b/src/gui/gui-action.c
@@ -1453,6 +1453,10 @@ gui_action_search_text (t_gui_window *window, char *args)
if (window->buffer->text_search == TEXT_SEARCH_DISABLED)
gui_buffer_search_start (window);
else
- gui_buffer_search_stop (window);
+ {
+ window->buffer->text_search_exact ^= 1;
+ gui_buffer_search_restart (window);
+ gui_input_draw (window->buffer, 1);
+ }
}
}
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 631287a19..5970e3a3b 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -209,6 +209,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int type,
/* text search */
new_buffer->text_search = TEXT_SEARCH_DISABLED;
+ new_buffer->text_search_exact = 0;
new_buffer->text_search_input = NULL;
/* add buffer to buffers queue */
@@ -647,7 +648,7 @@ gui_buffer_line_search (t_gui_line *line, char *text, int case_sensitive)
char *data;
int rc;
- if (!text)
+ if (!text || !text[0])
return 0;
rc = 0;
@@ -655,7 +656,7 @@ gui_buffer_line_search (t_gui_line *line, char *text, int case_sensitive)
if (data)
{
if ((case_sensitive && (strstr (data, text)))
- || (!case_sensitive && (strcasestr (data, text))))
+ || (!case_sensitive && (ascii_strcasestr (data, text))))
rc = 1;
free (data);
}
@@ -978,49 +979,6 @@ 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
*/
@@ -1038,7 +996,8 @@ gui_buffer_search_text (t_gui_window *window)
window->start_line->prev_line : window->buffer->last_line;
while (ptr_line)
{
- if (gui_buffer_line_search (ptr_line, window->buffer->input_buffer, 0))
+ if (gui_buffer_line_search (ptr_line, window->buffer->input_buffer,
+ window->buffer->text_search_exact))
{
window->start_line = ptr_line;
window->start_line_pos = 0;
@@ -1061,7 +1020,8 @@ gui_buffer_search_text (t_gui_window *window)
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))
+ if (gui_buffer_line_search (ptr_line, window->buffer->input_buffer,
+ window->buffer->text_search_exact))
{
window->start_line = ptr_line;
window->start_line_pos = 0;
@@ -1079,6 +1039,69 @@ gui_buffer_search_text (t_gui_window *window)
}
/*
+ * 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;
+ window->buffer->text_search_exact = 0;
+ 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_restart: restart search (after input changes or exact
+ * flag (un)set)
+ */
+
+void
+gui_buffer_search_restart (t_gui_window *window)
+{
+ window->start_line = NULL;
+ window->start_line_pos = 0;
+ window->buffer->text_search = TEXT_SEARCH_BACKWARD;
+ if (!gui_buffer_search_text (window))
+ {
+ gui_chat_draw (window->buffer, 1);
+ gui_status_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;
+ window->buffer->text_search = 0;
+ 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_print_log: print buffer infos in log (usually for crash dump)
*/
@@ -1117,6 +1140,7 @@ gui_buffer_print_log (t_gui_buffer *buffer)
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_exact. . . : %d\n", buffer->text_search_exact);
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);
diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h
index 679e6c92c..cd0a1cb26 100644
--- a/src/gui/gui-buffer.h
+++ b/src/gui/gui-buffer.h
@@ -128,6 +128,7 @@ struct t_gui_buffer
/* text search */
int text_search; /* text search type */
+ int text_search_exact; /* exact search (case sensitive) ? */
char *text_search_input; /* input saved before text search */
/* link to previous/next buffer */
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 3b24a1bb0..f9a0c74c4 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -100,6 +100,7 @@ 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_restart (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 *);