Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "off by one fix in multiple prompts" breaks multiline prompt



On 13 Aug 2018, at 09:19, dana <dana@xxxxxxx> wrote:
>Looking at that function again, i wonder if the original problem was actually
>related to the fact that it compares the current column count (and
>potentially increments the height) before checking whether the current character
>is a new-line?

I think that was in fact the problem. So if we revert the previous change, and
then add an additional check for a last-column new-line, we end up with
something like the attached. This seems to fix both the original issue and the
new one for me, but obviously further testing would be nice

dana


diff --git a/Src/prompt.c b/Src/prompt.c
index 959ed8e3d..1a3765407 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -1074,10 +1074,10 @@ putstr(int d)
 mod_export void
 countprompt(char *str, int *wp, int *hp, int overf)
 {
-    int w = 0, h = 1;
+    int w = 0, h = 1, multi = 0;
     int s = 1;
 #ifdef MULTIBYTE_SUPPORT
-    int wcw, multi = 0;
+    int wcw;
     char inchar;
     mbstate_t mbs;
     wchar_t wc;
@@ -1086,7 +1086,12 @@ countprompt(char *str, int *wp, int *hp, int overf)
 #endif
 
     for (; *str; str++) {
-	if (w > zterm_columns && overf >= 0) {
+	/*
+	 * Avoid double-incrementing the height when there's a newline in the
+	 * prompt and the line it terminates takes up exactly the width of the
+	 * terminal
+	 */
+	if (w >= zterm_columns && overf >= 0 && !multi && *str != '\n') {
 	    w = 0;
 	    h++;
 	}



Messages sorted by: Reverse Date, Date, Thread, Author