summaryrefslogtreecommitdiffstats
path: root/linenoise
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-01-28 19:30:50 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-01-28 19:30:50 -0800
commitdc611e17c14040fa0530ed28c33919c1aa4a270e (patch)
tree7c232a185742b2e052471abd4f27f2fc0cf255be /linenoise
parentcc413849fc0b92fee3c33ffd16378ca6ffa1070d (diff)
downloadtxr-dc611e17c14040fa0530ed28c33919c1aa4a270e.tar.gz
txr-dc611e17c14040fa0530ed28c33919c1aa4a270e.tar.bz2
txr-dc611e17c14040fa0530ed28c33919c1aa4a270e.zip
repl: bug handling comments in plain mode.
The is_balanced_line function assumes that comments are terminated by a carriage return, whic his the multi-line convention used by the interactive repl. The plain-mode listener, though, only replaces newlines by carriage returns when returning the complete multi-line input. When invoking the is_balanced_line callback, the newlines are still there, and so comments are not handled properly. Reported by Paul. A. Patience. * linenoise/linenoise.c (linenoise): In plain mode, replace the trailing newline with a carriage return after every physical line input, before that line is passed to the lino->enter_callback (i.e. is_balanced_line). The code to replace newlines with carriage returns at the end is consequently no longer required.
Diffstat (limited to 'linenoise')
-rw-r--r--linenoise/linenoise.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index e8686066..ddb25b0f 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -2581,7 +2581,7 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt)
if (plain) {
wchar_t *ret = 0;
- size_t len = 0, i;
+ size_t len = 0;
const wchar_t *condensed_prompt = prompt + wcslen(prompt);
int show_prompt = ls->show_prompt || (noninteractive && isatty(ifd));
@@ -2616,6 +2616,9 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt)
wmemcpy(nret + len, ls->data, nlen + 1);
ret = nret;
len = len + nlen;
+
+ if (len && ret[len-1] == '\n')
+ ret[len-1] = '\r';
}
if (!ls->enter_callback || ls->enter_callback(ret, ls->ce_ctx))
@@ -2625,11 +2628,6 @@ wchar_t *linenoise(lino_t *ls, const wchar_t *prompt)
if (ret != 0) {
if (len && ret[len - 1] == '\n')
ret[len-1] = '\0';
-
- for (i = 0; i < len; i++) {
- if (ret[i] == '\n')
- ret[i] = '\r';
- }
}
return ret;