[4/5] tui: make updating of start_line in tui_puts more consistent
Commit Message
The command window's start_line field is used by tui_redisplay_readline
to figure out on which window line to start redrawing the (possibly
multi-line) command line. It differs from cur_line only when the length
of the line being outputted is longer than the width of the window. In
this case, start_line will not equal to cur_line. Instead, start_line
will be equal to cur_line - N where N is the number of times the current
line was wrapped around the width of the command window. start_line
takes into consideration whether line wrapping has occurred, and
cur_line does not.
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 properly update start_line. It must
only be updated if a newline is emitted, or if ncurses scrolls the
command window (thus shifting all the line numbers).
gdb/ChangeLog:
* tui/tui-io.c (tui_puts): Fix the updating of start_line.
---
gdb/tui/tui-io.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
@@ -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,14 +188,23 @@ 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;
}
getyx (w, TUI_CMD_WIN->detail.command_info.cur_line,
TUI_CMD_WIN->detail.command_info.curch);
- TUI_CMD_WIN->detail.command_info.start_line
- = TUI_CMD_WIN->detail.command_info.cur_line;
}
/* Readline callback.