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.
This commit is contained in:
Joachim Nilsson 2009-02-08 22:09:02 +01:00
parent e828182cb0
commit 5b27b6ce4f

View File

@ -120,8 +120,10 @@ extern int tgetnum(void);
static void tty_flush(void) static void tty_flush(void)
{ {
ssize_t res;
if (ScreenCount) { if (ScreenCount) {
(void)write(1, Screen, ScreenCount); res = write (1, Screen, ScreenCount);
ScreenCount = 0; ScreenCount = 0;
} }
} }
@ -764,6 +766,29 @@ static el_status_t insert_char(int c)
return s; 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) static el_status_t meta(void)
{ {
int c; int c;
@ -773,15 +798,24 @@ static el_status_t meta(void)
return CSeof; return CSeof;
#if defined(ANSI_ARROWS) #if defined(ANSI_ARROWS)
/* Also include VT-100 arrows. */ /* Also include VT-100 arrows. */
if (c == '[' || c == 'O') if (c == '[' || c == 'O') {
switch (c = tty_get()) { c = tty_get();
// printf ("E[%c\n", c);
switch (c) {
default: return ring_bell(); default: return ring_bell();
case EOF: return CSeof; case EOF: return CSeof;
case 'A': return h_prev(); case '2': tty_get(); return CSstay; /* Insert */
case 'B': return h_next(); case '3': tty_get(); return del_char(); /* Delete */
case 'C': return fd_char(); case '5': tty_get(); return CSstay; /* PgUp */
case 'D': return bk_char(); 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) */ #endif /* defined(ANSI_ARROWS) */
if (isdigit(c)) { 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 ** Move back to the beginning of the current word and return an
** allocated copy of it. ** allocated copy of it.