about summary refs log tree commit diff stats
path: root/src/tools/bookmark_ignore.h
Commit message (Expand)AuthorAgeFilesLines
* Apply coding styleMichael Vetter2020-07-071-4/+4
* Revert "Apply coding style"Michael Vetter2020-07-071-4/+4
* Apply coding styleMichael Vetter2020-07-071-4/+4
* Add bookmark ignore add|removeMichael Vetter2020-05-241-0/+2
* List ignored bookmarksMichael Vetter2020-05-241-0/+1
* Add bookmark ignore functionality for multiple accountsMichael Vetter2020-05-241-0/+2
* PoC for bookmark ignoreMichael Vetter2020-05-241-0/+41
div>
f9737251 ^











a7d89e0e ^

439e6486 ^
8e0d8d2a ^

10507b68 ^
f928fb36 ^
fe519410 ^
1e6a1f99 ^
439e6486 ^
51a54260 ^
b2536e91 ^
46ee72f9 ^
83bd2073 ^


d28930ea ^

57f9e435 ^

8e0d8d2a ^
46ee72f9 ^
740e5b42 ^
fc5bfb7d ^
99d33228 ^
9d34c412 ^

5ce97728 ^
4b14c0c4 ^
118d97cd ^
107fdd35 ^
fc5bfb7d ^
f0f0dbfd ^
9aa282f6 ^
5cdd69f4 ^
38ed9188 ^
c1ee75da ^
dae4f1bb ^
c8bf654e ^
8b58eb68 ^
e1db13ea ^
83bd2073 ^
f24019ee ^
b3448eb2 ^


1e6a1f99 ^
83bd2073 ^

a70aa025 ^

83bd2073 ^
2ed78fe5 ^
8b58eb68 ^

8b58eb68 ^


0d25de94 ^
8b58eb68 ^


e9e54dca ^
















8b58eb68 ^









1e6a1f99 ^

8b58eb68 ^
0d25de94 ^
8b58eb68 ^



8b58eb68 ^







2ce43b63 ^
8b58eb68 ^

a70aa025 ^

f24019ee ^

8b58eb68 ^

b2536e91 ^
8b58eb68 ^

f24019ee ^



a70aa025 ^
8b58eb68 ^




a70aa025 ^



8b58eb68 ^



d8c410d2 ^


8b58eb68 ^





a70aa025 ^




8b58eb68 ^














































8b58eb68 ^


1e6a1f99 ^
8b58eb68 ^

2ce43b63 ^
9414ad26 ^








de15d47b ^
9414ad26 ^




a70aa025 ^

generated by cgit-pink 1.4.1-2-gfad0 (git 2.36.2.497.gbbea4dcf42) at 2024-12-12 03:59:40 +0000
/ui/inputwin.c?id=b3448eb265c7b656c07d3a72ea498dc6b5c5b888'>^
48a2cad8 ^
2b11baa5 ^

cfef64c7 ^

2b11baa5 ^
bee3e15e ^
2b11baa5 ^
17919298 ^
2b11baa5 ^





d68fb25d ^




75bce88b ^
d68fb25d ^


8b58eb68 ^
e9e54dca ^
e6f27de5 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
d68fb25d ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
e11e55e3 ^

75bce88b ^
e11e55e3 ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
e11e55e3 ^

75bce88b ^
e11e55e3 ^
28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
8195ab42 ^

28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
8195ab42 ^

28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
8195ab42 ^

28dd5458 ^


8b58eb68 ^
e9e54dca ^
28dd5458 ^
8195ab42 ^

