From 5e032b9b6a2dc023fc9a00006877b4233c301401 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 11 Sep 2015 06:08:59 -0700 Subject: linenoise: replace 9 with TAB; anticipate extension. * linenoise/linenoise.c (edit): Code block which handles tab completion before main command dispatch uses the TAB symbol instead of 9, and is refactored into a switch statement which will also handle a history search command. --- linenoise/linenoise.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 1440a68a..0622d258 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -756,13 +756,15 @@ static int edit(lino_t *l, const char *prompt) return -1; } while(1) { - char c; + unsigned char byte; + int c; int nread; char seq[3]; - nread = read(l->ifd,&c,1); + nread = read(l->ifd,&byte,1); if (nread <= 0) return l->len ? (int) l->len : -1; + c = byte; if (verbatim) { if (edit_insert(l,c)) { @@ -776,14 +778,18 @@ static int edit(lino_t *l, const char *prompt) /* Only autocomplete when the callback is set. It returns < 0 when * there was an error reading from fd. Otherwise it will return the * character that should be handled next. */ - if (c == 9 && l->completion_callback != NULL) { - c = complete_line(l); - /* Return on errors */ - if (c < 0) return l->len; - /* Read next character when 0 */ - if (c == 0) continue; + switch (c) { + case TAB: + if (l->completion_callback != NULL) + c = complete_line(l); + break; } + if (c < 0) + return l->len; + if (c == 0) + continue; + switch(c) { case ENTER: if (l->history_len > 0) { -- cgit v1.2.3