psql prompts with invisible characters - Mailing list pgsql-patches
From | Reece Hart |
---|---|
Subject | psql prompts with invisible characters |
Date | |
Msg-id | 1074279504.5426.33.camel@tallac Whole thread Raw |
Responses |
Re: psql prompts with invisible characters
Re: psql prompts with invisible characters Re: psql prompts with invisible characters |
List | pgsql-patches |
Okay, Tom, here's take II. warning: I've handchecked the sgml, but the doc tools I've got installed die when I make man within doc/src/sgml. Specifically: Unknown SDATA: [pi ] at /usr/share/sgml/docbook/utils-0.6.12/helpers/docbook2man-spec.pl line 1240, <STDIN> line 108418. I get this on an unmodified 7.4.1 tree as well, so I presume it's because I've got an incompatible version of docbook2man-spec.pl . Tips? -Reece # add support for prompts with invisible characters to psql # # This patch adds support for readline prompts which contain non-printing # characters as for colorized prompts or terminal title changes. This was # nearly a direct lift from bash-2.05b's lib/readline/display.c, per # guidance from Chet Ramey. diff -ru --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.4.1-orig/doc/src/sgml/ref/psql-ref.sgml postgresql-7.4.1/doc/src/sgml/ref/psql-ref.sgml --- postgresql-7.4.1-orig/doc/src/sgml/ref/psql-ref.sgml 2003-10-31 17:56:29.000000000 -0800 +++ postgresql-7.4.1/doc/src/sgml/ref/psql-ref.sgml 2004-01-16 09:56:54.000000000 -0800 @@ -2236,6 +2236,30 @@ </varlistentry> <varlistentry> + <term><literal>%[</literal> ... <literal>%]</literal></term> + <listitem> + <para> + Prompts may contain terminal control characters which, for + example, change the foreground, background, or style of the prompt + text, or change the title of the terminal window. In order for + the line editing features of readline to work properly, these + non-printing control characters must be designated as invisible + by surrounding them with <literal>%[</literal> and + <literal>%]</literal>. Multiple pairs of these may occur within + the prompt. For example, +<programlisting> +testdb=> <userinput>\set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%#%] '</userinput> +</programlisting> + results in a boldfaced (<literal>1;</literal>) yellow-on-black + <literal>33;40</literal> prompt for color-capable terminals. + See <ulink + url="http://www.termsys.demon.co.uk/vtansi.htm">http://www.termsys.demon.co.uk/vtansi.htm</a> + for an example of allowable codes. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><literal>%R</literal></term> <listitem> <para> diff -ru --exclude='*.rej' --exclude='*.o' --exclude='*.orig' postgresql-7.4.1-orig/src/bin/psql/prompt.c postgresql-7.4.1/src/bin/psql/prompt.c --- postgresql-7.4.1-orig/src/bin/psql/prompt.c 2003-10-03 18:04:46.000000000 -0700 +++ postgresql-7.4.1/src/bin/psql/prompt.c 2004-01-15 17:15:41.000000000 -0800 @@ -13,6 +13,7 @@ #include "settings.h" #include "common.h" #include "variables.h" +#include "input.h" #ifdef WIN32 #include <io.h> @@ -241,6 +242,20 @@ buf[0] = '>'; break; + case '[': + case ']': +#if defined (USE_READLINE) + buf[0] = '\001'; + buf[1] = (*p == '[') ? RL_PROMPT_START_IGNORE : RL_PROMPT_END_IGNORE; + buf[2] = '\0'; +#else + /* Should we remove text between %[ and %] + e.g., for fancy prompts on dumb terminals ? + If so, under what conditions? */ +#endif /* USE_READLINE */ + break; + /* end case [ or ] */ + /* execute command */ case '`': { -- Reece Hart, http://www.in-machina.com/~reece/, GPG:0x25EC91A0
pgsql-patches by date: