BUG #11028: psql doesn't use 0x01 and 0x02 to inform readline of non-printable PROMPT1 chars

Started by Robert Flemingover 11 years ago5 messagesbugs
Jump to latest
#1Robert Fleming
fleminra@gmail.com

The following bug has been logged on the website:

Bug reference: 11028
Logged by: Robert Fleming
Email address: fleminra@gmail.com
PostgreSQL version: 9.3.4
Operating system: Ubuntu 14.04
Description:

See http://stackoverflow.com/questions/19139330/

Basically, the colorized prompt suggested in
http://www.postgresql.org/docs/9.3/static/app-psql.html#APP-PSQL-PROMPTING
:

testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '

results in strange readline behavior. In that prompt, "%[" should be
preceded by "%001" and "%]" should be followed by "%002".

It seems to me that either psql should do this automatically, or
http://www.postgresql.org/docs/9.3/static/app-psql.html#APP-PSQL-PROMPTING
should be updated to use "%001" and "%002".

Thanks!

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Fleming (#1)
Re: BUG #11028: psql doesn't use 0x01 and 0x02 to inform readline of non-printable PROMPT1 chars

fleminra@gmail.com writes:

Basically, the colorized prompt suggested in
http://www.postgresql.org/docs/9.3/static/app-psql.html#APP-PSQL-PROMPTING
:

testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '

results in strange readline behavior. In that prompt, "%[" should be
preceded by "%001" and "%]" should be followed by "%002".

Actually, %[ is supposed to expand to \001 and %] is supposed to expand
to \002.

The example seems to work as given for me. Could you be more specific
about what's going wrong for you? Also, are you sure you are really
using GNU readline, and not something else like libedit?

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#3Robert Fleming
fleminra@gmail.com
In reply to: Tom Lane (#2)
Re: BUG #11028: psql doesn't use 0x01 and 0x02 to inform readline of non-printable PROMPT1 chars

Yes, sorry, actually it's using libedit. Is that supported?

Here is a video of what I'm seeing:
https://app.box.com/s/dj2hzo6tuny2os16t3rd
(This OGV file plays better in VLC than mplayer for me.)

On Wed, Jul 23, 2014 at 12:12 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Show quoted text

fleminra@gmail.com writes:

Basically, the colorized prompt suggested in

http://www.postgresql.org/docs/9.3/static/app-psql.html#APP-PSQL-PROMPTING

:

testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# '

results in strange readline behavior. In that prompt, "%[" should be
preceded by "%001" and "%]" should be followed by "%002".

Actually, %[ is supposed to expand to \001 and %] is supposed to expand
to \002.

The example seems to work as given for me. Could you be more specific
about what's going wrong for you? Also, are you sure you are really
using GNU readline, and not something else like libedit?

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Fleming (#3)
Re: BUG #11028: psql doesn't use 0x01 and 0x02 to inform readline of non-printable PROMPT1 chars

Robert Fleming <fleminra@gmail.com> writes:

Yes, sorry, actually it's using libedit. Is that supported?

Ah. We support libedit, but I'd not be a bit surprised if it does not
cope well with non-printing characters ...

A quick look into the readline.h supplied on my Mac OS X 10.9 machine
(which is from libedit not GNU readline) says that it defines
RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE, so at least in theory
you'd expect it to work. A bit of experimentation says that it doesn't
work all that well though compared to my Linux box :-(. Now, Apple has a
long track record of shipping broken versions of libedit, so this doesn't
prove a whole lot about what will happen on other platforms.

I'd make sure that PG was compiled against a version of readline.h that
provided definitions for RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE.
If it was, then whatever misbehavior you're seeing can be blamed on
libedit. If you're using an old version of libedit it's possible that a
newer one would work better. But really, libedit is full of inadequacies;
if you can possibly switch to GNU readline you'll probably be happier.

regards, tom lane

--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

#5Robert Fleming
fleminra@gmail.com
In reply to: Tom Lane (#4)
Re: BUG #11028: psql doesn't use 0x01 and 0x02 to inform readline of non-printable PROMPT1 chars

I just switched/updated to the PostgreSQL packages from apt.postgresql.org
(instead of Ubuntu's own packages) and now all is working as advertised.

I had done some debugging in psql/prompt.c and indeed the
RL_PROMPT_START_IGNORE section was executing. So I never quite got to the
bottom of it, but am content to just to run with the updated packages.

Thanks for your help.
Robert