1 /*
2 * inputwin.c
3 * vim: expandtab:ts=4:sts=4:sw=4
4 *
5 * Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
6 *
7 * This file is part of Profanity.
8 *
9 * Profanity is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * Profanity is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Profanity. If not, see <https://www.gnu.org/licenses/>.
21 *
22 * In addition, as a special exception, the copyright holders give permission to
23 * link the code of portions of this program with the OpenSSL library under
24 * certain conditions as described in each individual source file, and
25 * distribute linked combinations including the two.
26 *
27 * You must obey the GNU General Public License in all respects for all of the
28 * code used other than OpenSSL. If you modify file(s) with this exception, you
29 * may extend this exception to your version of the file(s), but you are not
30 * obligated to do so. If you do not wish to do so, delete this exception
31 * statement from your version. If you delete this exception statement from all
32 * source files in the program, then also delete it here.
33 *
34 */
35
36 #define _XOPEN_SOURCE_EXTENDED
37 #include "config.h"
38
39 #include <stdio.h>
40 #include <sys/select.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <wchar.h>
44 #include <sys/time.h>
45 #include <errno.h>
46 #include <pthread.h>
47
48 #include <readline/readline.h>
49 #include <readline/history.h>
50
51 #ifdef HAVE_NCURSESW_NCURSES_H
52 #include <ncursesw/ncurses.h>
53 #elif HAVE_NCURSES_H
54 #include <ncurses.h>
55 #elif HAVE_CURSES_H
56 #include <curses.h>
57 #endif
58
59 #include "profanity.h"
60 #include "log.h"
61 #include "common.h"
62 #include "command/cmd_ac.h"
63 #include "config/files.h"
64 #include "config/accounts.h"
65 #include "config/preferences.h"
66 #include "config/theme.h"
67 #include "ui/ui.h"
68 #include "ui/screen.h"
69 #include "ui/statusbar.h"
70 #include "ui/inputwin.h"
71 #include "ui/window.h"
72 #include "ui/window_list.h"
73 #include "xmpp/xmpp.h"
74 #include "xmpp/muc.h"
75 #include "xmpp/roster_list.h"
76 #include "xmpp/chat_state.h"
77
78 static WINDOW* inp_win;
79 static int pad_start = 0;
80
81 static struct timeval p_rl_timeout;
82 /* Timeout in ms. Shows how long select() may block. */
83 static gint inp_timeout = 0;
84 static gint no_input_count = 0;
85
86 static FILE* discard;
87 static fd_set fds;
88 static int r;
89 static char* inp_line = NULL;
90 static gboolean get_password = FALSE;
91
92 static void _inp_win_update_virtual(void);
93 static int _inp_edited(const wint_t ch);
94 static void _inp_win_handle_scroll(void);
95 static int _inp_offset_to_col(char* str, int offset);
96 static void _inp_write(char* line, int offset);
97
98 static void _inp_rl_addfuncs(void);
99 static int _inp_rl_getc(FILE* stream);
100 static void _inp_rl_linehandler(char* line);
101 static int _inp_rl_tab_handler(int count, int key);
102 static int _inp_rl_shift_tab_handler(int count, int key);
103 static int _inp_rl_win_clear_handler(int count, int key);
104 static int _inp_rl_win_close_handler(int count, int key);
105 static int _inp_rl_win_1_handler(int count, int key);
106 static int _inp_rl_win_2_handler(int count, int key);
107 static int _inp_rl_win_3_handler(int count, int key);
108 static int _inp_rl_win_4_handler(int count, int key);
109 static int _inp_rl_win_5_handler(int count, int key);
110 static int _inp_rl_win_6_handler(int count, int key);
111 static int _inp_rl_win_7_handler(int count, int key);
112 static int _inp_rl_win_8_handler(int count, int key);
113 static int _inp_rl_win_9_handler(int count, int key);
114 static int _inp_rl_win_0_handler(int count, int key);
115 static int _inp_rl_win_11_handler(int count, int key);
116 static int _inp_rl_win_12_handler(int count, int key);
117 static int _inp_rl_win_13_handler(int count, int key);
118 static int _inp_rl_win_14_handler(int count, int key);
119 static int _inp_rl_win_15_handler(int count, int key);
120 static int _inp_rl_win_16_handler(int count, int key);
121 static int _inp_rl_win_17_handler(int count, int key);
122 static int _inp_rl_win_18_handler(int count, int key);
123 static int _inp_rl_win_19_handler(int count, int key);
124 static int _inp_rl_win_20_handler(int count, int key);
125 static int _inp_rl_win_prev_handler(int count, int key);
126 static int _inp_rl_win_next_handler(int count, int key);
127 static int _inp_rl_win_next_unread_handler(int count, int key);
128 static int _inp_rl_win_attention_handler(int count, int key);
129 static int _inp_rl_win_attention_next_handler(int count, int key);
130 static int _inp_rl_win_pageup_handler(int count, int key);
131 static int _inp_rl_win_pagedown_handler(int count, int key);
132 static int _inp_rl_subwin_pageup_handler(int count, int key);
133 static int _inp_rl_subwin_pagedown_handler(int count, int key);
134 static int _inp_rl_startup_hook(void);
135 static int _inp_rl_down_arrow_handler(int count, int key);
136
137 void
create_input_window(void)138 create_input_window(void)
139 {
140 #ifdef NCURSES_REENTRANT
141 set_escdelay(25);
142 #else
143 ESCDELAY = 25;
144 #endif
145 discard = fopen("/dev/null", "a");
146 rl_outstream = discard;
147 rl_readline_name = "profanity";
148 _inp_rl_addfuncs();
149 rl_getc_function = _inp_rl_getc;
150 rl_startup_hook = _inp_rl_startup_hook;
151 rl_callback_handler_install(NULL, _inp_rl_linehandler);
152
153 inp_win = newpad(1, INP_WIN_MAX);
154 wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));
155 ;
156 keypad(inp_win, TRUE);
157 wmove(inp_win, 0, 0);
158
159 _inp_win_update_virtual();
160 }
161
162 char*
inp_readline(void)163 inp_readline(void)
164 {
165 free(inp_line);
166 inp_line = NULL;
167 p_rl_timeout.tv_sec = inp_timeout / 1000;
168 p_rl_timeout.tv_usec = inp_timeout % 1000 * 1000;
169 FD_ZERO(&fds);
170 FD_SET(fileno(rl_instream), &fds);
171 errno = 0;
172 pthread_mutex_unlock(&lock);
173 r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout);
174 pthread_mutex_lock(&lock);
175 if (r < 0) {
176 if (errno != EINTR) {
177 const char* err_msg = strerror(errno);
178 log_error("Readline failed: %s", err_msg);
179 }
180 return NULL;
181 }
182
183 if (FD_ISSET(fileno(rl_instream), &fds)) {
184 rl_callback_read_char();
185
186 if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') {
187 chat_state_activity();
188 }
189
190 ui_reset_idle_time();
191 if (!get_password) {
192 _inp_write(rl_line_buffer, rl_point);
193 }
194 inp_nonblocking(TRUE);
195 } else {
196 inp_nonblocking(FALSE);
197 chat_state_idle();
198 }
199
200 if (inp_line) {
201 if (!get_password && prefs_get_boolean(PREF_SLASH_GUARD)) {
202 if (strlen(inp_line) > 1) {
203 char* res = (char*)memchr(inp_line + 1, '/', 3);
204 if (res) {
205 cons_show("Your text contains a slash in the first 4 characters");
206 return NULL;
207 }
208 }
209 }
210 return strdup(inp_line);
211 } else {
212 return NULL;
213 }
214 }
215
216 void
inp_win_resize(void)217 inp_win_resize(void)
218 {
219 int col = getcurx(inp_win);
220 int wcols = getmaxx(stdscr);
221
222 // if lost cursor off screen, move contents to show it
223 if (col >= pad_start + wcols) {
224 pad_start = col - (wcols / 2);
225 if (pad_start < 0) {
226 pad_start = 0;
227 }
228 }
229
230 wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));
231 ;
232 _inp_win_update_virtual();
233 }
234
235 void
inp_nonblocking(gboolean reset)236 inp_nonblocking(gboolean reset)
237 {
238 if (!prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) {
239 inp_timeout = prefs_get_inpblock();
240 return;
241 }
242
243 if (reset) {
244 inp_timeout = 0;
245 no_input_count = 0;
246 }
247
248 if (inp_timeout < prefs_get_inpblock()) {
249 no_input_count++;
250
251 if (no_input_count % 10 == 0) {
252 inp_timeout += no_input_count;
253
254 if (inp_timeout > prefs_get_inpblock()) {
255 inp_timeout = prefs_get_inpblock();
256 }
257 }
258 }
259 }
260
261 void
inp_close(void)262 inp_close(void)
263 {
264 rl_callback_handler_remove();
265 fclose(discard);
266 }
267
268 char*
inp_get_line(void)269 inp_get_line(void)
270 {
271 werase(inp_win);
272 wmove(inp_win, 0, 0);
273 _inp_win_update_virtual();
274 doupdate();
275 char* line = NULL;
276 while (!line) {
277 line = inp_readline();
278 ui_update();
279 }
280 status_bar_clear_prompt();
281 return line;
282 }
283
284 char*
inp_get_password(void)285 inp_get_password(void)
286 {
287 werase(inp_win);
288 wmove(inp_win, 0, 0);
289 _inp_win_update_virtual();
290 doupdate();
291 char* password = NULL;
292 get_password = TRUE;
293 while (!password) {
294 password = inp_readline();
295 ui_update();
296 }
297 get_password = FALSE;
298 status_bar_clear_prompt();
299 return password;
300 }
301
302 void
inp_put_back(void)303 inp_put_back(void)
304 {
305 _inp_win_update_virtual();
306 }
307
308 static void
_inp_win_update_virtual(void)309 _inp_win_update_virtual(void)
310 {
311 int wcols = getmaxx(stdscr);
312 int row = screen_inputwin_row();
313 if (inp_win != NULL) {
314 pnoutrefresh(inp_win, 0, pad_start, row, 0, row, wcols - 1);
315 }
316 }
317
318 static void
_inp_write(char * line,int offset)319 _inp_write(char* line, int offset)
320 {
321 int col = _inp_offset_to_col(line, offset);
322 werase(inp_win);
323 waddstr(inp_win, line);
324 wmove(inp_win, 0, col);
325 _inp_win_handle_scroll();
326
327 _inp_win_update_virtual();
328 doupdate();
329 }
330
331 static int
_inp_edited(const wint_t ch)332 _inp_edited(const wint_t ch)
333 {
334 // Use own state to be thread-safe with possible pthreads. C standard
335 // guarantees that initial value of the state will be zeroed buffer.
336 static mbstate_t mbstate;
337
338 // backspace
339 if (ch == 127) {
340 return 1;
341 }
342
343 // ctrl-w
344 if (ch == 23) {
345 return 1;
346 }
347
348 // enter
349 if (ch == 13) {
350 return 1;
351 }
352
353 // printable
354 char bytes[MB_CUR_MAX + 1];
355 size_t utf_len = wcrtomb(bytes, ch, &mbstate);
356 if (utf_len == (size_t)-1) {
357 return 0;
358 }
359 bytes[utf_len] = '\0';
360 gunichar unichar = g_utf8_get_char(bytes);
361
362 return g_unichar_isprint(unichar);
363 }
364
365 static int
_inp_offset_to_col(char * str,int offset)366 _inp_offset_to_col(char* str, int offset)
367 {
368 int i = 0;
369 int col = 0;
370
371 while (i < offset && str[i] != '\0') {
372 gunichar uni = g_utf8_get_char(&str[i]);
373 size_t ch_len = mbrlen(&str[i], MB_CUR_MAX, NULL);
374 i += ch_len;
375 col++;
376 if (g_unichar_iswide(uni)) {
377 col++;
378 }
379 }
380
381 return col;
382 }
383
384 static void
_inp_win_handle_scroll(void)385 _inp_win_handle_scroll(void)
386 {
387 int col = getcurx(inp_win);
388 int wcols = getmaxx(stdscr);
389
390 if (col == 0) {
391 pad_start = 0;
392 } else if (col >= pad_start + (wcols - 1)) {
393 pad_start = col - (wcols / 2);
394 if (pad_start < 0) {
395 pad_start = 0;
396 }
397 } else if (col <= pad_start) {
398 pad_start = pad_start - (wcols / 2);
399 if (pad_start < 0) {
400 pad_start = 0;
401 }
402 }
403 }
404
405 static void
_inp_rl_addfuncs(void)406 _inp_rl_addfuncs(void)
407 {
408 rl_add_funmap_entry("prof_win_1", _inp_rl_win_1_handler);
409 rl_add_funmap_entry("prof_win_2", _inp_rl_win_2_handler);
410 rl_add_funmap_entry("prof_win_3", _inp_rl_win_3_handler);
411 rl_add_funmap_entry("prof_win_4", _inp_rl_win_4_handler);
412 rl_add_funmap_entry("prof_win_5", _inp_rl_win_5_handler);
413 rl_add_funmap_entry("prof_win_6", _inp_rl_win_6_handler);
414 rl_add_funmap_entry("prof_win_7", _inp_rl_win_7_handler);
415 rl_add_funmap_entry("prof_win_8", _inp_rl_win_8_handler);
416 rl_add_funmap_entry("prof_win_9", _inp_rl_win_9_handler);
417 rl_add_funmap_entry("prof_win_0", _inp_rl_win_0_handler);
418 rl_add_funmap_entry("prof_win_11", _inp_rl_win_11_handler);
419 rl_add_funmap_entry("prof_win_12", _inp_rl_win_12_handler);
420 rl_add_funmap_entry("prof_win_13", _inp_rl_win_13_handler);
421 rl_add_funmap_entry("prof_win_14", _inp_rl_win_14_handler);
422 rl_add_funmap_entry("prof_win_15", _inp_rl_win_15_handler);
423 rl_add_funmap_entry("prof_win_16", _inp_rl_win_16_handler);
424 rl_add_funmap_entry("prof_win_17", _inp_rl_win_17_handler);
425 rl_add_funmap_entry("prof_win_18", _inp_rl_win_18_handler);
426 rl_add_funmap_entry("prof_win_19", _inp_rl_win_19_handler);
427 rl_add_funmap_entry("prof_win_20", _inp_rl_win_20_handler);
428 rl_add_funmap_entry("prof_win_prev", _inp_rl_win_prev_handler);
429 rl_add_funmap_entry("prof_win_next", _inp_rl_win_next_handler);
430 rl_add_funmap_entry("prof_win_next_unread", _inp_rl_win_next_unread_handler);
431 rl_add_funmap_entry("prof_win_pageup", _inp_rl_win_pageup_handler);
432 rl_add_funmap_entry("prof_win_pagedown", _inp_rl_win_pagedown_handler);
433 rl_add_funmap_entry("prof_subwin_pageup", _inp_rl_subwin_pageup_handler);
434 rl_add_funmap_entry("prof_subwin_pagedown", _inp_rl_subwin_pagedown_handler);
435 rl_add_funmap_entry("prof_win_clear", _inp_rl_win_clear_handler);
436 rl_add_funmap_entry("prof_win_close", _inp_rl_win_close_handler);
437 }
438
439 // Readline callbacks
440
441 static int
_inp_rl_startup_hook(void)442 _inp_rl_startup_hook(void)
443 {
444 rl_bind_keyseq("\\e1", _inp_rl_win_1_handler);
445 rl_bind_keyseq("\\e2", _inp_rl_win_2_handler);
446 rl_bind_keyseq("\\e3", _inp_rl_win_3_handler);
447 rl_bind_keyseq("\\e4", _inp_rl_win_4_handler);
448 rl_bind_keyseq("\\e5", _inp_rl_win_5_handler);
449 rl_bind_keyseq("\\e6", _inp_rl_win_6_handler);
450 rl_bind_keyseq("\\e7", _inp_rl_win_7_handler);
451 rl_bind_keyseq("\\e8", _inp_rl_win_8_handler);
452 rl_bind_keyseq("\\e9", _inp_rl_win_9_handler);
453 rl_bind_keyseq("\\e0", _inp_rl_win_0_handler);
454 rl_bind_keyseq("\\eq", _inp_rl_win_11_handler);
455 rl_bind_keyseq("\\ew", _inp_rl_win_12_handler);
456 rl_bind_keyseq("\\ee", _inp_rl_win_13_handler);
457 rl_bind_keyseq("\\er", _inp_rl_win_14_handler);
458 rl_bind_keyseq("\\et", _inp_rl_win_15_handler);
459 rl_bind_keyseq("\\ey", _inp_rl_win_16_handler);
460 rl_bind_keyseq("\\eu", _inp_rl_win_17_handler);
461 rl_bind_keyseq("\\ei", _inp_rl_win_18_handler);
462 rl_bind_keyseq("\\eo", _inp_rl_win_19_handler);
463 rl_bind_keyseq("\\ep", _inp_rl_win_20_handler);
464
465 rl_bind_keyseq("\\eOP", _inp_rl_win_1_handler);
466 rl_bind_keyseq("\\eOQ", _inp_rl_win_2_handler);
467 rl_bind_keyseq("\\eOR", _inp_rl_win_3_handler);
468 rl_bind_keyseq("\\eOS", _inp_rl_win_4_handler);
469 rl_bind_keyseq("\\e[15~", _inp_rl_win_5_handler);
470 rl_bind_keyseq("\\e[17~", _inp_rl_win_6_handler);
471 rl_bind_keyseq("\\e[18~", _inp_rl_win_7_handler);
472 rl_bind_keyseq("\\e[19~", _inp_rl_win_8_handler);
473 rl_bind_keyseq("\\e[20~", _inp_rl_win_9_handler);
474 rl_bind_keyseq("\\e[21~", _inp_rl_win_0_handler);
475
476 rl_bind_keyseq("\\e[1;9D", _inp_rl_win_prev_handler);
477 rl_bind_keyseq("\\e[1;3D", _inp_rl_win_prev_handler);
478 rl_bind_keyseq("\\e\\e[D", _inp_rl_win_prev_handler);
479
480 rl_bind_keyseq("\\e[1;9C", _inp_rl_win_next_handler);
481 rl_bind_keyseq("\\e[1;3C", _inp_rl_win_next_handler);
482 rl_bind_keyseq("\\e\\e[C", _inp_rl_win_next_handler);
483
484 rl_bind_keyseq("\\ea", _inp_rl_win_next_unread_handler);
485 rl_bind_keyseq("\\ev", _inp_rl_win_attention_handler);
486 rl_bind_keyseq("\\em", _inp_rl_win_attention_next_handler);
487
488 rl_bind_keyseq("\\e\\e[5~", _inp_rl_subwin_pageup_handler);
489 rl_bind_keyseq("\\e[5;3~", _inp_rl_subwin_pageup_handler);
490 rl_bind_keyseq("\\e\\eOy", _inp_rl_subwin_pageup_handler);
491
492 rl_bind_keyseq("\\e\\e[6~", _inp_rl_subwin_pagedown_handler);
493 rl_bind_keyseq("\\e[6;3~", _inp_rl_subwin_pagedown_handler);
494 rl_bind_keyseq("\\e\\eOs", _inp_rl_subwin_pagedown_handler);
495
496 rl_bind_keyseq("\\e[5~", _inp_rl_win_pageup_handler);
497 rl_bind_keyseq("\\eOy", _inp_rl_win_pageup_handler);
498 rl_bind_keyseq("\\e[6~", _inp_rl_win_pagedown_handler);
499 rl_bind_keyseq("\\eOs", _inp_rl_win_pagedown_handler);
500
501 rl_bind_key('\t', _inp_rl_tab_handler);
502 rl_bind_keyseq("\\e[Z", _inp_rl_shift_tab_handler);
503
504 rl_bind_keyseq("\\e[1;5B", _inp_rl_down_arrow_handler); // ctrl+arrow down
505
506 // unbind unwanted mappings
507 rl_bind_keyseq("\\e=", NULL);
508
509 // disable readline completion
510 rl_variable_bind("disable-completion", "on");
511
512 // check for and load ~/.config/profanity/inputrc
513 gchar* inputrc = files_get_inputrc_file();
514 if (inputrc) {
515 rl_read_init_file(inputrc);
516 g_free(inputrc);
517 }
518
519 return 0;
520 }
521
522 static void
_inp_rl_linehandler(char * line)523 _inp_rl_linehandler(char* line)
524 {
525 if (line && *line) {
526 if (!get_password) {
527 add_history(line);
528 }
529 }
530 inp_line = line;
531 }
532
533 static gboolean shift_tab = FALSE;
534
535 static int
_inp_rl_getc(FILE * stream)536 _inp_rl_getc(FILE* stream)
537 {
538 int ch = rl_getc(stream);
539
540 // 27, 91, 90 = Shift tab
541 if (ch == 27) {
542 shift_tab = TRUE;
543 return ch;
544 }
545 if (shift_tab && ch == 91) {
546 return ch;
547 }
548 if (shift_tab && ch == 90) {
549 return ch;
550 }
551
552 shift_tab = FALSE;
553
554 if (_inp_edited(ch)) {
555 ProfWin* window = wins_get_current();
556 cmd_ac_reset(window);
557 }
558 return ch;
559 }
560
561 static int
_inp_rl_win_clear_handler(int count,int key)562 _inp_rl_win_clear_handler(int count, int key)
563 {
564 ProfWin* win = wins_get_current();
565 win_clear(win);
566 return 0;
567 }
568
569 static int
_inp_rl_win_close_handler(int count,int key)570 _inp_rl_win_close_handler(int count, int key)
571 {
572 ProfWin* win = wins_get_current();
573 gchar* args = 0;
574 cmd_close(win, 0, &args);
575 return 0;
576 }
577
578 static int
_inp_rl_tab_handler(int count,int key)579 _inp_rl_tab_handler(int count, int key)
580 {
581 if (rl_point != rl_end || !rl_line_buffer) {
582 return 0;
583 }
584
585 ProfWin* current = wins_get_current();
586 if ((strncmp(rl_line_buffer, "/", 1) != 0) && (current->type == WIN_MUC)) {
587 char* result = muc_autocomplete(current, rl_line_buffer, FALSE);
588 if (result) {
589 rl_replace_line(result, 1);
590 rl_point = rl_end;
591 free(result);
592 }
593 } else if (strncmp(rl_line_buffer, "/", 1) == 0) {
594 ProfWin* window = wins_get_current();
595 char* result = cmd_ac_complete(window, rl_line_buffer, FALSE);
596 if (result) {
597 rl_replace_line(result, 1);
598 rl_point = rl_end;
599 free(result);
600 }
601 }
602
603 return 0;
604 }
605
606 static int
_inp_rl_shift_tab_handler(int count,int key)607 _inp_rl_shift_tab_handler(int count, int key)
608 {
609 if (rl_point != rl_end || !rl_line_buffer) {
610 return 0;
611 }
612
613 ProfWin* current = wins_get_current();
614 if ((strncmp(rl_line_buffer, "/", 1) != 0) && (current->type == WIN_MUC)) {
615 char* result = muc_autocomplete(current, rl_line_buffer, TRUE);
616 if (result) {
617 rl_replace_line(result, 1);
618 rl_point = rl_end;
619 free(result);
620 }
621 } else if (strncmp(rl_line_buffer, "/", 1) == 0) {
622 ProfWin* window = wins_get_current();
623 char* result = cmd_ac_complete(window, rl_line_buffer, TRUE);
624 if (result) {
625 rl_replace_line(result, 1);
626 rl_point = rl_end;
627 free(result);
628 }
629 }
630
631 return 0;
632 }
633
634 static void
_go_to_win(int i)635 _go_to_win(int i)
636 {
637 ProfWin* window = wins_get_by_num(i);
638 if (window) {
639 ui_focus_win(window);
640 }
641 }
642
643 static int
_inp_rl_win_1_handler(int count,int key)644 _inp_rl_win_1_handler(int count, int key)
645 {
646 _go_to_win(1);
647 return 0;
648 }
649
650 static int
_inp_rl_win_2_handler(int count,int key)651 _inp_rl_win_2_handler(int count, int key)
652 {
653 _go_to_win(2);
654 return 0;
655 }
656
657 static int
_inp_rl_win_3_handler(int count,int key)658 _inp_rl_win_3_handler(int count, int key)
659 {
660 _go_to_win(3);
661 return 0;
662 }
663
664 static int
_inp_rl_win_4_handler(int count,int key)665 _inp_rl_win_4_handler(int count, int key)
666 {
667 _go_to_win(4);
668 return 0;
669 }
670
671 static int
_inp_rl_win_5_handler(int count,int key)672 _inp_rl_win_5_handler(int count, int key)
673 {
674 _go_to_win(5);
675 return 0;
676 }
677
678 static int
_inp_rl_win_6_handler(int count,int key)679 _inp_rl_win_6_handler(int count, int key)
680 {
681 _go_to_win(6);
682 return 0;
683 }
684
685 static int
_inp_rl_win_7_handler(int count,int key)686 _inp_rl_win_7_handler(int count, int key)
687 {
688 _go_to_win(7);
689 return 0;
690 }
691
692 static int
_inp_rl_win_8_handler(int count,int key)693 _inp_rl_win_8_handler(int count, int key)
694 {
695 _go_to_win(8);
696 return 0;
697 }
698
699 static int
_inp_rl_win_9_handler(int count,int key)700 _inp_rl_win_9_handler(int count, int key)
701 {
702 _go_to_win(9);
703 return 0;
704 }
705
706 static int
_inp_rl_win_0_handler(int count,int key)707 _inp_rl_win_0_handler(int count, int key)
708 {
709 _go_to_win(0);
710 return 0;
711 }
712
713 static int
_inp_rl_win_11_handler(int count,int key)714 _inp_rl_win_11_handler(int count, int key)
715 {
716 _go_to_win(11);
717 return 0;
718 }
719
720 static int
_inp_rl_win_12_handler(int count,int key)721 _inp_rl_win_12_handler(int count, int key)
722 {
723 _go_to_win(12);
724 return 0;
725 }
726
727 static int
_inp_rl_win_13_handler(int count,int key)728 _inp_rl_win_13_handler(int count, int key)
729 {
730 _go_to_win(13);
731 return 0;
732 }
733
734 static int
_inp_rl_win_14_handler(int count,int key)735 _inp_rl_win_14_handler(int count, int key)
736 {
737 _go_to_win(14);
738 return 0;
739 }
740
741 static int
_inp_rl_win_15_handler(int count,int key)742 _inp_rl_win_15_handler(int count, int key)
743 {
744 _go_to_win(15);
745 return 0;
746 }
747
748 static int
_inp_rl_win_16_handler(int count,int key)749 _inp_rl_win_16_handler(int count, int key)
750 {
751 _go_to_win(16);
752 return 0;
753 }
754
755 static int
_inp_rl_win_17_handler(int count,int key)756 _inp_rl_win_17_handler(int count, int key)
757 {
758 _go_to_win(17);
759 return 0;
760 }
761
762 static int
_inp_rl_win_18_handler(int count,int key)763 _inp_rl_win_18_handler(int count, int key)
764 {
765 _go_to_win(18);
766 return 0;
767 }
768
769 static int
_inp_rl_win_19_handler(int count,int key)770 _inp_rl_win_19_handler(int count, int key)
771 {
772 _go_to_win(19);
773 return 0;
774 }
775
776 static int
_inp_rl_win_20_handler(int count,int key)777 _inp_rl_win_20_handler(int count, int key)
778 {
779 _go_to_win(20);
780 return 0;
781 }
782
783 static int
_inp_rl_win_prev_handler(int count,int key)784 _inp_rl_win_prev_handler(int count, int key)
785 {
786 ProfWin* window = wins_get_previous();
787 if (window) {
788 ui_focus_win(window);
789 }
790 return 0;
791 }
792
793 static int
_inp_rl_win_next_handler(int count,int key)794 _inp_rl_win_next_handler(int count, int key)
795 {
796 ProfWin* window = wins_get_next();
797 if (window) {
798 ui_focus_win(window);
799 }
800 return 0;
801 }
802
803 static int
_inp_rl_win_next_unread_handler(int count,int key)804 _inp_rl_win_next_unread_handler(int count, int key)
805 {
806 ProfWin* window = wins_get_next_unread();
807 if (window) {
808 ui_focus_win(window);
809 }
810 return 0;
811 }
812
813 static int
_inp_rl_win_attention_handler(int count,int key)814 _inp_rl_win_attention_handler(int count, int key) {
815 ProfWin* current = wins_get_current();
816 if ( current ) {
817 gboolean attention = win_toggle_attention(current);
818 if (attention) {
819 win_println(current, THEME_DEFAULT, "!", "Attention flag has been activated");
820 } else {
821 win_println(current, THEME_DEFAULT, "!", "Attention flag has been deactivated");
822 }
823 win_redraw(current);
824 }
825 return 0;
826 }
827
828 static int
_inp_rl_win_attention_next_handler(int count,int key)829 _inp_rl_win_attention_next_handler(int count, int key) {
830 ProfWin* window = wins_get_next_attention();
831 if (window) {
832 ui_focus_win(window);
833 }
834 return 0;
835 }
836
837
838 static int
_inp_rl_win_pageup_handler(int count,int key)839 _inp_rl_win_pageup_handler(int count, int key)
840 {
841 ProfWin* current = wins_get_current();
842 win_page_up(current);
843 return 0;
844 }
845
846 static int
_inp_rl_win_pagedown_handler(int count,int key)847 _inp_rl_win_pagedown_handler(int count, int key)
848 {
849 ProfWin* current = wins_get_current();
850 win_page_down(current);
851 return 0;
852 }
853
854 static int
_inp_rl_subwin_pageup_handler(int count,int key)855 _inp_rl_subwin_pageup_handler(int count, int key)
856 {
857 ProfWin* current = wins_get_current();
858 win_sub_page_up(current);
859 return 0;
860 }
861
862 static int
_inp_rl_subwin_pagedown_handler(int count,int key)863 _inp_rl_subwin_pagedown_handler(int count, int key)
864 {
865 ProfWin* current = wins_get_current();
866 win_sub_page_down(current);
867 return 0;
868 }
869
870 static int
_inp_rl_down_arrow_handler(int count,int key)871 _inp_rl_down_arrow_handler(int count, int key)
872 {
873 add_history(rl_line_buffer);
874 using_history();
875 rl_replace_line("", 0);
876 rl_redisplay();
877 return 0;
878 }
879