Proposal: psql force prompting on notty

Lists: pgsql-hackerspgsql-patches
From: Michael Mauger <mmaug(at)yahoo(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Proposal: psql force prompting on notty
Date: 2003-11-01 06:51:44
Message-ID: 20031101065144.28680.qmail@web60305.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

I'm the maintainer of sql.el in GNU Emacs. On both the Mac OS X
and the Windows/Cygwin platform we've had reports that psql run
under Emacs does not issue a prompt for commands.

I did a little research and it appears that the cause is that
pset.notty is being set to false because stdin/stdout are not
a tty (pgsql-server/src/bin/psql/startup.c). I'd like to
propose that an option be added to the psql command line to
override the detection of the tty and force the prompting for
commands on stdin.

I believe the attached patch should add the option -I to psql
and force the prompt to appear as if it were an interactive
session regardless of the state of stdin/stdout. I do not
have a configuration available to properly test this however.

Please be sure to include me in any replies since I do not
subscribe to this list. TIA.

-- Michael

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

Attachment Content-Type Size
interactive.diff text/plain 1.6 KB

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Michael Mauger <mmaug(at)yahoo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Proposal: psql force prompting on notty
Date: 2003-11-01 18:21:08
Message-ID: Pine.LNX.4.44.0311011920430.1528-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Michael Mauger writes:

> I'm the maintainer of sql.el in GNU Emacs. On both the Mac OS X
> and the Windows/Cygwin platform we've had reports that psql run
> under Emacs does not issue a prompt for commands.

Why can't you make the Emacs session behave like a terminal for psql?

--
Peter Eisentraut peter_e(at)gmx(dot)net


From: Michael Mauger <mmaug(at)yahoo(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Proposal: psql force prompting on notty
Date: 2003-11-01 20:52:44
Message-ID: 20031101205244.89503.qmail@web60303.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

--- Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> Michael Mauger writes:
>
> > I'm the maintainer of sql.el in GNU Emacs. On both the Mac OS X
> > and the Windows/Cygwin platform we've had reports that psql run
> > under Emacs does not issue a prompt for commands.
>
> Why can't you make the Emacs session behave like a terminal for psql?
>

Discussion on emacs-devel indicates that there are some known issues with
pty support on the Mac OS X port which are being addressed. The problem
however does still exist on the Windows platform.

Emacs is not a Cygwin (Un*x emulation on Windows) executable (like psql
is) so it is not setting the psql process up in a way that cygwin
recognizes as being a pty-like environment. Thus the isatty() on stdin
and stdout are returning false when run under Emacs.

My proposed patch is small and overrides psql's detection of it's
environment when the user knows better.

-- Michael

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Michael Mauger <mmaug(at)yahoo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Proposal: psql force prompting on notty
Date: 2003-11-01 21:34:26
Message-ID: Pine.LNX.4.44.0311012233570.1528-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Michael Mauger writes:

> Emacs is not a Cygwin (Un*x emulation on Windows) executable (like psql
> is)

Why don't you use the native Windows version of psql?

--
Peter Eisentraut peter_e(at)gmx(dot)net


From: Michael Mauger <mmaug(at)yahoo(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Proposal: psql force prompting on notty
Date: 2003-11-02 01:36:56
Message-ID: 20031102013656.15069.qmail@web60309.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

--- Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> Michael Mauger writes:
>
> > Emacs is not a Cygwin (Un*x emulation on Windows) executable (like
> > psql is)
>
> Why don't you use the native Windows version of psql?
>

The Cygwin setup program makes pre-built binaries of postgres readily
available on Windows. (In fact, using this version is encouraged in the
Postgres for Windows installation notes.) A native Windows version would
not work either since the isatty() implementation there will only
recognize a Command Prompt window as a tty.

-- Michael

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Michael Mauger <mmaug(at)yahoo(dot)com>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Proposal: psql force prompting on notty
Date: 2003-11-11 00:48:02
Message-ID: 200311110048.hAB0m2N11510@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


This is an unusual one. The OS isn't handling things properly, and we
have to work around that. Can you get a Win32 user to test psql with
this patch to make sure it actually fixes the problem and behaves as
expected? If you want me to produce a psql binary, I can do that.

Thanks.

---------------------------------------------------------------------------

Michael Mauger wrote:
> I'm the maintainer of sql.el in GNU Emacs. On both the Mac OS X
> and the Windows/Cygwin platform we've had reports that psql run
> under Emacs does not issue a prompt for commands.
>
> I did a little research and it appears that the cause is that
> pset.notty is being set to false because stdin/stdout are not
> a tty (pgsql-server/src/bin/psql/startup.c). I'd like to
> propose that an option be added to the psql command line to
> override the detection of the tty and force the prompting for
> commands on stdin.
>
> I believe the attached patch should add the option -I to psql
> and force the prompt to appear as if it were an interactive
> session regardless of the state of stdin/stdout. I do not
> have a configuration available to properly test this however.
>
> Please be sure to include me in any replies since I do not
> subscribe to this list. TIA.
>
> -- Michael
>
> __________________________________
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
> http://sitebuilder.yahoo.com

Content-Description: interactive.diff

> --- pgsql-server/src/bin/psql/startup.c 29 Sep 2003 18:21:33 -0000 1.80
> +++ pgsql-server/src/bin/psql/startup.c 01 Nov 2003 06:10:42 -0000
> @@ -322,6 +322,7 @@
> {"field-separator", required_argument, NULL, 'F'},
> {"host", required_argument, NULL, 'h'},
> {"html", no_argument, NULL, 'H'},
> + {"interactive", no_argument, NULL, 'I'},
> {"list", no_argument, NULL, 'l'},
> {"no-readline", no_argument, NULL, 'n'},
> {"output", required_argument, NULL, 'o'},
> @@ -352,7 +353,7 @@
>
> memset(options, 0, sizeof *options);
>
> - while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:Hlno:p:P:qR:sStT:uU:v:VWxX?",
> + while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:HlMno:p:P:qR:sStT:uU:v:VWxX?",
> long_options, &optindex)) != -1)
> {
> switch (c)
> @@ -395,7 +396,10 @@
> case 'H':
> pset.popt.topt.format = PRINT_HTML;
> break;
> + case 'I':
> + pset.notty = 0;
> + break;
> case 'l':
> options->action = ACT_LIST_DB;
> break;
> --- pgsql-server/src/bin/psql/help.c 02 Oct 2003 06:39:31 -0000 1.81
> +++ pgsql-server/src/bin/psql/help.c 01 Nov 2003 06:29:50 -0000
> @@ -103,6 +103,7 @@
> puts(_(" -a echo all input from script"));
> puts(_(" -e echo commands sent to server"));
> puts(_(" -E display queries that internal commands generate"));
> + puts(_(" -I force interactive prompting for input"));
> puts(_(" -q run quietly (no messages, only query output)"));
> puts(_(" -o FILENAME send query results to file (or |pipe)"));
> puts(_(" -n disable enhanced command line editing (readline)"));

>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Michael Mauger <mmaug(at)yahoo(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] Proposal: psql force prompting on notty
Date: 2003-11-11 01:58:40
Message-ID: 20031111015840.59438.qmail@web60307.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

You can send it to me to test. I've duplicated the reported behavior
here so I can test the fix. (Ideally, send me a url to downloaded it
from rather than attaching it.)

Just a thought, a corresponding option of --batch/-B could be added to do
the opposite of the --interactive/-I option. Having options to override
dynamically detected configuration is not all that uncommon.

Thanks.

-- Michael

PS. Beware of the first patch I sent -- it had a bug in the string sent
to getopt. It had an option "M" rather than "I". The second patch was
corrected.

--- Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> wrote:
>
> This is an unusual one. The OS isn't handling things properly, and we
> have to work around that. Can you get a Win32 user to test psql with
> this patch to make sure it actually fixes the problem and behaves as
> expected? If you want me to produce a psql binary, I can do that.
>
> Thanks.
>
>
---------------------------------------------------------------------------
>
> Michael Mauger wrote:
> > I'm the maintainer of sql.el in GNU Emacs. On both the Mac OS X
> > and the Windows/Cygwin platform we've had reports that psql run
> > under Emacs does not issue a prompt for commands.
> >
> > I did a little research and it appears that the cause is that
> > pset.notty is being set to false because stdin/stdout are not
> > a tty (pgsql-server/src/bin/psql/startup.c). I'd like to
> > propose that an option be added to the psql command line to
> > override the detection of the tty and force the prompting for
> > commands on stdin.
> >
> > I believe the attached patch should add the option -I to psql
> > and force the prompt to appear as if it were an interactive
> > session regardless of the state of stdin/stdout. I do not
> > have a configuration available to properly test this however.
> >
> > Please be sure to include me in any replies since I do not
> > subscribe to this list. TIA.
> >

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree