Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Patrick Palka <patrick@parcs.ath.cx>
To: gdb-patches@sourceware.org
Cc: Patrick Palka <patrick@parcs.ath.cx>
Subject: [PATCH] TUI: rewrite tui_query_hook()
Date: Thu, 08 Jan 2015 03:51:00 -0000	[thread overview]
Message-ID: <1420689048-23538-1-git-send-email-patrick@parcs.ath.cx> (raw)

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


             reply	other threads:[~2015-01-08  3:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-08  3:51 Patrick Palka [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420689048-23538-1-git-send-email-patrick@parcs.ath.cx \
    --to=patrick@parcs.ath.cx \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox