1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-30 21:55:24 +00:00
profanity/src/ui/inputwin.c

830 lines
20 KiB
C
Raw Normal View History

/*
2013-02-02 19:57:46 +00:00
* inputwin.c
2012-02-20 20:07:38 +00:00
*
2019-01-22 10:31:45 +00:00
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
*
2012-02-20 20:07:38 +00:00
* 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
2016-07-24 00:14:49 +00:00
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
2012-02-20 20:07:38 +00:00
*
* 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.
*
2012-02-20 20:07:38 +00:00
*/
2013-01-03 00:16:39 +00:00
#define _XOPEN_SOURCE_EXTENDED
2016-03-31 20:05:02 +00:00
#include "config.h"
2012-09-08 15:51:09 +00:00
#include <stdio.h>
2016-01-19 22:51:55 +00:00
#include <sys/select.h>
#include <stdlib.h>
2012-08-26 00:50:50 +00:00
#include <string.h>
2013-01-03 00:16:39 +00:00
#include <wchar.h>
2015-02-01 21:01:00 +00:00
#include <sys/time.h>
#include <errno.h>
2016-04-11 18:13:18 +00:00
#include <pthread.h>
2012-05-10 22:51:06 +00:00
2015-01-30 23:28:02 +00:00
#include <readline/readline.h>
#include <readline/history.h>
2016-03-31 20:05:02 +00:00
#ifdef HAVE_NCURSESW_NCURSES_H
2013-01-02 20:27:37 +00:00
#include <ncursesw/ncurses.h>
2016-03-31 20:05:02 +00:00
#elif HAVE_NCURSES_H
#include <ncurses.h>
2012-09-08 15:51:09 +00:00
#endif
2012-05-10 22:51:06 +00:00
2016-07-24 14:43:51 +00:00
#include "profanity.h"
#include "log.h"
2013-02-02 20:55:58 +00:00
#include "common.h"
2016-07-24 14:43:51 +00:00
#include "command/cmd_ac.h"
2016-07-24 16:12:09 +00:00
#include "config/files.h"
#include "config/accounts.h"
2013-02-02 21:59:29 +00:00
#include "config/preferences.h"
#include "config/theme.h"
2013-02-02 20:55:58 +00:00
#include "ui/ui.h"
#include "ui/screen.h"
2014-04-07 20:12:30 +00:00
#include "ui/statusbar.h"
2014-04-07 20:50:28 +00:00
#include "ui/inputwin.h"
2015-06-15 19:11:34 +00:00
#include "ui/window.h"
2016-07-24 14:43:51 +00:00
#include "ui/window_list.h"
#include "xmpp/xmpp.h"
2016-07-24 14:43:51 +00:00
#include "xmpp/muc.h"
#include "xmpp/roster_list.h"
#include "xmpp/chat_state.h"
2012-02-08 23:55:11 +00:00
static WINDOW *inp_win;
2015-02-03 23:07:15 +00:00
static int pad_start = 0;
2015-01-16 23:32:57 +00:00
2015-01-30 23:28:02 +00:00
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;
2015-01-30 23:28:02 +00:00
static fd_set fds;
static int r;
static char *inp_line = NULL;
static gboolean get_password = FALSE;
2015-01-30 23:28:02 +00:00
static void _inp_win_update_virtual(void);
2018-02-09 22:48:55 +00:00
static int _inp_edited(const wint_t ch);
2015-02-03 23:07:15 +00:00
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);
2015-12-06 01:12:28 +00:00
static void _inp_rl_addfuncs(void);
2015-02-03 23:07:15 +00:00
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_shift_tab_handler(int count, int key);
2015-12-06 01:29:51 +00:00
static int _inp_rl_win_clear_handler(int count, int key);
2019-01-10 11:44:52 +00:00
static int _inp_rl_win_close_handler(int count, int key);
2015-12-06 01:29:51 +00:00
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_11_handler(int count, int key);
static int _inp_rl_win_12_handler(int count, int key);
static int _inp_rl_win_13_handler(int count, int key);
static int _inp_rl_win_14_handler(int count, int key);
static int _inp_rl_win_15_handler(int count, int key);
static int _inp_rl_win_16_handler(int count, int key);
static int _inp_rl_win_17_handler(int count, int key);
static int _inp_rl_win_18_handler(int count, int key);
static int _inp_rl_win_19_handler(int count, int key);
static int _inp_rl_win_20_handler(int count, int key);
2015-12-06 01:29:51 +00:00
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_next_unread_handler(int count, int key);
2015-12-06 01:29:51 +00:00
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);
2015-02-03 23:07:15 +00:00
static int _inp_rl_startup_hook(void);
static int _inp_rl_down_arrow_handler(int count, int key);
2015-02-03 23:07:15 +00:00
void
create_input_window(void)
{
#ifdef NCURSES_REENTRANT
set_escdelay(25);
#else
ESCDELAY = 25;
#endif
discard = fopen("/dev/null", "a");
rl_outstream = discard;
2015-02-03 23:07:15 +00:00
rl_readline_name = "profanity";
2015-12-06 01:12:28 +00:00
_inp_rl_addfuncs();
2015-02-03 23:07:15 +00:00
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();
}
2015-10-25 23:31:11 +00:00
char*
2015-02-03 23:07:15 +00:00
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;
2015-02-03 23:07:15 +00:00
FD_ZERO(&fds);
FD_SET(fileno(rl_instream), &fds);
errno = 0;
2016-04-11 18:13:18 +00:00
pthread_mutex_unlock(&lock);
2015-02-03 23:07:15 +00:00
r = select(FD_SETSIZE, &fds, NULL, NULL, &p_rl_timeout);
2016-04-11 18:13:18 +00:00
pthread_mutex_lock(&lock);
2015-02-03 23:07:15 +00:00
if (r < 0) {
if (errno != EINTR) {
char *err_msg = strerror(errno);
log_error("Readline failed: %s", err_msg);
}
return NULL;
2015-02-03 23:07:15 +00:00
}
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') {
chat_state_activity();
2015-02-03 23:07:15 +00:00
}
ui_reset_idle_time();
if (!get_password) {
_inp_write(rl_line_buffer, rl_point);
}
2015-02-03 23:07:15 +00:00
inp_nonblocking(TRUE);
} else {
inp_nonblocking(FALSE);
chat_state_idle();
2015-02-03 23:07:15 +00:00
}
if (inp_line) {
return strdup(inp_line);
} else {
return NULL;
}
2015-02-03 23:07:15 +00:00
}
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);
2015-02-03 23:07:15 +00:00
}
2015-10-25 23:31:11 +00:00
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();
}
2018-03-10 22:16:52 +00:00
status_bar_clear_prompt();
return line;
}
char*
inp_get_password(void)
2015-02-03 23:07:15 +00:00
{
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;
2018-03-10 22:16:52 +00:00
status_bar_clear_prompt();
return password;
2015-02-03 23:07:15 +00:00
}
void
inp_put_back(void)
{
_inp_win_update_virtual();
}
static void
_inp_win_update_virtual(void)
{
int wcols = getmaxx(stdscr);
int row = screen_inputwin_row();
pnoutrefresh(inp_win, 0, pad_start, row, 0, row, wcols-2);
2015-02-03 23:07:15 +00:00
}
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();
2015-02-03 23:07:15 +00:00
}
static int
2018-02-09 22:48:55 +00:00
_inp_edited(const wint_t ch)
{
2018-02-09 22:48:55 +00:00
// backspace
if (ch == 127) {
return 1;
}
// ctrl-w
if (ch == 23) {
return 1;
}
// enter
if (ch == 13) {
return 1;
}
// printable
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);
2015-07-19 21:48:12 +00:00
return g_unichar_isprint(unichar);
}
2015-02-03 23:07:15 +00:00
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);
2015-02-03 23:07:15 +00:00
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);
2015-02-06 14:11:21 +00:00
if (col == 0) {
pad_start = 0;
} else if (col >= pad_start + (wcols -2)) {
2015-02-03 23:07:15 +00:00
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;
}
}
}
2015-12-06 01:12:28 +00:00
static void
_inp_rl_addfuncs(void)
{
2015-12-06 01:29:51 +00:00
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_11", _inp_rl_win_11_handler);
rl_add_funmap_entry("prof_win_12", _inp_rl_win_12_handler);
rl_add_funmap_entry("prof_win_13", _inp_rl_win_13_handler);
rl_add_funmap_entry("prof_win_14", _inp_rl_win_14_handler);
rl_add_funmap_entry("prof_win_15", _inp_rl_win_15_handler);
rl_add_funmap_entry("prof_win_16", _inp_rl_win_16_handler);
rl_add_funmap_entry("prof_win_17", _inp_rl_win_17_handler);
rl_add_funmap_entry("prof_win_18", _inp_rl_win_18_handler);
rl_add_funmap_entry("prof_win_19", _inp_rl_win_19_handler);
rl_add_funmap_entry("prof_win_20", _inp_rl_win_20_handler);
2015-12-06 01:29:51 +00:00
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_next_unread", _inp_rl_win_next_unread_handler);
2015-12-06 01:29:51 +00:00
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);
2019-01-10 11:44:52 +00:00
rl_add_funmap_entry("prof_win_close", _inp_rl_win_close_handler);
2015-12-06 01:12:28 +00:00
}
2015-02-03 23:07:15 +00:00
// Readline callbacks
2015-02-03 23:27:06 +00:00
static int
_inp_rl_startup_hook(void)
{
2015-12-06 01:29:51 +00:00
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("\\eq", _inp_rl_win_11_handler);
rl_bind_keyseq("\\ew", _inp_rl_win_12_handler);
rl_bind_keyseq("\\ee", _inp_rl_win_13_handler);
rl_bind_keyseq("\\er", _inp_rl_win_14_handler);
rl_bind_keyseq("\\et", _inp_rl_win_15_handler);
rl_bind_keyseq("\\ey", _inp_rl_win_16_handler);
rl_bind_keyseq("\\eu", _inp_rl_win_17_handler);
rl_bind_keyseq("\\ei", _inp_rl_win_18_handler);
rl_bind_keyseq("\\eo", _inp_rl_win_19_handler);
rl_bind_keyseq("\\ep", _inp_rl_win_20_handler);
2015-12-06 01:29:51 +00:00
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("\\ea", _inp_rl_win_next_unread_handler);
2015-12-06 01:29:51 +00:00
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);
2015-02-03 23:27:06 +00:00
rl_bind_key('\t', _inp_rl_tab_handler);
rl_bind_keyseq("\\e[Z", _inp_rl_shift_tab_handler);
2015-02-03 23:27:06 +00:00
rl_bind_keyseq("\\e[1;5B", _inp_rl_down_arrow_handler); // ctrl+arrow down
2015-09-29 20:08:20 +00:00
// unbind unwanted mappings
rl_bind_keyseq("\\e=", NULL);
2015-11-29 22:23:31 +00:00
// disable readline completion
rl_variable_bind("disable-completion", "on");
2015-12-06 02:12:20 +00:00
// check for and load ~/.config/profanity/inputrc
2016-07-24 20:35:12 +00:00
char *inputrc = files_get_inputrc_file();
2015-12-06 02:12:20 +00:00
if (inputrc) {
rl_read_init_file(inputrc);
free(inputrc);
}
2015-02-03 23:27:06 +00:00
return 0;
}
2015-01-30 23:28:02 +00:00
static void
2015-02-03 23:07:15 +00:00
_inp_rl_linehandler(char *line)
2015-01-30 23:28:02 +00:00
{
2015-02-02 21:27:58 +00:00
if (line && *line) {
if (!get_password) {
add_history(line);
}
2015-01-30 23:28:02 +00:00
}
inp_line = line;
2015-01-30 23:28:02 +00:00
}
static gboolean shift_tab = FALSE;
2015-02-03 23:07:15 +00:00
static int
_inp_rl_getc(FILE *stream)
{
2015-02-03 23:07:15 +00:00
int ch = rl_getc(stream);
// 27, 91, 90 = Shift tab
if (ch == 27) {
shift_tab = TRUE;
return ch;
}
if (shift_tab && ch == 91) {
return ch;
}
if (shift_tab && ch == 90) {
return ch;
}
shift_tab = FALSE;
2018-02-09 22:48:55 +00:00
if (_inp_edited(ch)) {
2015-06-16 21:59:08 +00:00
ProfWin *window = wins_get_current();
2016-05-19 23:19:03 +00:00
cmd_ac_reset(window);
}
return ch;
}
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_clear_handler(int count, int key)
{
2015-06-15 16:54:47 +00:00
ProfWin *win = wins_get_current();
win_clear(win);
return 0;
}
2019-01-10 11:44:52 +00:00
static int
_inp_rl_win_close_handler(int count, int key)
{
ProfWin *win = wins_get_current();
gchar* args = 0;
cmd_close(win, 0, &args);
return 0;
}
2015-02-03 23:07:15 +00:00
static int
_inp_rl_tab_handler(int count, int key)
2015-01-31 01:58:15 +00:00
{
if (rl_point != rl_end || !rl_line_buffer) {
2015-01-31 01:58:15 +00:00
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, FALSE);
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_ac_complete(window, rl_line_buffer, FALSE);
if (result) {
rl_replace_line(result, 1);
rl_point = rl_end;
free(result);
}
}
return 0;
}
static int
_inp_rl_shift_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, TRUE);
2015-01-31 01:58:15 +00:00
if (result) {
rl_replace_line(result, 1);
2015-01-31 01:58:15 +00:00
rl_point = rl_end;
2015-06-24 19:20:55 +00:00
free(result);
2015-01-31 01:58:15 +00:00
}
} else if (strncmp(rl_line_buffer, "/", 1) == 0) {
2015-06-16 21:59:08 +00:00
ProfWin *window = wins_get_current();
char *result = cmd_ac_complete(window, rl_line_buffer, TRUE);
2015-01-31 01:58:15 +00:00
if (result) {
rl_replace_line(result, 1);
2015-01-31 01:58:15 +00:00
rl_point = rl_end;
free(result);
2015-01-31 01:58:15 +00:00
}
}
return 0;
}
2015-04-30 21:09:39 +00:00
static void
_go_to_win(int i)
{
ProfWin *window = wins_get_by_num(i);
if (window) {
2015-11-02 20:59:36 +00:00
ui_focus_win(window);
2015-04-30 21:09:39 +00:00
}
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_1_handler(int count, int key)
2015-01-31 18:02:42 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(1);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_2_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(2);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_3_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(3);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_4_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(4);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_5_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(5);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_6_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(6);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_7_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(7);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_8_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(8);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_9_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(9);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_0_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-04-30 21:09:39 +00:00
_go_to_win(0);
2015-01-31 22:00:22 +00:00
return 0;
}
static int
_inp_rl_win_11_handler(int count, int key)
{
_go_to_win(11);
return 0;
}
static int
_inp_rl_win_12_handler(int count, int key)
{
_go_to_win(12);
return 0;
}
static int
_inp_rl_win_13_handler(int count, int key)
{
_go_to_win(13);
return 0;
}
static int
_inp_rl_win_14_handler(int count, int key)
{
_go_to_win(14);
return 0;
}
static int
_inp_rl_win_15_handler(int count, int key)
{
_go_to_win(15);
return 0;
}
static int
_inp_rl_win_16_handler(int count, int key)
{
_go_to_win(16);
return 0;
}
static int
_inp_rl_win_17_handler(int count, int key)
{
_go_to_win(17);
return 0;
}
static int
_inp_rl_win_18_handler(int count, int key)
{
_go_to_win(18);
return 0;
}
static int
_inp_rl_win_19_handler(int count, int key)
{
_go_to_win(19);
return 0;
}
static int
_inp_rl_win_20_handler(int count, int key)
{
_go_to_win(20);
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_prev_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
ProfWin *window = wins_get_previous();
if (window) {
2015-11-02 20:59:36 +00:00
ui_focus_win(window);
}
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_next_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
ProfWin *window = wins_get_next();
if (window) {
2015-11-02 20:59:36 +00:00
ui_focus_win(window);
}
2015-01-31 22:00:22 +00:00
return 0;
}
static int
_inp_rl_win_next_unread_handler(int count, int key)
{
ProfWin *window = wins_get_next_unread();
if (window) {
ui_focus_win(window);
}
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_pageup_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-11-01 18:49:53 +00:00
ProfWin *current = wins_get_current();
win_page_up(current);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_win_pagedown_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-11-01 18:49:53 +00:00
ProfWin *current = wins_get_current();
win_page_down(current);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_subwin_pageup_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-11-01 18:49:53 +00:00
ProfWin *current = wins_get_current();
win_sub_page_up(current);
2015-01-31 22:00:22 +00:00
return 0;
}
2015-02-03 23:07:15 +00:00
static int
2015-12-06 01:29:51 +00:00
_inp_rl_subwin_pagedown_handler(int count, int key)
2015-01-31 22:00:22 +00:00
{
2015-11-01 18:49:53 +00:00
ProfWin *current = wins_get_current();
win_sub_page_down(current);
2015-01-31 22:00:22 +00:00
return 0;
}
static int
_inp_rl_down_arrow_handler(int count, int key)
{
add_history(rl_line_buffer);
using_history();
rl_replace_line("", 0);
rl_redisplay();
return 0;
}