28dd5458 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
  
             
  
                                                            
  














                                                                       











                                                                                

   
                              

                   
                       
                   
                   
                  
                  
                     
                  
 


                              

                              

                    
      
 
                            
                   
                            

                               
                
                
                      
                        
                  
                         
                        
                      
                        
                      
 
                       
                         
 
                                   
                                                       


                               
                     

                  

                                     
 
                                          

                                           


                                                     
                                   


                                                   
















                                                               









                                      

                                      
                                   
                       



                                                           







                                                   
     

                  

                    

                                                     

                                      
              

                                                            



                                                      
                    




                                              



                                            



                                   


                                                 





                               




                                














































                                                          


                                 
                    

 
     








                              
                    




                       

                      


                         

                              



                                  
                    

                         
                       
                    







                              

















                                                                      
               
 
 
          
                               

                             
                                                          


                                              
                                      

 







                                                
                                                          










                                    




                                


                                               











                                            


                      
















                                                                                 

 

                     


                          









































                                                                 


                                           


                                 


                                                 






                                                     


             
           
                               
 
                        


                              
     
                    

 

                          
 

                             

                                             



              
          
                                             
 

                                      



             
                                       
 
                                                


                 


                                                                               
                     
                                       
                              
                         

                                                      

                                                                
                     
                                       
                              
                         





             




                                         
                             


     
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                         
 
                  


             
          
                                            
 

                                          
                             
     


             
          
                                            
 

                                      
                             
     


             
          
                                              
 

                                          


             
          
                                                
 

                                          


             
          
                                                 
 

                                          


             
          
                                                   
 

                                          

             
/*
 * inputwin.c
 *
 * Copyright (C) 2012 - 2015 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#define _XOPEN_SOURCE_EXTENDED
#include "config.h"

#include <sys/select.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <wchar.h>
#include <sys/time.h>
#include <errno.h>

#include <readline/readline.h>
#include <readline/history.h>

#ifdef HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h>
#elif HAVE_NCURSES_H
#include <ncurses.h>
#endif

#include "command/command.h"
#include "common.h"
#include "config/accounts.h"
#include "config/preferences.h"
#include "config/theme.h"
#include "log.h"
#include "muc.h"
#include "profanity.h"
#include "roster_list.h"
#include "ui/ui.h"
#include "ui/statusbar.h"
#include "ui/inputwin.h"
#include "ui/window.h"
#include "window_list.h"
#include "xmpp/xmpp.h"

static WINDOW *inp_win;
static int pad_start = 0;

static struct timeval p_rl_timeout;
/* Timeout in ms. Shows how long select() may block. */
static gint inp_timeout = 0;
static gint no_input_count = 0;

static FILE *discard;
static fd_set fds;
static int r;
static char *inp_line = NULL;
static gboolean get_password = FALSE;

static void _inp_win_update_virtual(void);
static int _inp_printable(const wint_t ch);
static void _inp_win_handle_scroll(void);
static int _inp_offset_to_col(char *str, int offset);
static void _inp_write(char *line, int offset);

static void _inp_rl_addfuncs(void);
static int _inp_rl_getc(FILE *stream);
static void _inp_rl_linehandler(char *line);
static int _inp_rl_tab_handler(int count, int key);
static int _inp_rl_win_clear_handler(int count, int key);
static int _inp_rl_win_1_handler(int count, int key);
static int _inp_rl_win_2_handler(int count, int key);
static int _inp_rl_win_3_handler(int count, int key);
static int _inp_rl_win_4_handler(int count, int key);
static int _inp_rl_win_5_handler(int count, int key);
static int _inp_rl_win_6_handler(int count, int key);
static int _inp_rl_win_7_handler(int count, int key);
static int _inp_rl_win_8_handler(int count, int key);
static int _inp_rl_win_9_handler(int count, int key);
static int _inp_rl_win_0_handler(int count, int key);
static int _inp_rl_win_prev_handler(int count, int key);
static int _inp_rl_win_next_handler(int count, int key);
static int _inp_rl_win_pageup_handler(int count, int key);
static int _inp_rl_win_pagedown_handler(int count, int key);
static int _inp_rl_subwin_pageup_handler(int count, int key);
static int _inp_rl_subwin_pagedown_handler(int count, int key);
static int _inp_rl_startup_hook(void);

void
create_input_window(void)
{
#ifdef NCURSES_REENTRANT
    set_escdelay(25);
#else
    ESCDELAY = 25;
#endif
    discard = fopen("/dev/null", "a");
    rl_outstream = discard;
    rl_readline_name = "profanity";
    _inp_rl_addfuncs();
    rl_getc_function = _inp_rl_getc;
    rl_startup_hook = _inp_rl_startup_hook;
    rl_callback_handler_install(NULL, _inp_rl_linehandler);

    inp_win = newpad(1, INP_WIN_MAX);
    wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));;
    keypad(inp_win, TRUE);
    wmove(inp_win, 0, 0);

    _inp_win_update_virtual();
}

