mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
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. Reece Hart
This commit is contained in:
parent
bd046b99f0
commit
18f7a8e262
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.102 2003/12/23 23:13:14 momjian Exp $
|
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.103 2004/01/20 19:49:34 tgl Exp $
|
||||||
PostgreSQL documentation
|
PostgreSQL documentation
|
||||||
-->
|
-->
|
||||||
|
|
||||||
@ -2315,6 +2315,28 @@ testdb=> <userinput>\set content '\'' `sed -e "s/'/\\\\\\'/g" < my_file.txt` '\'
|
|||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</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;40m%]%n@%/%R%[%033[0m%#%] '
|
||||||
|
</programlisting>
|
||||||
|
results in a boldfaced (<literal>1;</literal>) yellow-on-black
|
||||||
|
(<literal>33;40</literal>) prompt on VT100-compatible, color-capable
|
||||||
|
terminals.
|
||||||
|
</para>
|
||||||
|
</listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
</variablelist>
|
</variablelist>
|
||||||
|
|
||||||
To insert a percent sign into your prompt, write
|
To insert a percent sign into your prompt, write
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.31 2003/11/29 19:52:07 pgsql Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/prompt.c,v 1.32 2004/01/20 19:49:34 tgl Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "prompt.h"
|
#include "prompt.h"
|
||||||
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "input.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -57,7 +58,9 @@
|
|||||||
* %:name: - The value of the psql variable 'name'
|
* %:name: - The value of the psql variable 'name'
|
||||||
* (those will not be rescanned for more escape sequences!)
|
* (those will not be rescanned for more escape sequences!)
|
||||||
*
|
*
|
||||||
* If the application-wide prompts became NULL somehow, the returned string
|
* %[ ... %] - tell readline that the contained text is invisible
|
||||||
|
*
|
||||||
|
* If the application-wide prompts become NULL somehow, the returned string
|
||||||
* will be empty (not NULL!).
|
* will be empty (not NULL!).
|
||||||
*--------------------------
|
*--------------------------
|
||||||
*/
|
*/
|
||||||
@ -282,10 +285,23 @@ get_prompt(promptStatus_t status)
|
|||||||
break;
|
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 marked as such,
|
||||||
|
* 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;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
buf[0] = *p;
|
buf[0] = *p;
|
||||||
buf[1] = '\0';
|
buf[1] = '\0';
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
esc = false;
|
esc = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user