[3/5] tui: simplify and fix up handling of start_line in tui_redisplay_readline
Commit Message
This patch makes three small changes:
The code guarded by the c == '\n' condition is dead code because
whatever value start_line and curch get set to will be overwritten after
the while-loop finishes anyway. So this patch removes this dead code.
Besides that, the remaining two writes to start_line are combined into
one write.
Finally, if start_line ever falls below 0, which can happen if the
command line is so long that it wraps along the height of the entire
command window, just reset it to 0 so that we avoid passing an invalid y
parameter to wmove() later, and emit a beep to "warn" the user that the
command line is too long.
gdb/ChangeLog:
* tui/tui-io.c (tui_redisplay_readline): Simplify the updating
of start_line. If start_line is negative, re-set it to 0 and
emit a beep.
---
gdb/tui/tui-io.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
@@ -270,26 +270,33 @@ tui_redisplay_readline (void)
{
waddch (w, c);
}
- if (c == '\n')
- {
- getyx (w, TUI_CMD_WIN->detail.command_info.start_line,
- TUI_CMD_WIN->detail.command_info.curch);
- }
getyx (w, line, col);
if (col < prev_col)
height++;
prev_col = col;
}
+
wclrtobot (w);
- getyx (w, TUI_CMD_WIN->detail.command_info.start_line,
- TUI_CMD_WIN->detail.command_info.curch);
+
+ TUI_CMD_WIN->detail.command_info.start_line
+ = getcury (w) - (height - 1);
+ TUI_CMD_WIN->detail.command_info.curch
+ = getcurx (w);
+
+ /* This can happen if the command line is so long that it wraps along the
+ height of the entire window. */
+ if (TUI_CMD_WIN->detail.command_info.start_line < 0)
+ {
+ beep ();
+ TUI_CMD_WIN->detail.command_info.start_line = 0;
+ }
+
if (c_line >= 0)
{
wmove (w, c_line, c_pos);
TUI_CMD_WIN->detail.command_info.cur_line = c_line;
TUI_CMD_WIN->detail.command_info.curch = c_pos;
}
- TUI_CMD_WIN->detail.command_info.start_line -= height - 1;
wrefresh (w);
fflush(stdout);