char*
inp_readline(void)
{
    free(inp_line);
    inp_line = NULL;
    p_rl_timeout.tv_sec = inp_timeout / 1000;
    p_rl_timeout.tv_usec = inp_timeout % 1000 * 1000;
    FD_ZERO(&fds);
    FD_SET(fileno(rl_instream), &fds);
    errno = 0;
    r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout);
    if (r < 0) {
        if (errno != EINTR) {
            char *err_msg = strerror(errno);
            log_error("Readline failed: %s", err_msg);
        }
        return NULL;
    }

    if (FD_ISSET(fileno(rl_instream), &fds)) {
        rl_callback_read_char();

        if (rl_line_buffer &&
                rl_line_buffer[0] != '/' &&
                rl_line_buffer[0] != '\0' &&
                rl_line_buffer[0] != '\n') {
            prof_handle_activity();
        }

        ui_reset_idle_time();
        if (!get_password) {
            _inp_write(rl_line_buffer, rl_point);
        }
        inp_nonblocking(TRUE);
    } else {
        inp_nonblocking(FALSE);
        prof_handle_idle();
    }

    if (inp_line) {
        return strdup(inp_line);
    } else {
        return NULL;
    }
}

void
inp_win_resize(void)
{
    int col = getcurx(inp_win);
    int wcols = getmaxx(stdscr);

    // if lost cursor off screen, move contents to show it
    if (col >= pad_start + wcols) {
        pad_start = col - (wcols / 2);
        if (pad_start < 0) {
            pad_start = 0;
        }
    }

    wbkgd(inp_win, theme_attrs(THEME_INPUT_TEXT));;
    _inp_win_update_virtual();
}

void
inp_nonblocking(gboolean reset)
{
    if (! prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) {
        inp_timeout = prefs_get_inpblock();
        return;
    }

    if (reset) {
        inp_timeout = 0;
        no_input_count = 0;
    }

    if (inp_timeout < prefs_get_inpblock()) {
        no_input_count++;

        if (no_input_count % 10 == 0) {
            inp_timeout += no_input_count;

            if (inp_timeout > prefs_get_inpblock()) {
                inp_timeout = prefs_get_inpblock();
            }
        }
    }
}

void
inp_close(void)
{
    rl_callback_handler_remove();
    fclose(discard);
}

char*
inp_get_line(void)
{
    werase(inp_win);
    wmove(inp_win, 0, 0);
    _inp_win_update_virtual();
    doupdate();
    char *line = NULL;
    while (!line) {
        line = inp_readline();
        ui_update();
    }
    status_bar_clear();
    return line;
}

char*
inp_get_password(void)
{
    werase(inp_win);
    wmove(inp_win, 0, 0);
    _inp_win_update_virtual();
    doupdate();
    char *password = NULL;
    get_password = TRUE;
    while (!password) {
        password = inp_readline();
        ui_update();
    }
    get_password = FALSE;
    status_bar_clear();
    return password;
}

void
inp_put_back(void)
{
    _inp_win_update_virtual();
}

static void
_inp_win_update_virtual(void)
{
    int wrows, wcols;
    getmaxyx(stdscr, wrows, wcols);
    pnoutrefresh(inp_win, 0, pad_start, wrows-1, 0, wrows-1, wcols-2);
}

static void
_inp_write(char *line, int offset)
{
    int col = _inp_offset_to_col(line, offset);
    werase(inp_win);
    waddstr(inp_win, line);
    wmove(inp_win, 0, col);
    _inp_win_handle_scroll();

    _inp_win_update_virtual();
    doupdate();
}

static int
_inp_printable(const wint_t ch)
{
    char bytes[MB_CUR_MAX+1];
    size_t utf_len = wcrtomb(bytes, ch, (mbstate_t*)NULL);
    bytes[utf_len] = '\0';
    gunichar unichar = g_utf8_get_char(bytes);

    return g_unichar_isprint(unichar);
}

static int
_inp_offset_to_col(char *str, int offset)
{
    int i = 0;
    int col = 0;

    while (i < offset && str[i] != '\0') {
        gunichar uni = g_utf8_get_char(&str[i]);
        size_t ch_len = mbrlen(&str[i], MB_CUR_MAX, NULL);
        i += ch_len;
        col++;
        if (g_unichar_iswide(uni)) {
            col++;
        }
    }

    return col;
}

static void
_inp_win_handle_scroll(void)
{
    int col = getcurx(inp_win);
    int wcols = getmaxx(stdscr);

    if (col == 0) {
        pad_start = 0;
    } else if (col >= pad_start + (wcols -2)) {
        pad_start = col - (wcols / 2);
        if (pad_start < 0) {
            pad_start = 0;
        }
    } else if (col <= pad_start) {
        pad_start = pad_start - (wcols / 2);
        if (pad_start < 0) {
            pad_start = 0;
        }
    }
}

