From 0eed0b1cbcf301c594020fb4bbe9a39c3f94a8a6 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 20 Sep 2015 18:56:07 -0700 Subject: linenoise: move to end in mlmode on Ctrl-C, Ctrl-Z. If we don't move the cursor to the end, then the shell prompt (Ctrl-Z) or next REPL prompt (Ctrl-C) comes in the middle of the previous input. * linenoise/linenoise.c (edit): in multi-line mode, move to end of input on Ctrl-C. On Ctrl-Z suspend, do the same, but save and restore the position. --- linenoise/linenoise.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 0464bf9d..f62a97d8 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -1557,6 +1557,11 @@ static int edit(lino_t *l, const char *prompt) record_undo(l); return (int)l->len; case CTL('C'): + if (l->mlmode) { + edit_move_end(l); + if (l->need_refresh) + refresh_line(l); + } record_undo(l); l->error = lino_intr; return -1; @@ -1727,10 +1732,18 @@ static int edit(lino_t *l, const char *prompt) l->need_refresh = 1; break; case CTL('Z'): - disable_raw_mode(l); - raise(SIGTSTP); - enable_raw_mode(l); - l->need_refresh = 1; + { + size_t dpos = l->dpos; + if (l->mlmode) + edit_move_end(l); + if (l->need_refresh) + refresh_line(l); + disable_raw_mode(l); + raise(SIGTSTP); + enable_raw_mode(l); + l->dpos = dpos; + l->need_refresh = 1; + } break; case CTL('O'): restore_undo(l); -- cgit v1.2.3