diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-01-28 19:39:03 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-01-28 19:39:03 -0800 |
commit | 499708ec41e69fefdfee1f9db1bbcfbc7db5b87f (patch) | |
tree | 7902fca2260b1f03c9cc2f92e56da529b5692216 | |
parent | dc611e17c14040fa0530ed28c33919c1aa4a270e (diff) | |
download | txr-499708ec41e69fefdfee1f9db1bbcfbc7db5b87f.tar.gz txr-499708ec41e69fefdfee1f9db1bbcfbc7db5b87f.tar.bz2 txr-499708ec41e69fefdfee1f9db1bbcfbc7db5b87f.zip |
linenoise: Ctrl-V Ctrl-J now inserts CR not LF.
If newlines are inserted into the input, they don't behave
well. The is_balanced_line callback doesn't recognize them as
line terminators for the purposes of delimiting ; comments.
Also, they make a mess in the ~/.txr_history file.
Plus, users of shells like Bash are used to Ctrl-V Ctrl-J
inserting a line break; some users have that in their muscle
memory. So let's just do that as a special case: Ctrl-V Ctrl-J
behaves like Ctrl-V Ctrl-M.
* linenoise/linenoise.c (history_search, edit): Remap a
verbatim Ctrl-J to a carriage return.
-rw-r--r-- | linenoise/linenoise.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index ddb25b0f..e783a2f5 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -763,6 +763,8 @@ static int history_search(lino_t *l) verbatim: if (hl >= convert(int, nelem(hpat))) break; + if (c == CTL('J')) + c = '\r'; hpat[hl++] = c; /* fallthrough */ if (0) { @@ -2129,6 +2131,8 @@ static int edit(lino_t *l, const wchar_t *prompt) if (verbatim || (paste && c != ESC && c != BACKSPACE && c != CTL('H'))) { + if (verbatim && c == CTL('J')) + c = '\r'; if (edit_insert(l,c)) { l->error = lino_ioerr; goto out; |