summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-23 16:21:24 -0500
committerJune McEnroe <june@causal.agency>2022-01-21 22:04:33 -0500
commit1a3bc6209c60bea2a26b0ed69628308f1e59ab32 (patch)
treeb87e8a05abf4476500b75c6e4ee5a04c18d984e2 /src
parentdash: Add RPS1 and RPS2 right prompt variables (diff)
downloaddash-1a3bc6209c60bea2a26b0ed69628308f1e59ab32.tar.gz
dash-1a3bc6209c60bea2a26b0ed69628308f1e59ab32.zip
dash: 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 '')
-rw-r--r--src/parser.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/parser.c b/src/parser.c
index 444fa08..985b51d 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1601,7 +1601,7 @@ STATIC void
 setprompt(int which)
 {
 	struct stackmark smark;
-	const char *prompt, *rprompt;
+	const char *prompt, *rprompt, *nl;
 	int show;
 
 	needprompt = 0;
@@ -1641,6 +1641,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);
 }
@@ -1651,7 +1655,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 *