Using newline or control codes in custom psql prompts corrupts display when viewing history

From: Casey Allen Shobe <casey(at)shobe(dot)info>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Using newline or control codes in custom psql prompts corrupts display when viewing history
Date: 2013-01-17 21:05:03
Message-ID: CAFmVg3iPYQsW4YHsbondATT=gi7gd_xmPj1FkxpCAv9GaQ0xWQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I'm not sure if this is a bug in psql, but it seems like it. I've ran into
similar things with a bash custom prompt, but as long as I put a newline
character in after all my custom color stuff and don't use any color
codes on the second line, this fixes the issue at a bash prompt.

For instance, for bash, I am using:

PS1="\n\e[1;32m\]\u\[\e[0;31m\](at)\e[0;32m\]\h.`dnsdomainname`\e[0;31m\]:\e[0;35m\]\w
\e[0;37m\](\`if [ \$? = 0 ]; then echo \[\e[33m\]^_^; else echo
\[\e[31m\]O_O; fi\`\e[0;37m\])\e[0m\]\n\$ "
This works with no problem, although there IS a similar problem if I put a
control character AFTER the final \n. For similar functionality within
psql, I am using:

\set PROMPT1
'\n%[%033[1;32m%]%n%[%033[0;31m%](at)%[%033[0;32m%]%M%[%033[0;31m%]:%[%033[0;33m%]%>
%[%033[0;31m%][%[%033[0;36m%]%/%[%033[0;31m%]] %[%033[0m%]\n%R%# '
\set PROMPT2 '%R%# '
(note the newline character (\n) and lack of color codes following it near
the end of each)

It looks exactly how I want, and I'm very happy with this, until I hit the
up arrow on my keyboard until hitting a history entry that's either
multiline or a single long line. At this point I see only part of the
command, as it overwrites the second prompt line and a bunch is truncated
from the beginning. If I keep going up through history a few more times,
or simply press down arrow, then the cursor moves backwards up onto the
first line maybe 50 characters to the right of the last colorized stuff.

I've attached a screenshot that attempts to show what I'm talking about.

Following this screenshot, I tried a non-colorized version of the prompt:

\set PROMPT1 '\n%n(at)%M:%> [%/] %R%# '

Unfortunately, the problem still manifested. Ultimately, I was able to
reproduce it with a \n and enough characters. I am able to reproduce the
bug with the following simple prompt:

\set PROMPT1 '\ntest prompt '

That said, it's reproducible with no newlines and only the colorization
control characters as well. Either of these as well as probably some other
special characters cause the problem.

Any advice welcome,
--
Casey Allen Shobe
casey(at)shobe(dot)info

Attachment Content-Type Size
psql_custom_prompt_bug.PNG image/png 78.6 KB

Browse pgsql-bugs by date

  From Date Subject
Next Message Kevin Grittner 2013-01-17 21:57:53 Re: BUG #7814: Rotation of the log is not carried out.
Previous Message tsunezumi 2013-01-17 11:07:05 BUG #7814: Rotation of the log is not carried out.