diff options
| author | Andres Freund <andres@anarazel.de> | 2014-09-02 13:05:48 +0200 |
|---|---|---|
| committer | Andres Freund <andres@anarazel.de> | 2014-09-02 13:06:11 +0200 |
| commit | 51bb79569f934ad2135c2ff859c61b9ab8d51750 (patch) | |
| tree | 3dc8d93438ee68238f1229ed16e37f4f5198ba3a /src/bin/psql/copy.c | |
| parent | bd3b7a9eef6fd8d71ad9aa5eaf1f90e904e96f0b (diff) | |
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
Diffstat (limited to 'src/bin/psql/copy.c')
| -rw-r--r-- | src/bin/psql/copy.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index 4b749154adf..90f4a24fa5d 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -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++; + } } } |
