summaryrefslogtreecommitdiffstats
path: root/linenoise/linenoise.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-09-16 20:29:31 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-09-16 20:29:31 -0700
commitd8257ec1f490f80b5d168def3cb4e36d969fe526 (patch)
treee1b205a96e6269381cfab479c8a65a14f001c330 /linenoise/linenoise.c
parent49a8cbbca600bb587216cb6b114c4fef2f762e99 (diff)
downloadtxr-d8257ec1f490f80b5d168def3cb4e36d969fe526.tar.gz
txr-d8257ec1f490f80b5d168def3cb4e36d969fe526.tar.bz2
txr-d8257ec1f490f80b5d168def3cb4e36d969fe526.zip
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.
Diffstat (limited to 'linenoise/linenoise.c')
-rw-r--r--linenoise/linenoise.c17
1 files changed, 16 insertions, 1 deletions
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;