I get an trash after the prompt when I flick through the history when I add colors to my prompt.
I have tried the proposed color prompt command from the postgres doc:
\set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '
I have also tried a lot of other prompt examples that i found with google but with the same result.
So after setting the prompt I have a yellow prompt something like this:
ulf@mydb=#
I then run the query:
ulf@mydb=# select * from country;
Then I flick through the history with ↑↑↓. This would bring me the select-line ones more, but instead I get:
ulf@mydb=# \set PROMPT1 'select * from country;
Note the \set...
before the select
which is a remnant from the initial promt-setting.
I also get similar result if I put the \set PROMPT1
-command in .pslqrc
I get the same result in both xterm and gnome-terminal. I have my bash-prompt colored in a similar way but I have no problems with that prompt.
What have I done wrong?
psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. Alternatively, input can be from a file or from command line arguments.
psql is a PostgreSQL interactive console, or a terminal-based front-end to PostgreSQL. It allows you to write queries in SQL syntax, issue those queries to a PostgreSQL database, and see the results of those queries in the terminal window.
Note: I have yet to find the root cause of why this is necessary sometimes, however, this should fix it for you.
There are two characters to indicate start/stop of non-printable characters in readline/libedit (?), 0x01 and 0x02.
So, if you add these before and after the non-printable sequences in your PROMPT1, it should work. The result in your case would be:
\set PROMPT1 '%001%[%033[1;33;40m%]%002%n@%/%R%001%[%033[0m%]%002%# '
Update:
It would seem this should be handled in psql though, somewhere they must get lost some how. Maybe USE_READLINE
isn't defined?
See: Line 286 in src/bin/psql/prompt.c
\set PROMPT1 '%001%[%033[1;32;40m%][%`hostname -i`] %002%n@%/%R%001%[%033[0m%]%002%# '
Image - colours in psql prompt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With