diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-05 20:30:43 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-05 20:30:43 -0700 |
commit | 2caaa995b0af3b2dc65c6ae187d24fb92d9798a6 (patch) | |
tree | e1dc22585cf94818ab442de47b5ef18dd32de64d /linenoise/linenoise.c | |
parent | 80c3ddd09b310c6473063d1c7c9511476b3b810a (diff) | |
download | txr-2caaa995b0af3b2dc65c6ae187d24fb92d9798a6.tar.gz txr-2caaa995b0af3b2dc65c6ae187d24fb92d9798a6.tar.bz2 txr-2caaa995b0af3b2dc65c6ae187d24fb92d9798a6.zip |
linenoise: Ctrl-V verbatim insert.
* linenoise/linenoise.c (enum key_action): New enum
constant, CTRL_V.
(edit): Implement Ctrl-V.
Diffstat (limited to 'linenoise/linenoise.c')
-rw-r--r-- | linenoise/linenoise.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index b43a15a0..b94a9a6d 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -171,6 +171,7 @@ enum key_action { CTRL_P = 16, CTRL_T = 20, CTRL_U = 21, + CTRL_V = 22, CTRL_W = 23, ESC = 27, BACKSPACE = 127 @@ -777,6 +778,8 @@ static void edit_delete_prev_word(struct lino_state *l) { * The function returns the length of the current buffer. */ static int edit(lino_t *l, const char *prompt) { + int verbatim = 0; + /* Populate the linenoise state that we pass to functions implementing * specific editing functionalities. */ l->prompt = prompt; @@ -804,6 +807,12 @@ static int edit(lino_t *l, const char *prompt) if (nread <= 0) return l->len ? (int) l->len : -1; + if (verbatim) { + if (edit_insert(l,c)) return -1; + verbatim = 0; + 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. */ @@ -928,6 +937,9 @@ static int edit(lino_t *l, const char *prompt) l->dpos = l->dlen = 0; refresh_line(l); break; + case CTRL_V: /* insert next char verbatim */ + verbatim = 1; + break; case CTRL_K: /* delete from current to end of line. */ l->data[l->dpos] = '\0'; l->dlen = l->dpos; |