[1/2] tui: make updating of start_line in tui_puts more consistent

Message ID 1440551173-18266-1-git-send-email-patrick@parcs.ath.cx
State New, archived
Headers

Commit Message

Patrick Palka Aug. 26, 2015, 1:06 a.m. UTC
  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(-)
  

Comments

Pedro Alves Sept. 10, 2015, 3:25 p.m. UTC | #1
On 08/26/2015 02:06 AM, Patrick Palka wrote:
> 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.

OK.

Thanks,
Pedro Alves
  

Patch

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.