Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
psql: Fix %w length in PROMPT2 when PROMPT1 contains a newline.
authorThomas Munro <tmunro@postgresql.org>
Mon, 10 Feb 2020 00:20:00 +0000 (13:20 +1300)
committerThomas Munro <tmunro@postgresql.org>
Mon, 10 Feb 2020 00:21:26 +0000 (13:21 +1300)
The width of the invisible PROMPT2 must take into account, in order
for user input to be aligned with the first line, that PROMPT1 can
contain newlines.

Author: Maxence Ahlouche
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/CAJeaomVyLSP_Wj%3D0FtYNTuoopWHyFarhUtYKDHs0HHv%2Bb%3DN9sA%40mail.gmail.com

src/bin/psql/prompt.c

index 56202bd76818886273e8ad6d3f6aaf2584a96493..26592b328725c7accd4c4a40ec0434f1bd659be9 100644 (file)
@@ -373,7 +373,10 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
                if (visible)
                {
                    chwidth = PQdsplen(p, pset.encoding);
-                   if (chwidth > 0)
+
+                   if (*p == '\n')
+                       last_prompt1_width = 0;
+                   else if (chwidth > 0)
                        last_prompt1_width += chwidth;
                }