public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] tui: make updating of start_line in tui_puts more consistent
@ 2015-08-26  1:06 Patrick Palka
  2015-08-26  1:06 ` [PATCH 2/2] tui: maintain a scrollback buffer and dump it upon exit (PR tui/14584) Patrick Palka
  2015-09-10 15:25 ` [PATCH 1/2] tui: make updating of start_line in tui_puts more consistent Pedro Alves
  0 siblings, 2 replies; 6+ messages in thread
From: Patrick Palka @ 2015-08-26  1:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: Patrick Palka

The command window's start_line field is used by the function
tui_redisplay_readline to figure out on which window line to start
redrawing the (possibly multi-line) command line.  It differs from the Y
coordinate of the window cursor only when the length of the line being
outputted is longer than the width of the window.

The function tui_puts however currently does not respect this property
of start_line.  After a call to tui_puts, start_line will always be
equal to cur_line even when the outputted line may have wrapped a few
times.  This patch makes tui_puts update start_line in a way that's
consistent with how tui_redisplay_readline does it.  This patch also
explicitly documents this property of start_line.

gdb/ChangeLog:

	* tui/tui-data.h (tui_command_info): Add comment documenting the
	field start_line.
	* tui/tui-io.c (tui_puts): Fix the updating of start_line.
---
 gdb/tui/tui-data.h |  5 +++++
 gdb/tui/tui-io.c   | 17 ++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index df1fe6c..2f9030a 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -265,6 +265,11 @@ struct tui_source_info
 
 struct tui_command_info
 {
+  /* The line number (i.e. the Y coordinate of the command window) that
+     contains the start of the latest line being outputted.  START_LINE differs
+     from the Y coordinate of the window cursor only when the current line is
+     longer than the width of the window, i.e. only when the current line has
+     wrapped to the next line one or more times.  */
   int start_line;
 };
 
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index c7a092f..311c96c 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -168,7 +168,12 @@ tui_puts (const char *string)
         }
       else if (tui_skip_line != 1)
         {
+	  int prev_line, prev_col;
+
           tui_skip_line = -1;
+
+	  getyx (w, prev_line, prev_col);
+
 	  /* Expand TABs, since ncurses on MS-Windows doesn't.  */
 	  if (c == '\t')
 	    {
@@ -183,11 +188,21 @@ tui_puts (const char *string)
 	    }
 	  else
 	    waddch (w, c);
+
+	  if (c == '\n')
+	    TUI_CMD_WIN->detail.command_info.start_line = getcury (w);
+	  else if (getcurx (w) <= prev_col && getcury (w) == prev_line)
+	    {
+	      /* If the cursor is on the last line of the command window and the
+		 added character caused the line to wrap, then we have to adjust
+		 start_line to compensate for the scrolling up of each line that
+		 the line wrapping caused.  */
+	      TUI_CMD_WIN->detail.command_info.start_line--;
+	    }
         }
       else if (c == '\n')
         tui_skip_line = -1;
     }
-  TUI_CMD_WIN->detail.command_info.start_line = getcury (w);
 }
 
 /* Readline callback.
-- 
2.5.0.417.g69c5dbd.dirty

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

end of thread, other threads:[~2015-09-11  8:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-26  1:06 [PATCH 1/2] tui: make updating of start_line in tui_puts more consistent Patrick Palka
2015-08-26  1:06 ` [PATCH 2/2] tui: maintain a scrollback buffer and dump it upon exit (PR tui/14584) Patrick Palka
2015-09-10 15:25   ` Pedro Alves
2015-09-10 22:57     ` Patrick Palka
2015-09-11  8:58       ` Pedro Alves
2015-09-10 15:25 ` [PATCH 1/2] tui: make updating of start_line in tui_puts more consistent Pedro Alves

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).