From 02f786920bc437b4192fdea36d525a33e5821eae Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 9 Jul 2017 08:42:56 -0700 Subject: linenoise: replace linefeeds with CR in previous result. This fixes the issue that when a multi-line result is pasted into the edit buffer with Ctrl-X P, the line breaks appear in it as linefeeds, displayed as ^J. In linenoise, we need line breaks to be carriage returns. * linenoise/linenoise.c (lino_set_result): replace newlines with carriage returns in the given string. * linenoise/linenoise.h (lino_set_result): Add comment that function takes ownership of memory assumed to be malloced, and that it modifies it. --- linenoise/linenoise.c | 2 ++ linenoise/linenoise.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c index 41f9066c..a3c83e66 100644 --- a/linenoise/linenoise.c +++ b/linenoise/linenoise.c @@ -2621,4 +2621,6 @@ void lino_set_result(lino_t *ls, char *res) { free(ls->result); ls->result = res; + while ((res = strchr(res, '\n')) != 0) + *res = '\r'; } diff --git a/linenoise/linenoise.h b/linenoise/linenoise.h index b07b15ea..cf2ddba6 100644 --- a/linenoise/linenoise.h +++ b/linenoise/linenoise.h @@ -69,7 +69,7 @@ int lino_hist_add(lino_t *, const char *line); int lino_hist_set_max_len(lino_t *, int len); int lino_hist_save(lino_t *, const char *filename); int lino_hist_load(lino_t *, const char *filename); -void lino_set_result(lino_t *, char *); +void lino_set_result(lino_t *, char *); /* takes ownership of malloced mem; modifies it */ int lino_clear_screen(lino_t *); void lino_set_multiline(lino_t *, int ml); int lino_get_multiline(lino_t *); -- cgit v1.2.3