Re: proposal - psql - use pager for \watch command

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal - psql - use pager for \watch command
Date: 2021-03-22 21:07:07
Message-ID: CA+hUKGKP3B7-7K+RWk47xg9vT6N-o1XPbTNtF8m4r=774gLLzQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Mar 23, 2021 at 1:53 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> po 22. 3. 2021 v 13:13 odesílatel Thomas Munro <thomas(dot)munro(at)gmail(dot)com> napsal:
>> The problem is that Apple's /dev/tty device is defective, and doesn't
>> work in poll(). It always returns immediately with revents=POLLNVAL,
>> but pspg assumes that data is ready and tries to read the keyboard and
>> then blocks until I press a key. This seems to fix it:
>>
>> +#ifndef __APPLE__
>> + /* macOS can't use poll() on /dev/tty */
>> state.tty = fopen("/dev/tty", "r+");
>> +#endif
>> if (!state.tty)
>> state.tty = fopen(ttyname(fileno(stdout)), "r");
>
>
> it is hell.

Heh. I've recently spent many, many hours trying to make AIO work on
macOS, and nothing surprises me anymore. BTW I found something from
years ago on the 'net that fits with my observation about /dev/tty:

https://www.mail-archive.com/bug-gnulib(at)gnu(dot)org/msg00296.html

Curious, which other OS did you put that fallback case in for? I'm a
little confused about why it works, so I'm not sure if it's the best
possible change, but I'm not planning to dig any further now, too many
patches, not enough time :-)

> Please, can you verify this fix?

It works perfectly for me on a macOS 11.2 system with that change,
repainting the screen exactly when it should. I'm happy about that
because (1) it means I can confirm that the proposed change to psql is
working correctly on the 3 Unixes I have access to, and (2) I am sure
that a lot of Mac users will appreciate being able to use super-duper
\watch mode when this ships (a high percentage of PostgreSQL users I
know use a Mac as their client machine).

>> A minor problem is that on macOS, _GNU_SOURCE doesn't seem to imply
>> NCURSES_WIDECHAR, so I suspect Unicode will be broken unless you
>> manually add -DNCURSES_WIDECHAR=1, though I didn't check.
>
> It is possible -
>
> can you run "pspg --version"

Looks like I misunderstood: it is showing "with wide char support",
it's just that the "num" is 0 rather than 1. I'm not planning to
investigate that any further now, but I checked that it can show the
output of SELECT 'špeĉiäl chârãçtérs' correctly.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Pryzby 2021-03-22 21:13:29 Re: UPDATE ... SET (single_column) = row_constructor is a bit broken from V10 906bfcad7ba7c
Previous Message Peter Eisentraut 2021-03-22 20:58:20 Re: Since '2001-09-09 01:46:40'::timestamp microseconds are lost when extracting epoch