From d8257ec1f490f80b5d168def3cb4e36d969fe526 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 16 Sep 2015 20:29:31 -0700 Subject: linenoise: Ctrl-X extended commands. * linenoise/linenoise.c (edit): Handle the Ctrl-X key by setting a temporary flag. This sets the framework for commands prefixed by Ctrl-X. --- linenoise/linenoise.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 2a6173a4..515e775d 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1012,7 +1012,7 @@ static void edit_delete_prev_word(lino_t *l) { * The function returns the length of the current buffer. */ static int edit(lino_t *l, const char *prompt) { - int verbatim = 0; + int verbatim = 0, extended = 0; /* Populate the linenoise state that we pass to functions implementing * specific editing functionalities. */ @@ -1062,6 +1062,18 @@ static int edit(lino_t *l, const char *prompt) continue; } + if (extended) { + extended = 0; + + switch (c) { + default: + generate_beep(l); + break; + } + continue; + } + + /* 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. */ @@ -1207,6 +1219,9 @@ static int edit(lino_t *l, const char *prompt) case CTL('V'): /* insert next char verbatim */ verbatim = 1; break; + case CTL('X'): + extended = 1; + continue; case CTL('K'): /* delete from current to end of line. */ l->data[l->dpos] = '\0'; l->dlen = l->dpos; -- cgit v1.2.3