1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +03:00

Add psql PROMPT variable showing which line of a statement is being edited.

The new %l substitution shows the line number inside a (potentially
multi-line) statement starting from one.

Author: Sawada Masahiko, heavily editorialized by me.
Reviewed-By: Jeevan Chalke, Alvaro Herrera
This commit is contained in:
Andres Freund
2014-09-02 13:05:48 +02:00
parent bd3b7a9eef
commit 51bb79569f
5 changed files with 47 additions and 6 deletions

View File

@ -517,8 +517,8 @@ bool
handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
{
bool OK;
const char *prompt;
char buf[COPYBUFSIZ];
bool showprompt = false;
/*
* Establish longjmp destination for exiting from wait-for-input. (This is
@ -540,21 +540,20 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
/* Prompt if interactive input */
if (isatty(fileno(copystream)))
{
showprompt = true;
if (!pset.quiet)
puts(_("Enter data to be copied followed by a newline.\n"
"End with a backslash and a period on a line by itself."));
prompt = get_prompt(PROMPT_COPY);
}
else
prompt = NULL;
OK = true;
if (isbinary)
{
/* interactive input probably silly, but give one prompt anyway */
if (prompt)
if (showprompt)
{
const char *prompt = get_prompt(PROMPT_COPY);
fputs(prompt, stdout);
fflush(stdout);
}
@ -589,8 +588,9 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
bool firstload;
bool linedone;
if (prompt)
if (showprompt)
{
const char *prompt = get_prompt(PROMPT_COPY);
fputs(prompt, stdout);
fflush(stdout);
}
@ -650,7 +650,10 @@ handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
}
if (copystream == pset.cur_cmd_source)
{
pset.lineno++;
pset.stmt_lineno++;
}
}
}