psql提示中的颜色 [英] Colors in the psql prompt

查看:102
本文介绍了psql提示中的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在提示中添加颜色时,翻阅历史记录会在提示后出现垃圾。



我已经尝试了< a href = http://www.postgresql.org/docs/9.3/interactive/app-psql.html rel = noreferrer> postgres文档:

  \设置PROMPT1'%[%033 [1; 33; 40m%]%n @%/%R%[%033 [0m%]%#'

我还尝试了很多其他与Google一起找到的提示示例,但结果相同。



因此在设置提示后,我会看到一个黄色提示,如下所示:

  ulf @ mydb =#

然后我运行查询:

  ulf @ mydb =#select * from country; 

然后我用 。这会带给我更多选择线,但是我却得到:

  ulf @ mydb =#\set PROMPT1'选择*来自国家; 

请注意设置... select 之前,这是初始promt-setting的剩余部分。



如果我把在 .pslqrc

中的设置PROMPT1 命令

我在xterm和gnome-terminal中都得到了相同的结果。我的bash提示具有类似的颜色,但该提示没有问题。



我做错了什么?

解决方案

注意:我尚未找到有时为什么需要这样做的根本原因,但是,这应该为您解决。 / p>

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



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

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

更新:
看来这应该在psql中处理,但是在某些地方它们一定会丢失。也许未定义 USE_READLINE
请参阅: src / bin / psql / prompt中的286行.c


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 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?

解决方案

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

这篇关于psql提示中的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