10

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 ↑</kbd>↑</kbd>↓</kbd>. 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 selectwhich 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?

4

2 回答 2

12

注意:我还没有找到为什么有时需要这样做的根本原因,但是,这应该可以为您解决。

在 readline/libedit (?) 中有两个字符表示不可打印字符的开始/停止,0x01 和 0x02。

因此,如果您在 PROMPT1 中的不可打印序列之前和之后添加这些,它应该可以工作。在您的情况下,结果将是:

\set PROMPT1 '%001%[%033[1;33;40m%]%002%n@%/%R%001%[%033[0m%]%002%# '

更新: 看起来这应该在 psql 中处理,但他们必须在某个地方迷路。也许USE_READLINE没有定义?请参阅:src/bin/psql/prompt.c 中的第 286 行

于 2013-10-03T09:39:40.417 回答
0
\set PROMPT1 '%001%[%033[1;32;40m%][%`hostname -i`] %002%n@%/%R%001%[%033[0m%]%002%# '

图像 - psql 提示中的颜色

于 2021-03-26T08:05:48.570 回答