mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
psql: give ^D hint for \q in place where \q is ignored
Also add comment on why exit/quit are not documented. Discussion: https://postgr.es/m/20180202053928.GA13472@momjian.us
This commit is contained in:
parent
5c9f2564fa
commit
91389228a1
@ -223,6 +223,7 @@ MainLoop(FILE *source)
|
|||||||
char *rest_of_line = NULL;
|
char *rest_of_line = NULL;
|
||||||
bool found_help = false;
|
bool found_help = false;
|
||||||
bool found_exit_or_quit = false;
|
bool found_exit_or_quit = false;
|
||||||
|
bool found_q = false;
|
||||||
|
|
||||||
/* Search for the words we recognize; must be first word */
|
/* Search for the words we recognize; must be first word */
|
||||||
if (pg_strncasecmp(first_word, "help", 4) == 0)
|
if (pg_strncasecmp(first_word, "help", 4) == 0)
|
||||||
@ -237,10 +238,18 @@ MainLoop(FILE *source)
|
|||||||
found_exit_or_quit = true;
|
found_exit_or_quit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (strncmp(first_word, "\\q", 2) == 0)
|
||||||
|
{
|
||||||
|
rest_of_line = first_word + 2;
|
||||||
|
found_q = true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we found a command word, check whether the rest of the line
|
* If we found a command word, check whether the rest of the line
|
||||||
* contains only whitespace plus maybe one semicolon. If not,
|
* contains only whitespace plus maybe one semicolon. If not,
|
||||||
* ignore the command word after all.
|
* ignore the command word after all. These commands are only
|
||||||
|
* for compatibility with other SQL clients and are not
|
||||||
|
* documented.
|
||||||
*/
|
*/
|
||||||
if (rest_of_line != NULL)
|
if (rest_of_line != NULL)
|
||||||
{
|
{
|
||||||
@ -288,6 +297,7 @@ MainLoop(FILE *source)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "quit" and "exit" are only commands when the query buffer is
|
* "quit" and "exit" are only commands when the query buffer is
|
||||||
* empty, but we emit a one-line message even when it isn't to
|
* empty, but we emit a one-line message even when it isn't to
|
||||||
@ -318,6 +328,21 @@ MainLoop(FILE *source)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If they typed "\q" in a place where "\q" is not active,
|
||||||
|
* supply a hint. The text is still added to the query
|
||||||
|
* buffer.
|
||||||
|
*/
|
||||||
|
if (found_q && query_buf->len != 0 &&
|
||||||
|
prompt_status != PROMPT_READY &&
|
||||||
|
prompt_status != PROMPT_CONTINUE &&
|
||||||
|
prompt_status != PROMPT_PAREN)
|
||||||
|
#ifndef WIN32
|
||||||
|
puts(_("Use control-D to quit."));
|
||||||
|
#else
|
||||||
|
puts(_("Use control-C to quit."));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* echo back if flag is set, unless interactive */
|
/* echo back if flag is set, unless interactive */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user