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

Поиск
Список
Период
Сортировка
От Casey Allen Shobe
Тема Using newline or control codes in custom psql prompts corrupts display when viewing history
Дата
Msg-id CAFmVg3iPYQsW4YHsbondATT=gi7gd_xmPj1FkxpCAv9GaQ0xWQ@mail.gmail.com
обсуждение исходный текст
Список 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\]@\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%]@%[%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@%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@shobe.info


Вложения

В списке pgsql-bugs по дате отправления:

Предыдущее
От: bricklen
Дата:
Сообщение: Re: BUG #7814: Rotation of the log is not carried out.
Следующее
От: giomac@gmail.com
Дата:
Сообщение: BUG #7815: Upgrading PostgreSQL from 9.1 to 9.2 with pg_upgrade/postgreql-setup fails - invalid status retrieve