From f02ba717a03c2dee7528c4a6e54b827bdd4f8169 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sun, 4 Jul 2004 15:39:49 +0000 Subject: Added /buffer command, jump to buffer by number (alt-digit), actions now ok in private buffers --- src/gui/curses/gui-display.c | 45 ++++++++++++++++++++++++------------------- src/gui/curses/gui-input.c | 14 ++++++++++++++ src/gui/gui-common.c | 46 ++++++++++++++++++++++++++++++++++---------- src/gui/gui.h | 12 +++++++----- 4 files changed, 82 insertions(+), 35 deletions(-) (limited to 'src/gui') diff --git a/src/gui/curses/gui-display.c b/src/gui/curses/gui-display.c index 5decef5d0..f331637d4 100644 --- a/src/gui/curses/gui-display.c +++ b/src/gui/curses/gui-display.c @@ -482,8 +482,8 @@ gui_display_line (t_gui_window *window, t_gui_line *line, int stop_at_end) /* insert spaces for align text under time/nick */ if ((window->win_chat_cursor_x == 0) && - (ptr_message->type != MSG_TYPE_TIME) && - (ptr_message->type != MSG_TYPE_NICK) && + (!(ptr_message->type & MSG_TYPE_TIME)) && + (!(ptr_message->type & MSG_TYPE_NICK)) && (line->length_align > 0) && /* TODO: modify arbitraty value for non aligning messages on time/nick? */ (line->length_align < (window->win_chat_width - 5))) @@ -805,12 +805,17 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase) wrefresh (ptr_win->win_status); } wmove (ptr_win->win_status, 0, 0); + + /* display number of buffers */ + gui_window_set_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "[%d] ", + (last_gui_buffer) ? last_gui_buffer->number : 0); + + /* display current server */ if (SERVER(ptr_win->buffer) && SERVER(ptr_win->buffer)->name) - { - gui_window_set_color (ptr_win->win_status, - COLOR_WIN_STATUS); wprintw (ptr_win->win_status, "[%s] ", SERVER(ptr_win->buffer)->name); - } + if (SERVER(ptr_win->buffer) && !CHANNEL(ptr_win->buffer)) { gui_window_set_color (ptr_win->win_status, @@ -870,7 +875,7 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase) if (hotlist) { gui_window_set_color (ptr_win->win_status, COLOR_WIN_STATUS); - wprintw (ptr_win->win_status, _("Act: ")); + wprintw (ptr_win->win_status, _("[Act: ")); for (ptr_hotlist = hotlist; ptr_hotlist; ptr_hotlist = ptr_hotlist->next_hotlist) { @@ -896,6 +901,9 @@ gui_draw_buffer_status (t_gui_buffer *buffer, int erase) if (ptr_hotlist->next_hotlist) wprintw (ptr_win->win_status, ","); } + gui_window_set_color (ptr_win->win_status, + COLOR_WIN_STATUS); + wprintw (ptr_win->win_status, "]"); } /* display "-MORE-" if last line is not displayed */ @@ -1215,7 +1223,6 @@ gui_switch_to_buffer (t_gui_window *window, t_gui_buffer *buffer) window->win_status = newwin (1, window->win_width, window->win_y + window->win_height - 2, window->win_x); buffer->num_displayed++; - buffer->unread_data = 0; hotlist_remove_buffer (buffer); } @@ -1301,8 +1308,6 @@ gui_move_page_down (t_gui_window *window) window->sub_lines -= window->win_chat_height - 1; if (window->sub_lines < 0) window->sub_lines = 0; - if (window->sub_lines == 0) - window->buffer->unread_data = 0; gui_draw_buffer_chat (window->buffer, 0); gui_draw_buffer_status (window->buffer, 0); } @@ -1344,7 +1349,7 @@ gui_curses_resize_handler () } /* - * gui_view_init_subviews: init subviews for a WeeChat view + * gui_window_init_subviews: init subviews for a WeeChat window */ void @@ -1661,9 +1666,11 @@ gui_add_message (t_gui_buffer *buffer, int type, int color, char *message) buffer->last_line->last_message->message = strdup (message); length = strlen (message); buffer->last_line->length += length; - if (type == MSG_TYPE_MSG) + if (type & MSG_TYPE_MSG) buffer->last_line->line_with_message = 1; - if ((type == MSG_TYPE_TIME) || (type == MSG_TYPE_NICK)) + if (type & MSG_TYPE_HIGHLIGHT) + buffer->last_line->line_with_highlight = 1; + if ((type & MSG_TYPE_TIME) || (type & MSG_TYPE_NICK)) buffer->last_line->length_align += length; if (pos) { @@ -1677,14 +1684,12 @@ gui_add_message (t_gui_buffer *buffer, int type, int color, char *message) /*else gui_display_line (buffer, buffer->last_line, 1);*/ } - if ((buffer->num_displayed == 0) || (gui_current_window->sub_lines > 0)) + if (buffer->num_displayed == 0) { - if (buffer->unread_data < 1 + buffer->last_line->line_with_message) - { - buffer->unread_data = 1 + buffer->last_line->line_with_message; - hotlist_add (buffer->last_line->line_with_message, buffer); - gui_draw_buffer_status (buffer, 1); - } + hotlist_add (buffer->last_line->line_with_message + + buffer->last_line->line_with_highlight, + buffer); + gui_draw_buffer_status (gui_current_window->buffer, 1); } } } diff --git a/src/gui/curses/gui-input.c b/src/gui/curses/gui-input.c index 179d962d7..e56bbd038 100644 --- a/src/gui/curses/gui-input.c +++ b/src/gui/curses/gui-input.c @@ -299,6 +299,8 @@ gui_read_keyb () case KEY_ESCAPE: if ((key = getch()) != ERR) { + /*gui_printf (gui_current_window->buffer, + "[Debug] key pressed = %d, as octal: %o\n", key, key);*/ switch (key) { case KEY_LEFT: @@ -327,6 +329,18 @@ gui_read_keyb () } } break; + /* Alt-number */ + case 49: /* Alt-1 */ + case 50: /* Alt-2 */ + case 51: /* Alt-3 */ + case 52: /* Alt-4 */ + case 53: /* Alt-5 */ + case 54: /* Alt-6 */ + case 55: /* Alt-7 */ + case 56: /* Alt-8 */ + case 57: /* Alt-9 */ + gui_switch_to_buffer_by_number (gui_current_window, key - 48); + break; /* Alt-A */ case 'a': case 'A': diff --git a/src/gui/gui-common.c b/src/gui/gui-common.c index 864096918..445eca13d 100644 --- a/src/gui/gui-common.c +++ b/src/gui/gui-common.c @@ -145,7 +145,7 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int switch_to if ((new_buffer = (t_gui_buffer *)(malloc (sizeof (t_gui_buffer))))) { new_buffer->num_displayed = 0; - new_buffer->number = (gui_buffers) ? last_gui_buffer->number + 1 : 1; + new_buffer->number = (last_gui_buffer) ? last_gui_buffer->number + 1 : 1; /* assign server and channel to buffer */ SERVER(new_buffer) = server; @@ -157,21 +157,19 @@ gui_buffer_new (t_gui_window *window, void *server, void *channel, int switch_to CHANNEL(new_buffer)->buffer = new_buffer; if (!window->buffer) + { window->buffer = new_buffer; - window->first_line_displayed = 1; - window->sub_lines = 0; - - gui_calculate_pos_size (window); - - /* init buffers */ - gui_window_init_subwindows (window); + window->first_line_displayed = 1; + window->sub_lines = 0; + gui_calculate_pos_size (window); + gui_window_init_subwindows (window); + } /* init lines */ new_buffer->lines = NULL; new_buffer->last_line = NULL; new_buffer->num_lines = 0; new_buffer->line_complete = 1; - new_buffer->unread_data = 0; /* init input buffer */ new_buffer->input_buffer_alloc = INPUT_BUFFER_BLOCK_SIZE; @@ -242,7 +240,6 @@ gui_buffer_clear (t_gui_buffer *buffer) buffer->last_line = NULL; buffer->num_lines = 0; buffer->line_complete = 1; - buffer->unread_data = 0; for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { @@ -407,6 +404,7 @@ gui_new_line (t_gui_buffer *buffer) new_line->length = 0; new_line->length_align = 0; new_line->line_with_message = 0; + new_line->line_with_highlight = 0; new_line->messages = NULL; new_line->last_message = NULL; if (!buffer->lines) @@ -624,3 +622,31 @@ gui_buffer_insert_string (t_gui_buffer *buffer, char *string, int pos) /* insert new string */ strncpy (buffer->input_buffer + pos, string, length); } + +/* + * gui_switch_to_buffer_by_number: switch to another buffer with number + */ + +t_gui_buffer * +gui_switch_to_buffer_by_number (t_gui_window *window, int number) +{ + t_gui_buffer *ptr_buffer; + + /* buffer is currently displayed ? */ + if (number == window->buffer->number) + return window->buffer; + + /* search for buffer in the list */ + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) + { + if ((ptr_buffer != window->buffer) && (number == ptr_buffer->number)) + { + gui_switch_to_buffer (window, ptr_buffer); + gui_redraw_buffer (window->buffer); + return ptr_buffer; + } + } + + /* buffer not found */ + return NULL; +} diff --git a/src/gui/gui.h b/src/gui/gui.h index 1066d478d..a2b6a726b 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -66,10 +66,11 @@ #define BUFFER_IS_CHANNEL(buffer) (CHANNEL(buffer) && (CHANNEL(buffer)->type == CHAT_CHANNEL)) #define BUFFER_IS_PRIVATE(buffer) (CHANNEL(buffer) && (CHANNEL(buffer)->type == CHAT_PRIVATE)) -#define MSG_TYPE_TIME 0 -#define MSG_TYPE_NICK 1 -#define MSG_TYPE_INFO 2 -#define MSG_TYPE_MSG 3 +#define MSG_TYPE_TIME 1 +#define MSG_TYPE_NICK 2 +#define MSG_TYPE_INFO 4 +#define MSG_TYPE_MSG 8 +#define MSG_TYPE_HIGHLIGHT 16 #define gui_printf_color(buffer, color, fmt, argz...) \ gui_printf_color_type(buffer, MSG_TYPE_INFO, color, fmt, ##argz) @@ -95,6 +96,7 @@ struct t_gui_line int length; /* length of the line (in char) */ int length_align; /* alignment length (time or time/nick) */ int line_with_message; /* line contains a message from a user? */ + int line_with_highlight; /* line contains highlight */ t_gui_message *messages; /* messages for the line */ t_gui_message *last_message; /* last message of the line */ t_gui_line *prev_line; /* link to previous line */ @@ -138,7 +140,6 @@ struct t_gui_buffer t_gui_line *last_line; /* last line of chat window */ int num_lines; /* number of lines in the window */ int line_complete; /* current line complete ? (\n ending) */ - int unread_data; /* highlight windows with unread data */ /* inupt buffer */ char *input_buffer; /* input buffer */ @@ -235,6 +236,7 @@ extern void gui_delete_previous_word (t_gui_buffer *); extern void gui_move_previous_word (t_gui_buffer *); extern void gui_move_next_word (t_gui_buffer *); extern void gui_buffer_insert_string (t_gui_buffer *, char *, int); +extern t_gui_buffer *gui_switch_to_buffer_by_number (t_gui_window *, int); /* GUI dependant functions */ extern int gui_assign_color (int *, char *); extern int gui_get_color_by_name (char *); -- cgit v1.2.3