On Fri, Feb  2, 2018 at 12:39:28AM -0500, Bruce Momjian wrote:
> I just thought of an inconsistency.  First, we now consistently exit with
> 'exit', 'quit', and '\q' if used in an empty psql query buffer.  Also, we now
> hint when 'exit' and 'quit' are used in non-empty query buffers:
> 
>       test=> SELECT
>       test-> exit
> -->   Use \q to quit.
> 
> We obviously don't need to hint for '\q' since it works in this context.
> 
> Where it is odd is that we hint for 'exit' and 'quit' in places that
> '\q' doesn't work, but we don't hint for '\q' in the same contexts. 
> Here is the hint for 'exit' and 'quit':
> 
>       test=> SELECT '
>       test'> exit
> -->   Use control-D to quit.
> 
> but we don't hint for '\q':
> 
>       test=> SELECT '
>       test'> \q
> -->   test'>
> 
> Should we give the same "Use control-D to quit." hint here for '\q'?
> I think it is logical that we should.

I have applied the attached patch giving a ^D/^C hint where \q is
ignored, and add C comment documenting why exit/quit is not documented.

I consider this issue closed, or quited, or exited.  :-)

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +
diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c
new file mode 100644
index a3ef150..c06ce3c
*** a/src/bin/psql/mainloop.c
--- b/src/bin/psql/mainloop.c
*************** MainLoop(FILE *source)
*** 223,228 ****
--- 223,229 ----
  			char	   *rest_of_line = NULL;
  			bool		found_help = false;
  			bool		found_exit_or_quit = false;
+ 			bool		found_q = false;
  
  			/* Search for the words we recognize;  must be first word */
  			if (pg_strncasecmp(first_word, "help", 4) == 0)
*************** MainLoop(FILE *source)
*** 237,246 ****
  				found_exit_or_quit = true;
  			}
  
  			/*
  			 * If we found a command word, check whether the rest of the line
  			 * contains only whitespace plus maybe one semicolon.  If not,
! 			 * ignore the command word after all.
  			 */
  			if (rest_of_line != NULL)
  			{
--- 238,255 ----
  				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
  			 * contains only whitespace plus maybe one semicolon.  If not,
! 			 * 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)
  			{
*************** MainLoop(FILE *source)
*** 288,293 ****
--- 297,303 ----
  					continue;
  				}
  			}
+ 
  			/*
  			 * "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
*************** MainLoop(FILE *source)
*** 318,323 ****
--- 328,348 ----
  					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 */

Reply via email to