static void
_inp_rl_addfuncs(void)
{
    rl_add_funmap_entry("prof_win_1", _inp_rl_win_1_handler);
    rl_add_funmap_entry("prof_win_2", _inp_rl_win_2_handler);
    rl_add_funmap_entry("prof_win_3", _inp_rl_win_3_handler);
    rl_add_funmap_entry("prof_win_4", _inp_rl_win_4_handler);
    rl_add_funmap_entry("prof_win_5", _inp_rl_win_5_handler);
    rl_add_funmap_entry("prof_win_6", _inp_rl_win_6_handler);
    rl_add_funmap_entry("prof_win_7", _inp_rl_win_7_handler);
    rl_add_funmap_entry("prof_win_8", _inp_rl_win_8_handler);
    rl_add_funmap_entry("prof_win_9", _inp_rl_win_9_handler);
    rl_add_funmap_entry("prof_win_0", _inp_rl_win_0_handler);
    rl_add_funmap_entry("prof_win_prev", _inp_rl_win_prev_handler);
    rl_add_funmap_entry("prof_win_next", _inp_rl_win_next_handler);
    rl_add_funmap_entry("prof_win_pageup", _inp_rl_win_pageup_handler);
    rl_add_funmap_entry("prof_win_pagedown", _inp_rl_win_pagedown_handler);
    rl_add_funmap_entry("prof_subwin_pageup", _inp_rl_subwin_pageup_handler);
    rl_add_funmap_entry("prof_subwin_pagedown", _inp_rl_subwin_pagedown_handler);
    rl_add_funmap_entry("prof_win_clear", _inp_rl_win_clear_handler);
}

// Readline callbacks

static int
_inp_rl_startup_hook(void)
{
    rl_bind_keyseq("\\e1", _inp_rl_win_1_handler);
    rl_bind_keyseq("\\e2", _inp_rl_win_2_handler);
    rl_bind_keyseq("\\e3", _inp_rl_win_3_handler);
    rl_bind_keyseq("\\e4", _inp_rl_win_4_handler);
    rl_bind_keyseq("\\e5", _inp_rl_win_5_handler);
    rl_bind_keyseq("\\e6", _inp_rl_win_6_handler);
    rl_bind_keyseq("\\e7", _inp_rl_win_7_handler);
    rl_bind_keyseq("\\e8", _inp_rl_win_8_handler);
    rl_bind_keyseq("\\e9", _inp_rl_win_9_handler);
    rl_bind_keyseq("\\e0", _inp_rl_win_0_handler);

    rl_bind_keyseq("\\eOP", _inp_rl_win_1_handler);
    rl_bind_keyseq("\\eOQ", _inp_rl_win_2_handler);
    rl_bind_keyseq("\\eOR", _inp_rl_win_3_handler);
    rl_bind_keyseq("\\eOS", _inp_rl_win_4_handler);
    rl_bind_keyseq("\\e[15~", _inp_rl_win_5_handler);
    rl_bind_keyseq("\\e[17~", _inp_rl_win_6_handler);
    rl_bind_keyseq("\\e[18~", _inp_rl_win_7_handler);
    rl_bind_keyseq("\\e[19~", _inp_rl_win_8_handler);
    rl_bind_keyseq("\\e[20~", _inp_rl_win_9_handler);
    rl_bind_keyseq("\\e[21~", _inp_rl_win_0_handler);

    rl_bind_keyseq("\\e[1;9D", _inp_rl_win_prev_handler);
    rl_bind_keyseq("\\e[1;3D", _inp_rl_win_prev_handler);
    rl_bind_keyseq("\\e\\e[D", _inp_rl_win_prev_handler);

    rl_bind_keyseq("\\e[1;9C", _inp_rl_win_next_handler);
    rl_bind_keyseq("\\e[1;3C", _inp_rl_win_next_handler);
    rl_bind_keyseq("\\e\\e[C", _inp_rl_win_next_handler);

    rl_bind_keyseq("\\e\\e[5~", _inp_rl_subwin_pageup_handler);
    rl_bind_keyseq("\\e[5;3~", _inp_rl_subwin_pageup_handler);
    rl_bind_keyseq("\\e\\eOy", _inp_rl_subwin_pageup_handler);

    rl_bind_keyseq("\\e\\e[6~", _inp_rl_subwin_pagedown_handler);
    rl_bind_keyseq("\\e[6;3~", _inp_rl_subwin_pagedown_handler);
    rl_bind_keyseq("\\e\\eOs", _inp_rl_subwin_pagedown_handler);

    rl_bind_keyseq("\\e[5~", _inp_rl_win_pageup_handler);
    rl_bind_keyseq("\\eOy", _inp_rl_win_pageup_handler);
    rl_bind_keyseq("\\e[6~", _inp_rl_win_pagedown_handler);
    rl_bind_keyseq("\\eOs", _inp_rl_win_pagedown_handler);

    rl_bind_key('\t', _inp_rl_tab_handler);

    // unbind unwanted mappings
    rl_bind_keyseq("\\e=", NULL);

    // disable readline completion
    rl_variable_bind("disable-completion", "on");

    // check for and load ~/.config/profanity/inputrc
    char *inputrc = prefs_get_inputrc();
    if (inputrc) {
        rl_read_init_file(inputrc);
        free(inputrc);
    }

    return 0;
}

