From 5b27b6ce4fe81b24a1d82020a16879d6f8b4f28c Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 8 Feb 2009 22:09:02 +0100 Subject: [PATCH] src/editline.c: tty_flush(): Silence compiler warning. meta(): Extend to support Home, End and Del keys, in addition to the arrow keys. Also capturing PgUp, PgDn and Ins to prevent them from generating odd ~ characters in input. Also rearranged a couple of callback functions so they could be reached by the meta() function without forward declaring them. This is also better placement, together with other similar fns. --- src/editline.c | 71 +++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/src/editline.c b/src/editline.c index ba15e58..09b35f0 100755 --- a/src/editline.c +++ b/src/editline.c @@ -120,8 +120,10 @@ extern int tgetnum(void); static void tty_flush(void) { + ssize_t res; + if (ScreenCount) { - (void)write(1, Screen, ScreenCount); + res = write (1, Screen, ScreenCount); ScreenCount = 0; } } @@ -764,6 +766,29 @@ static el_status_t insert_char(int c) return s; } +static el_status_t beg_line(void) +{ + if (Point) { + Point = 0; + return CSmove; + } + return CSstay; +} + +static el_status_t end_line(void) +{ + if (Point != End) { + Point = End; + return CSmove; + } + return CSstay; +} + +static el_status_t del_char(void) +{ + return delete_string(Repeat == NO_ARG ? 1 : Repeat); +} + static el_status_t meta(void) { int c; @@ -773,15 +798,24 @@ static el_status_t meta(void) return CSeof; #if defined(ANSI_ARROWS) /* Also include VT-100 arrows. */ - if (c == '[' || c == 'O') - switch (c = tty_get()) { + if (c == '[' || c == 'O') { + c = tty_get(); +// printf ("E[%c\n", c); + switch (c) { default: return ring_bell(); case EOF: return CSeof; - case 'A': return h_prev(); - case 'B': return h_next(); - case 'C': return fd_char(); - case 'D': return bk_char(); + case '2': tty_get(); return CSstay; /* Insert */ + case '3': tty_get(); return del_char(); /* Delete */ + case '5': tty_get(); return CSstay; /* PgUp */ + case '6': tty_get(); return CSstay; /* PgDn */ + case 'A': return h_prev(); /* Up */ + case 'B': return h_next(); /* Down */ + case 'C': return fd_char(); /* Left */ + case 'D': return bk_char(); /* Right */ + case 'F': return end_line(); /* End */ + case 'H': return beg_line(); /* Home */ } + } #endif /* defined(ANSI_ARROWS) */ if (isdigit(c)) { @@ -1047,29 +1081,6 @@ void add_history(char *p __attribute__ ((unused))) } -static el_status_t beg_line(void) -{ - if (Point) { - Point = 0; - return CSmove; - } - return CSstay; -} - -static el_status_t del_char(void) -{ - return delete_string(Repeat == NO_ARG ? 1 : Repeat); -} - -static el_status_t end_line(void) -{ - if (Point != End) { - Point = End; - return CSmove; - } - return CSstay; -} - /* ** Move back to the beginning of the current word and return an ** allocated copy of it.