public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] TUI: rewrite tui_query_hook()
@ 2015-01-08  3:51 Patrick Palka
  2015-01-08 11:03 ` Pedro Alves
  2015-01-08 13:31 ` [PATCH] TUI: rewrite tui_query_hook() Eli Zaretskii
  0 siblings, 2 replies; 14+ messages in thread
From: Patrick Palka @ 2015-01-08  3:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Patrick Palka

This patch rewrites tui_query_hook() to print things via tui_puts() and
to read in a line of input via wgetnstr().  The main motivation for this
rewrite is to get the backspace key to work correctly during a quit
prompt so that the user can revise their answer before pressing enter.
The backspace key now works correctly because we now use getstr()
instead of successive calls to getch().

gdb/ChangeLog:

	* tui/tui-hooks.c (tui_query_hook): Rewrite to use tui_puts and
	wgetnstr.
---
 gdb/tui/tui-hooks.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index 6ba6285..9dee840 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -68,9 +68,9 @@ tui_query_hook (const char *msg, va_list argp)
 {
   int retval;
   int ans2;
-  int answer;
   char *question;
   struct cleanup *old_chain;
+  WINDOW *win = TUI_CMD_WIN->generic.handle;
 
   /* Format the question outside of the loop, to avoid reusing
      ARGP.  */
@@ -80,30 +80,18 @@ tui_query_hook (const char *msg, va_list argp)
   echo ();
   while (1)
     {
-      wrap_here ("");		/* Flush any buffered output.  */
-      gdb_flush (gdb_stdout);
+      char response[2], answer;
 
-      fputs_filtered (question, gdb_stdout);
-      printf_filtered (_("(y or n) "));
+      tui_puts (question);
+      tui_puts (_("(y or n) "));
 
-      wrap_here ("");
-      gdb_flush (gdb_stdout);
-
-      answer = tui_getc (stdin);
-      clearerr (stdin);		/* in case of C-d */
-      if (answer == EOF)	/* C-d */
+      if (wgetnstr (win, response, 1) == ERR)
 	{
 	  retval = 1;
 	  break;
 	}
-      /* Eat rest of input line, to EOF or newline.  */
-      if (answer != '\n')
-	do
-	  {
-            ans2 = tui_getc (stdin);
-	    clearerr (stdin);
-	  }
-	while (ans2 != EOF && ans2 != '\n' && ans2 != '\r');
+
+      answer = response[0];
 
       if (answer >= 'a')
 	answer -= 040;
@@ -117,10 +105,13 @@ tui_query_hook (const char *msg, va_list argp)
 	  retval = 0;
 	  break;
 	}
-      printf_filtered (_("Please answer y or n.\n"));
+      tui_puts (_("Please answer y or n.\n"));
     }
   noecho ();
 
+  /* Update our knowledge of the cursor position.  */
+  tui_puts ("");
+
   do_cleanups (old_chain);
   return retval;
 }
-- 
2.2.1.212.gc5b9256

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-01-08 15:50 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-08  3:51 [PATCH] TUI: rewrite tui_query_hook() Patrick Palka
2015-01-08 11:03 ` Pedro Alves
2015-01-08 12:40   ` Patrick Palka
2015-01-08 13:53     ` Pedro Alves
2015-01-08 14:10       ` Patrick Palka
2015-01-08 14:14         ` Patrick Palka
2015-01-08 14:25         ` Patrick Palka
2015-01-08 15:17   ` [PATCH] Consolidate the custom TUI query hook with default query hook Patrick Palka
2015-01-08 15:50     ` Pedro Alves
2015-01-08 13:31 ` [PATCH] TUI: rewrite tui_query_hook() Eli Zaretskii
2015-01-08 13:43   ` Patrick Palka
2015-01-08 13:57     ` Pedro Alves
2015-01-08 14:14     ` Eli Zaretskii
2015-01-08 14:27       ` Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).