static void
_inp_rl_linehandler(char *line)
{
    if (line && *line) {
        if (!get_password) {
            add_history(line);
        }
    }
    inp_line = line;
}

static int
_inp_rl_getc(FILE *stream)
{
    int ch = rl_getc(stream);
    if (_inp_printable(ch)) {
        ProfWin *window = wins_get_current();
        cmd_reset_autocomplete(window);
    }
    return ch;
}

static int
_inp_rl_win_clear_handler(int count, int key)
{
    ProfWin *win = wins_get_current();
    win_clear(win);
    return 0;
}

static int
_inp_rl_tab_handler(int count, int key)
{
    if (rl_point != rl_end || !rl_line_buffer) {
        return 0;
    }

    ProfWin *current = wins_get_current();
    if ((strncmp(rl_line_buffer, "/", 1) != 0) && (current->type == WIN_MUC)) {
        char *result = muc_autocomplete(current, rl_line_buffer);
        if (result) {
            rl_replace_line(result, 1);
            rl_point = rl_end;
            free(result);
        }
    } else if (strncmp(rl_line_buffer, "/", 1) == 0) {
        ProfWin *window = wins_get_current();
        char *result = cmd_autocomplete(window, rl_line_buffer);
        if (result) {
            rl_replace_line(result, 1);
            rl_point = rl_end;
            free(result);
        }
    }

    return 0;
}

static void
_go_to_win(int i)
{
    ProfWin *window = wins_get_by_num(i);
    if (window) {
        ui_focus_win(window);
    }
}

static int
_inp_rl_win_1_handler(int count, int key)
{
    _go_to_win(1);
    return 0;
}

static int
_inp_rl_win_2_handler(int count, int key)
{
    _go_to_win(2);
    return 0;
}

static int
_inp_rl_win_3_handler(int count, int key)
{
    _go_to_win(3);
    return 0;
}

static int
_inp_rl_win_4_handler(int count, int key)
{
    _go_to_win(4);
    return 0;
}

static int
_inp_rl_win_5_handler(int count, int key)
{
    _go_to_win(5);
    return 0;
}

static int
_inp_rl_win_6_handler(int count, int key)
{
    _go_to_win(6);
    return 0;
}

static int
_inp_rl_win_7_handler(int count, int key)
{
    _go_to_win(7);
    return 0;
}

static int
_inp_rl_win_8_handler(int count, int key)
{
    _go_to_win(8);
    return 0;
}

static int
_inp_rl_win_9_handler(int count, int key)
{
    _go_to_win(9);
    return 0;
}

static int
_inp_rl_win_0_handler(int count, int key)
{
    _go_to_win(0);
    return 0;
}

static int
_inp_rl_win_prev_handler(int count, int key)
{
    ProfWin *window = wins_get_previous();
    if (window) {
        ui_focus_win(window);
    }
    return 0;
}

static int
_inp_rl_win_next_handler(int count, int key)
{
    ProfWin *window = wins_get_next();
    if (window) {
        ui_focus_win(window);
    }
    return 0;
}

static int
_inp_rl_win_pageup_handler(int count, int key)
{
    ProfWin *current = wins_get_current();
    win_page_up(current);
    return 0;
}

static int
_inp_rl_win_pagedown_handler(int count, int key)
{
    ProfWin *current = wins_get_current();
    win_page_down(current);
    return 0;
}

static int
_inp_rl_subwin_pageup_handler(int count, int key)
{
    ProfWin *current = wins_get_current();
    win_sub_page_up(current);
    return 0;
}

static int
_inp_rl_subwin_pagedown_handler(int count, int key)
{
    ProfWin *current = wins_get_current();
    win_sub_page_down(current);
    return 0;
}