diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-12-31 05:30:46 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-12-31 05:30:46 -0800 |
commit | 51322f6c66d153d2f008a227c5e517f6fb34dbab (patch) | |
tree | e1df325a64c7c570e72f0dec8e7f2c765fc2b7b2 /linenoise | |
parent | de3c3e1d083d4fde847505b4626467e2cb8d4cd6 (diff) | |
download | txr-51322f6c66d153d2f008a227c5e517f6fb34dbab.tar.gz txr-51322f6c66d153d2f008a227c5e517f6fb34dbab.tar.bz2 txr-51322f6c66d153d2f008a227c5e517f6fb34dbab.zip |
linenoise: submit and stay in history.
* linenoise/linenoise.c (struct lino_state): New member
save_hist_idx.
(edit): If save_hist_idx is set, jump to that history position
and clear it. Handle ENTER in extended (Ctrl-X) mode
similarly to regular ENTER, but setting save_hist_idx.
* txr.1: Documented.
Diffstat (limited to 'linenoise')
-rw-r--r-- | linenoise/linenoise.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 93f4bf6c..1dd7577d 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -89,6 +89,7 @@ struct lino_state { char *clip; /* Selection */ int ifd; /* Terminal stdin file descriptor. */ int ofd; /* Terminal stdout file descriptor. */ + int save_hist_idx; /* Jump to history position on entry into edit */ /* Volatile state pertaining to just one linenoise call */ char buf[LINENOISE_MAX_DISP]; /* Displayed line bufer. */ @@ -1676,6 +1677,16 @@ static int edit(lino_t *l, const char *prompt) l->error = lino_ioerr; return ret; } + + if (l->save_hist_idx) { + int hi = l->history_len - l->save_hist_idx - 1; + l->history_index = l->save_hist_idx; + l->save_hist_idx = 0; + strcpy(l->data, l->history[hi]); + l->dpos = l->dlen = strlen(l->data); + l->need_refresh = 1; + } + while(1) { unsigned char byte; int c; @@ -1814,6 +1825,14 @@ static int edit(lino_t *l, const char *prompt) clear_sel(l); } break; + case ENTER: + if (l->mlmode) + edit_move_end(l); + if (l->need_refresh) + refresh_line(l); + ret = l->len; + l->save_hist_idx = l->history_index; + goto out; default: if (isdigit((unsigned char) c)) { if (extend_num < 0) |