Tom-

Here's take III of the patch, with the #ifdef for RL_PROMPT_START_IGNORE, the #else chopped, and made with diff -c against 7.4.1. A brief comment seemed warranted since this is an undocumented readline feature.

Note that the #if is:
#if defined (USE_READLINE) && defined (RL_PROMPT_START_IGNORE)
Although this is pedantic (R_P_S_I implies U_R), it seemed more transparent for those who come this way hence. Do as you like with it.

Fini?

-Reece

-- 
Reece Hart, http://www.in-machina.com/~reece/, GPG:0x25EC91A0
# patch for fancy (e.g., colored) prompts in psql, take III
# 
# This is a patch to support readline prompts which contain non-printing
# characters, as for fancy colorized prompts.  This was nearly a direct
# lift from bash-2.05b's lib/readline/display.c, per guidance from Chet Ramey.
#
# Usage:
# Invisible characters within the prompt must be quoted with %[ and %].
# example: \set PROMPT1 '%[%033[1;[EMAIL PROTECTED]/%R%[%033[0m%]%# '
# 
diff -r --exclude='*.rej' --exclude='*.log' --exclude='*.so' --exclude='*.o' 
--exclude='*.orig' -c 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,2241 ****
--- 2236,2265 ----
        </varlistentry>
  
        <varlistentry>
+         <term><literal>%[</literal> ... <literal>%]</literal></term>
+       <listitem>
+          <para>
+                Prompts may contain terminal control characters which, for
+                example, change the color, 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=> \set PROMPT1 '%[%033[1;33;[EMAIL PROTECTED]/%R%[%033[0m%#%] '
+ </programlisting>
+                results in a boldfaced (<literal>1;</literal>) yellow-on-black
+                <literal>33;40</literal> prompt (within 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 -r --exclude='*.rej' --exclude='*.log' --exclude='*.so' --exclude='*.o' 
--exclude='*.orig' -c 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-20 09:33:23.000000000 -0800
***************
*** 13,18 ****
--- 13,19 ----
  #include "settings.h"
  #include "common.h"
  #include "variables.h"
+ #include "input.h"
  
  #ifdef WIN32
  #include <io.h>
***************
*** 241,246 ****
--- 242,259 ----
                                                buf[0] = '>';
                                        break;
  
+                           case '[':
+                           case ']':
+ #if defined (USE_READLINE) && defined (RL_PROMPT_START_IGNORE)
+                                 /* readline >=4.0 undocumented feature: non-printing
+                                        characters in prompt strings must be quoted 
in order
+                                        to properly display the line during editing.
+                                 */
+                                 buf[0] = '\001';
+                                 buf[1] = (*p == '[') ? RL_PROMPT_START_IGNORE : 
RL_PROMPT_END_IGNORE;
+ #endif /* USE_READLINE */
+                                 break;
+                                       
                                        /* execute command */
                                case '`':
                                        {
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to