diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2004-07-01 20:43:57 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2004-07-01 20:43:57 +0000 |
commit | 062e5ea1aed8e37c717b15283adcba0e1a62c9b1 (patch) | |
tree | 32746e312f5b5816c9e89798df9c438416491a2b /src/gui/curses/gui-input.c | |
parent | 66ff97166f17621d962f1254b09757af26ebc2c7 (diff) | |
download | weechat-062e5ea1aed8e37c717b15283adcba0e1a62c9b1.zip |
Window management
Diffstat (limited to 'src/gui/curses/gui-input.c')
-rw-r--r-- | src/gui/curses/gui-input.c | 315 |
1 files changed, 161 insertions, 154 deletions
diff --git a/src/gui/curses/gui-input.c b/src/gui/curses/gui-input.c index be601dfa8..3e98619a1 100644 --- a/src/gui/curses/gui-input.c +++ b/src/gui/curses/gui-input.c @@ -49,7 +49,7 @@ void gui_read_keyb () { int key, i; - t_gui_view *ptr_view; + t_gui_buffer *ptr_buffer; char new_char[2]; key = getch (); @@ -59,16 +59,20 @@ gui_read_keyb () { /* resize event */ case KEY_RESIZE: - gui_calculate_pos_size (gui_current_view); - gui_redraw_view (gui_current_view); + gui_calculate_pos_size (gui_current_window); + gui_redraw_buffer (gui_current_window->buffer); break; - /* previous view */ + /* previous buffer in window */ case KEY_F(6): - gui_switch_to_previous_view (); + gui_switch_to_previous_buffer (gui_current_window); break; - /* next view */ + /* next buffer in window */ case KEY_F(7): - gui_switch_to_next_view (); + gui_switch_to_next_buffer (gui_current_window); + break; + /* next window */ + case KEY_F(8): + gui_switch_to_next_window (gui_current_window); break; /* remove last infobar message */ case KEY_F(10): @@ -76,205 +80,208 @@ gui_read_keyb () break; /* cursor up */ case KEY_UP: - if (gui_current_view->ptr_history) + if (gui_current_window->buffer->ptr_history) { - gui_current_view->ptr_history = - gui_current_view->ptr_history->next_history; - if (!gui_current_view->ptr_history) - gui_current_view->ptr_history = - gui_current_view->history; + gui_current_window->buffer->ptr_history = + gui_current_window->buffer->ptr_history->next_history; + if (!gui_current_window->buffer->ptr_history) + gui_current_window->buffer->ptr_history = + gui_current_window->buffer->history; } else - gui_current_view->ptr_history = - gui_current_view->history; - if (gui_current_view->ptr_history) + gui_current_window->buffer->ptr_history = + gui_current_window->buffer->history; + if (gui_current_window->buffer->ptr_history) { - gui_current_view->input_buffer_size = - strlen (gui_current_view->ptr_history->text); - gui_optimize_input_buffer_size (gui_current_view); - gui_current_view->input_buffer_pos = - gui_current_view->input_buffer_size; - strcpy (gui_current_view->input_buffer, - gui_current_view->ptr_history->text); - gui_draw_view_input (gui_current_view); + gui_current_window->buffer->input_buffer_size = + strlen (gui_current_window->buffer->ptr_history->text); + gui_optimize_input_buffer_size (gui_current_window->buffer); + gui_current_window->buffer->input_buffer_pos = + gui_current_window->buffer->input_buffer_size; + strcpy (gui_current_window->buffer->input_buffer, + gui_current_window->buffer->ptr_history->text); + gui_draw_buffer_input (gui_current_window->buffer, 0); } break; /* cursor down */ case KEY_DOWN: - if (gui_current_view->ptr_history) + if (gui_current_window->buffer->ptr_history) { - gui_current_view->ptr_history = - gui_current_view->ptr_history->prev_history; - if (gui_current_view->ptr_history) - gui_current_view->input_buffer_size = - strlen (gui_current_view->ptr_history->text); + gui_current_window->buffer->ptr_history = + gui_current_window->buffer->ptr_history->prev_history; + if (gui_current_window->buffer->ptr_history) + gui_current_window->buffer->input_buffer_size = + strlen (gui_current_window->buffer->ptr_history->text); else - gui_current_view->input_buffer_size = 0; - gui_optimize_input_buffer_size (gui_current_view); - gui_current_view->input_buffer_pos = - gui_current_view->input_buffer_size; - if (gui_current_view->ptr_history) - strcpy (gui_current_view->input_buffer, - gui_current_view->ptr_history->text); - gui_draw_view_input (gui_current_view); + gui_current_window->buffer->input_buffer_size = 0; + gui_optimize_input_buffer_size (gui_current_window->buffer); + gui_current_window->buffer->input_buffer_pos = + gui_current_window->buffer->input_buffer_size; + if (gui_current_window->buffer->ptr_history) + strcpy (gui_current_window->buffer->input_buffer, + gui_current_window->buffer->ptr_history->text); + gui_draw_buffer_input (gui_current_window->buffer, 0); } break; /* cursor left */ case KEY_LEFT: - if (gui_current_view->input_buffer_pos > 0) + if (gui_current_window->buffer->input_buffer_pos > 0) { - gui_current_view->input_buffer_pos--; - gui_draw_view_input (gui_current_view); + gui_current_window->buffer->input_buffer_pos--; + gui_draw_buffer_input (gui_current_window->buffer, 0); } break; /* cursor right */ case KEY_RIGHT: - if (gui_current_view->input_buffer_pos < - gui_current_view->input_buffer_size) + if (gui_current_window->buffer->input_buffer_pos < + gui_current_window->buffer->input_buffer_size) { - gui_current_view->input_buffer_pos++; - gui_draw_view_input (gui_current_view); + gui_current_window->buffer->input_buffer_pos++; + gui_draw_buffer_input (gui_current_window->buffer, 0); } break; /* home key */ case KEY_HOME: - if (gui_current_view->input_buffer_pos > 0) + if (gui_current_window->buffer->input_buffer_pos > 0) { - gui_current_view->input_buffer_pos = 0; - gui_draw_view_input (gui_current_view); + gui_current_window->buffer->input_buffer_pos = 0; + gui_draw_buffer_input (gui_current_window->buffer, 0); } break; /* end key */ case KEY_END: - if (gui_current_view->input_buffer_pos < - gui_current_view->input_buffer_size) + if (gui_current_window->buffer->input_buffer_pos < + gui_current_window->buffer->input_buffer_size) { - gui_current_view->input_buffer_pos = - gui_current_view->input_buffer_size; - gui_draw_view_input (gui_current_view); + gui_current_window->buffer->input_buffer_pos = + gui_current_window->buffer->input_buffer_size; + gui_draw_buffer_input (gui_current_window->buffer, 0); } break; /* page up */ case KEY_PPAGE: - gui_move_page_up (); + gui_move_page_up (gui_current_window); break; /* page down */ case KEY_NPAGE: - gui_move_page_down (); + gui_move_page_down (gui_current_window); break; /* erase before cursor and move cursor to the left */ case 127: case KEY_BACKSPACE: - if (gui_current_view->input_buffer_pos > 0) + if (gui_current_window->buffer->input_buffer_pos > 0) { - i = gui_current_view->input_buffer_pos-1; - while (gui_current_view->input_buffer[i]) + i = gui_current_window->buffer->input_buffer_pos-1; + while (gui_current_window->buffer->input_buffer[i]) { - gui_current_view->input_buffer[i] = - gui_current_view->input_buffer[i+1]; + gui_current_window->buffer->input_buffer[i] = + gui_current_window->buffer->input_buffer[i+1]; i++; } - gui_current_view->input_buffer_size--; - gui_current_view->input_buffer_pos--; - gui_current_view->input_buffer[gui_current_view->input_buffer_size] = '\0'; - gui_draw_view_input (gui_current_view); - gui_optimize_input_buffer_size (gui_current_view); - gui_current_view->completion.position = -1; + gui_current_window->buffer->input_buffer_size--; + gui_current_window->buffer->input_buffer_pos--; + gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; + gui_draw_buffer_input (gui_current_window->buffer, 0); + gui_optimize_input_buffer_size (gui_current_window->buffer); + gui_current_window->buffer->completion.position = -1; } break; /* Control + Backspace */ case 0x08: - gui_delete_previous_word (); + gui_delete_previous_word (gui_current_window->buffer); break; /* erase char under cursor */ case KEY_DC: - if (gui_current_view->input_buffer_pos < - gui_current_view->input_buffer_size) + if (gui_current_window->buffer->input_buffer_pos < + gui_current_window->buffer->input_buffer_size) { - i = gui_current_view->input_buffer_pos; - while (gui_current_view->input_buffer[i]) + i = gui_current_window->buffer->input_buffer_pos; + while (gui_current_window->buffer->input_buffer[i]) { - gui_current_view->input_buffer[i] = - gui_current_view->input_buffer[i+1]; + gui_current_window->buffer->input_buffer[i] = + gui_current_window->buffer->input_buffer[i+1]; i++; } - gui_current_view->input_buffer_size--; - gui_current_view->input_buffer[gui_current_view->input_buffer_size] = '\0'; - gui_draw_view_input (gui_current_view); - gui_optimize_input_buffer_size (gui_current_view); - gui_current_view->completion.position = -1; + gui_current_window->buffer->input_buffer_size--; + gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; + gui_draw_buffer_input (gui_current_window->buffer, 0); + gui_optimize_input_buffer_size (gui_current_window->buffer); + gui_current_window->buffer->completion.position = -1; } break; /* Tab : completion */ case '\t': - completion_search (&(gui_current_view->completion), - CHANNEL(gui_current_view), - gui_current_view->input_buffer, - gui_current_view->input_buffer_size, - gui_current_view->input_buffer_pos); - if (gui_current_view->completion.word_found) + completion_search (&(gui_current_window->buffer->completion), + CHANNEL(gui_current_window->buffer), + gui_current_window->buffer->input_buffer, + gui_current_window->buffer->input_buffer_size, + gui_current_window->buffer->input_buffer_pos); + if (gui_current_window->buffer->completion.word_found) { // replace word with new completed word into input buffer - gui_current_view->input_buffer_size += - gui_current_view->completion.diff_size; - gui_optimize_input_buffer_size (gui_current_view); - gui_current_view->input_buffer[gui_current_view->input_buffer_size] = '\0'; + gui_current_window->buffer->input_buffer_size += + gui_current_window->buffer->completion.diff_size; + gui_optimize_input_buffer_size (gui_current_window->buffer); + gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; - if (gui_current_view->completion.diff_size > 0) + if (gui_current_window->buffer->completion.diff_size > 0) { - for (i = gui_current_view->input_buffer_size - 1; - i >= gui_current_view->completion.position_replace + - (int)strlen (gui_current_view->completion.word_found); i--) - gui_current_view->input_buffer[i] = - gui_current_view->input_buffer[i - - gui_current_view->completion.diff_size]; + for (i = gui_current_window->buffer->input_buffer_size - 1; + i >= gui_current_window->buffer->completion.position_replace + + (int)strlen (gui_current_window->buffer->completion.word_found); i--) + gui_current_window->buffer->input_buffer[i] = + gui_current_window->buffer->input_buffer[i - + gui_current_window->buffer->completion.diff_size]; } else { - for (i = gui_current_view->completion.position_replace + - strlen (gui_current_view->completion.word_found); - i < gui_current_view->input_buffer_size; i++) - gui_current_view->input_buffer[i] = - gui_current_view->input_buffer[i - - gui_current_view->completion.diff_size]; + for (i = gui_current_window->buffer->completion.position_replace + + strlen (gui_current_window->buffer->completion.word_found); + i < gui_current_window->buffer->input_buffer_size; i++) + gui_current_window->buffer->input_buffer[i] = + gui_current_window->buffer->input_buffer[i - + gui_current_window->buffer->completion.diff_size]; } - strncpy (gui_current_view->input_buffer + gui_current_view->completion.position_replace, - gui_current_view->completion.word_found, - strlen (gui_current_view->completion.word_found)); - gui_current_view->input_buffer_pos = - gui_current_view->completion.position_replace + - strlen (gui_current_view->completion.word_found); - gui_current_view->completion.position = - gui_current_view->input_buffer_pos; + strncpy (gui_current_window->buffer->input_buffer + gui_current_window->buffer->completion.position_replace, + gui_current_window->buffer->completion.word_found, + strlen (gui_current_window->buffer->completion.word_found)); + gui_current_window->buffer->input_buffer_pos = + gui_current_window->buffer->completion.position_replace + + strlen (gui_current_window->buffer->completion.word_found); + gui_current_window->buffer->completion.position = + gui_current_window->buffer->input_buffer_pos; /* add space or completor to the end of completion, if needed */ - if (gui_current_view->completion.base_word[0] == '/') + if (gui_current_window->buffer->completion.base_word[0] == '/') { - if (gui_current_view->input_buffer[gui_current_view->input_buffer_pos] != ' ') - gui_buffer_insert_string (" ", - gui_current_view->input_buffer_pos); - gui_current_view->completion.position++; - gui_current_view->input_buffer_pos++; + if (gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_pos] != ' ') + gui_buffer_insert_string (gui_current_window->buffer, + " ", + gui_current_window->buffer->input_buffer_pos); + gui_current_window->buffer->completion.position++; + gui_current_window->buffer->input_buffer_pos++; } else { - if (gui_current_view->completion.base_word_pos == 0) + if (gui_current_window->buffer->completion.base_word_pos == 0) { - if (strncmp (gui_current_view->input_buffer + gui_current_view->input_buffer_pos, + if (strncmp (gui_current_window->buffer->input_buffer + gui_current_window->buffer->input_buffer_pos, cfg_look_completor, strlen (cfg_look_completor)) != 0) - gui_buffer_insert_string (cfg_look_completor, - gui_current_view->input_buffer_pos); - gui_current_view->completion.position += strlen (cfg_look_completor); - gui_current_view->input_buffer_pos += strlen (cfg_look_completor); - if (gui_current_view->input_buffer[gui_current_view->input_buffer_pos] != ' ') - gui_buffer_insert_string (" ", - gui_current_view->input_buffer_pos); - gui_current_view->completion.position++; - gui_current_view->input_buffer_pos++; + gui_buffer_insert_string (gui_current_window->buffer, + cfg_look_completor, + gui_current_window->buffer->input_buffer_pos); + gui_current_window->buffer->completion.position += strlen (cfg_look_completor); + gui_current_window->buffer->input_buffer_pos += strlen (cfg_look_completor); + if (gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_pos] != ' ') + gui_buffer_insert_string (gui_current_window->buffer, + " ", + gui_current_window->buffer->input_buffer_pos); + gui_current_window->buffer->completion.position++; + gui_current_window->buffer->input_buffer_pos++; } } - gui_draw_view_input (gui_current_view); + gui_draw_buffer_input (gui_current_window->buffer, 0); } break; /* escape code (for control-key) */ @@ -284,10 +291,10 @@ gui_read_keyb () switch (key) { case KEY_LEFT: - gui_switch_to_previous_view (); + gui_switch_to_previous_buffer (gui_current_window); break; case KEY_RIGHT: - gui_switch_to_next_view (); + gui_switch_to_next_buffer (gui_current_window); break; case 79: /* TODO: replace 79 by constant name! */ @@ -299,11 +306,11 @@ gui_read_keyb () { /* Control + Right */ case 99: - gui_move_next_word (); + gui_move_next_word (gui_current_window->buffer); break; /* Control + Left */ case 100: - gui_move_previous_word (); + gui_move_previous_word (gui_current_window->buffer); break; } } @@ -314,35 +321,36 @@ gui_read_keyb () break; /* send command/message */ case '\n': - if (gui_current_view->input_buffer_size > 0) + if (gui_current_window->buffer->input_buffer_size > 0) { - gui_current_view->input_buffer[gui_current_view->input_buffer_size] = '\0'; - history_add (gui_current_view, gui_current_view->input_buffer); - gui_current_view->input_buffer_size = 0; - gui_current_view->input_buffer_pos = 0; - gui_current_view->input_buffer_1st_display = 0; - gui_current_view->completion.position = -1; - gui_current_view->ptr_history = NULL; - ptr_view = gui_current_view; - user_command (SERVER(gui_current_view), - gui_current_view->input_buffer); - if (ptr_view == gui_current_view) - gui_draw_view_input (ptr_view); - if (ptr_view) - ptr_view->input_buffer[0] = '\0'; + gui_current_window->buffer->input_buffer[gui_current_window->buffer->input_buffer_size] = '\0'; + history_add (gui_current_window->buffer, gui_current_window->buffer->input_buffer); + gui_current_window->buffer->input_buffer_size = 0; + gui_current_window->buffer->input_buffer_pos = 0; + gui_current_window->buffer->input_buffer_1st_display = 0; + gui_current_window->buffer->completion.position = -1; + gui_current_window->buffer->ptr_history = NULL; + ptr_buffer = gui_current_window->buffer; + user_command (SERVER(gui_current_window->buffer), + gui_current_window->buffer->input_buffer); + if (ptr_buffer == gui_current_window->buffer) + gui_draw_buffer_input (ptr_buffer, 0); + if (ptr_buffer) + ptr_buffer->input_buffer[0] = '\0'; } break; /* other key => add to input buffer */ default: - /*gui_printf (gui_current_view, + /*gui_printf (gui_current_buffer, "[Debug] key pressed = %d, as octal: %o\n", key, key);*/ new_char[0] = key; new_char[1] = '\0'; - gui_buffer_insert_string (new_char, - gui_current_view->input_buffer_pos); - gui_current_view->input_buffer_pos++; - gui_draw_view_input (gui_current_view); - gui_current_view->completion.position = -1; + gui_buffer_insert_string (gui_current_window->buffer, + new_char, + gui_current_window->buffer->input_buffer_pos); + gui_current_window->buffer->input_buffer_pos++; + gui_draw_buffer_input (gui_current_window->buffer, 0); + gui_current_window->buffer->completion.position = -1; break; } } @@ -374,14 +382,13 @@ gui_main_loop () if (local_time->tm_min != old_min) { old_min = local_time->tm_min; - gui_redraw_view_infobar (gui_current_view); + gui_draw_buffer_infobar (gui_current_window->buffer, 1); } /* second has changed ? => count down time for infobar, if needed */ if (local_time->tm_sec != old_sec) { old_sec = local_time->tm_sec; - /* TODO: manage splited windows! */ if (gui_infobar && gui_infobar->remaining_time > 0) { gui_infobar->remaining_time--; |