Re: Getting psql to redisplay command after \e

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Getting psql to redisplay command after \e
Date: 2019-11-04 00:35:25
Message-ID: 5444.1572827725@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> writes:
>> I did experiment with trying to do that, but I couldn't get it to work,
>> even with the single version of libreadline I had at hand. It appears
>> to me that readline() starts by clearing the internal buffer. Even if
>> we could persuade it to work in a particular readline version, I think
>> the odds of making it portable across all the libreadline and libedit
>> versions that are out there aren't very good. And there's definitely no
>> chance of being remotely compatible with that behavior when using the
>> bare tty drivers (psql -n).

> This suggests that readline cannot be used to edit simply a known string?
> :-( "rl_insert_text" looked promising, although probably not portable, and
> I tried to make it work without much success anyway. Maybe I'll try to
> investigate more deeply later.

I think that rl_insert_text and friends can probably only be used from
readline callback functions. So in principle maybe you could make it
work by having an rl_startup_hook that injects text if there is any
to inject. There would remain the issues of (a) is it portable across
a wide range of readline and libedit versions, (b) will the prompting
behavior be nice, and (c) do we really want this to work fundamentally
differently when readline is turned off?

(Pavel's code cited nearby seems to me to be a fine example of what
we do *not* want to do. Getting in bed with libreadline to that
extent is inevitably going to misbehave in some places.)

>> In practice, if you decide that you don't like what you're looking at,
>> you're probably going to go back into the editor to fix it, ie issue
>> another \e. So I'm not sure that it's worth such pushups to get the
>> data into readline's buffer.

> For me \e should mean edit, not edit-and-execute, so I should be back to
> prompt, which is the crux of my unease with how the feature behaves,
> because it combines two functions that IMO shouldn't.

I don't understand that complaint at all. My proposed patch does not
change the behavior to force execution, and it does display a prompt ---
one that reflects whether you've given a complete command.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2019-11-04 00:39:32 Re: let's make the list of reportable GUCs configurable (was Re: Add %r substitution for psql prompts to show recovery status)
Previous Message Thomas Munro 2019-11-03 23:29:32 Re: Parallel leader process info in EXPLAIN