From e361d2f498442315a074703caa63a6c55ab8b578 Mon Sep 17 00:00:00 2001 From: Emanuele Giaquinta Date: Wed, 16 Apr 2008 21:14:05 +0000 Subject: [PATCH] Remove the need to buffer input by moving the 'gui key pressed' events generation into term_gets. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4805 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-text/gui-readline.c | 15 +-------------- src/fe-text/term-curses.c | 10 ++++------ src/fe-text/term-terminfo.c | 20 +++++++++----------- src/fe-text/term.h | 2 +- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c index 61c8ddc5..1b37fde1 100644 --- a/src/fe-text/gui-readline.c +++ b/src/fe-text/gui-readline.c @@ -722,25 +722,12 @@ static void key_delete_to_next_space(void) static void sig_input(void) { - unichar buffer[128]; - int ret, i; - if (!active_entry) { /* no active entry yet - wait until we have it */ return; } - ret = term_gets(buffer, sizeof(buffer)/sizeof(buffer[0])); - if (ret == -1) { - /* lost terminal */ - if (!term_detached) - signal_emit("command quit", 1, "Lost terminal"); - } else { - for (i = 0; i < ret; i++) { - signal_emit("gui key pressed", 1, - GINT_TO_POINTER(buffer[i])); - } - } + term_gets(); } time_t get_idle_time(void) diff --git a/src/fe-text/term-curses.c b/src/fe-text/term-curses.c index e776e9c9..c79508aa 100644 --- a/src/fe-text/term-curses.c +++ b/src/fe-text/term-curses.c @@ -19,6 +19,7 @@ */ #include "module.h" +#include "signals.h" #include "settings.h" #include "term.h" @@ -384,16 +385,15 @@ void term_set_input_type(int type) { } -int term_gets(unichar *buffer, int size) +void term_gets(void) { - int count; #ifdef WIDEC_CURSES wint_t key; #else int key; #endif - for (count = 0; count < size; ) { + for (;;) { #ifdef WIDEC_CURSES if (get_wch(&key) == ERR) #else @@ -405,8 +405,6 @@ int term_gets(unichar *buffer, int size) continue; #endif - buffer[count++] = key; + signal_emit("gui key pressed", 1, GINT_TO_POINTER(key)); } - - return count; } diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c index 4b1b2bb8..293a0595 100644 --- a/src/fe-text/term-terminfo.c +++ b/src/fe-text/term-terminfo.c @@ -608,40 +608,40 @@ void term_set_input_type(int type) } } -int term_gets(unichar *buffer, int size) +void term_gets(void) { int ret, i, char_len; if (term_detached) - return 0; + return; /* fread() doesn't work */ - if (size > sizeof(term_inbuf)-term_inbuf_pos) - size = sizeof(term_inbuf)-term_inbuf_pos; ret = read(fileno(current_term->in), - term_inbuf + term_inbuf_pos, size); + term_inbuf + term_inbuf_pos, sizeof(term_inbuf)-term_inbuf_pos); if (ret == 0) { /* EOF - terminal got lost */ if (auto_detach) term_detach(); + else ret = -1; } else if (ret == -1 && (errno == EINTR || errno == EAGAIN)) ret = 0; + if (ret == -1) + signal_emit("command quit", 1, "Lost terminal"); if (ret > 0) { /* convert input to unichars. */ term_inbuf_pos += ret; - ret = 0; for (i = 0; i < term_inbuf_pos; ) { + unichar key; char_len = input_func(term_inbuf+i, term_inbuf_pos-i, - buffer); + &key); if (char_len < 0) break; + signal_emit("gui key pressed", 1, GINT_TO_POINTER(key)); i += char_len; - buffer++; - ret++; } if (i >= term_inbuf_pos) @@ -651,6 +651,4 @@ int term_gets(unichar *buffer, int size) term_inbuf_pos -= i; } } - - return ret; } diff --git a/src/fe-text/term.h b/src/fe-text/term.h index 8d109db4..f80e23b4 100644 --- a/src/fe-text/term.h +++ b/src/fe-text/term.h @@ -86,7 +86,7 @@ void term_stop(void); /* keyboard input handling */ void term_set_input_type(int type); -int term_gets(unichar *buffer, int size); +void term_gets(void); /* internal */ void term_common_init(void);