summary refs log tree commit diff
path: root/bin/dash
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-23 16:21:24 -0500
committerJune McEnroe <june@causal.agency>2020-12-23 16:21:24 -0500
commit115d9322b60a86a2df6965ceebc10f8c388a97b3 (patch)
tree908f13616762657bb6ae7808331289b7ea94cef9 /bin/dash
parentAdd RPS1 and RPS2 right prompt variables (diff)
downloadsrc-115d9322b60a86a2df6965ceebc10f8c388a97b3.tar.gz
src-115d9322b60a86a2df6965ceebc10f8c388a97b3.zip
Fix multi-line prompts when right prompts are used
editline does not render a multi-line PS1 correctly when RPS1 is also
set. To work around this, return only the last line of the cached prompt
to editline, and print the leading lines separately inside setprompt.
Diffstat (limited to 'bin/dash')
-rw-r--r--bin/dash/src/parser.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/bin/dash/src/parser.c b/bin/dash/src/parser.c
index 21052c21..499f7f8e 100644
--- a/bin/dash/src/parser.c
+++ b/bin/dash/src/parser.c
@@ -1598,7 +1598,7 @@ STATIC void
 setprompt(int which)
 {
 	struct stackmark smark;
-	const char *prompt, *rprompt;
+	const char *prompt, *rprompt, *nl;
 	int show;
 
 	needprompt = 0;
@@ -1638,6 +1638,10 @@ setprompt(int which)
 		free(rpromptcache);
 		promptcache = savestr(expandstr(prompt));
 		rpromptcache = savestr(expandstr(rprompt));
+
+		nl = strrchr(promptcache, '\n');
+		if (nl)
+			outmem(promptcache, &nl[1] - promptcache, out2);
 	}
 	popstackmark(&smark);
 }
@@ -1648,7 +1652,14 @@ setprompt(int which)
 const char *
 getprompt(void *unused)
 {
-	return promptcache;
+	const char *nl;
+
+	nl = strrchr(promptcache, '\n');
+
+	if (nl)
+		return &nl[1];
+	else
+		return promptcache;
 }
 
 const char *