修订版 | 6f1cb6eac2f28c6e1cb49c011f2b916afb90b4ff (tree) |
---|---|
时间 | 2015-08-21 12:06:47 |
作者 | Patrick Palka <patrick@parc...> |
Commiter | Patrick Palka |
Remove fields curch and cur_line from TUI_CMD_WIN
These fields are currently used to track the location of the cursor
inside the command window. But their usefulness is questionable because
ncurses already internally keeps track of the location of the cursor,
whose coordinates we can query using the functions getyx(), getcurx() or
getcury(). It is an unnecessary pain to keep these fields in sync with
ncurses, and their meaning is not well-defined anyway. For instance, it
is not clear whether the coordinates held in these fields are
authoritative, or whether the coordinates reported by ncurses are.
So to keep things simple, this patch removes these fields and replaces
existing reads of these fields with calls to the appropriate ncurses
querying functions, and replaces writes to these fields with calls to
wmove() (when necessary and applicable).
In the function tui_cont_sig(), I removed the call to wmove() entirely
because moving to (start_line, curch) makes no sense. The move should
have been to (cur_line, curch) -- which would now be a no-op.
Tested on x86_64 Fedora 22, no obvious regressions.
gdb/ChangeLog:
* tui/tui-data.h (tui_command_info): Remove fields cur_line and
curch.
* tui/tui-data.c (tui_clear_win_detail) [CMD_WIN]: Don't set
cur_line or curch, instead call wmove().
(init_win_info) [CMD_WIN]: Likewise.
* tui/tui-io.c (tui_puts): Likewise. Don't read cur_line,
instead call getcury().
(tui_redisplay_readline): Don't set cur_line or curch.
(tui_mld_erase_entire_line): Don't read cur_line, instead call
getcury().
(tui_cont_sig): Remove call to wmove.
(tui_getc): Don't read cur_line or curch, instead call getcury()
or getyx(). Don't set curch.
* tui/tui-win.c (make_visible_with_new_height) [CMD_WIN]: Don't
set cur_line or curch. Always move cursor to (0,0).
@@ -1,3 +1,21 @@ | ||
1 | +2015-08-21 Patrick Palka <patrick@parcs.ath.cx> | |
2 | + | |
3 | + * tui/tui-data.h (tui_command_info): Remove fields cur_line and | |
4 | + curch. | |
5 | + * tui/tui-data.c (tui_clear_win_detail) [CMD_WIN]: Don't set | |
6 | + cur_line or curch, instead call wmove(). | |
7 | + (init_win_info) [CMD_WIN]: Likewise. | |
8 | + * tui/tui-io.c (tui_puts): Likewise. Don't read cur_line, | |
9 | + instead call getcury(). | |
10 | + (tui_redisplay_readline): Don't set cur_line or curch. | |
11 | + (tui_mld_erase_entire_line): Don't read cur_line, instead call | |
12 | + getcury(). | |
13 | + (tui_cont_sig): Remove call to wmove. | |
14 | + (tui_getc): Don't read cur_line or curch, instead call getcury() | |
15 | + or getyx(). Don't set curch. | |
16 | + * tui/tui-win.c (make_visible_with_new_height) [CMD_WIN]: Don't | |
17 | + set cur_line or curch. Always move cursor to (0,0). | |
18 | + | |
1 | 19 | 2015-08-20 Pedro Alves <palves@redhat.com> |
2 | 20 | |
3 | 21 | * infrun.c (print_target_wait_results): Make extern. |
@@ -212,8 +212,7 @@ tui_clear_win_detail (struct tui_win_info *win_info) | ||
212 | 212 | win_info->detail.source_info.horizontal_offset = 0; |
213 | 213 | break; |
214 | 214 | case CMD_WIN: |
215 | - win_info->detail.command_info.cur_line = | |
216 | - win_info->detail.command_info.curch = 0; | |
215 | + wmove (win_info->generic.handle, 0, 0); | |
217 | 216 | break; |
218 | 217 | case DATA_WIN: |
219 | 218 | win_info->detail.data_display_info.data_content = |
@@ -546,8 +545,6 @@ init_win_info (struct tui_win_info *win_info) | ||
546 | 545 | win_info->detail.data_display_info.current_group = 0; |
547 | 546 | break; |
548 | 547 | case CMD_WIN: |
549 | - win_info->detail.command_info.cur_line = 0; | |
550 | - win_info->detail.command_info.curch = 0; | |
551 | 548 | break; |
552 | 549 | default: |
553 | 550 | win_info->detail.opaque = NULL; |
@@ -265,8 +265,6 @@ struct tui_source_info | ||
265 | 265 | |
266 | 266 | struct tui_command_info |
267 | 267 | { |
268 | - int cur_line; /* The current line position. */ | |
269 | - int curch; /* The current cursor position. */ | |
270 | 268 | int start_line; |
271 | 269 | }; |
272 | 270 |
@@ -187,10 +187,7 @@ tui_puts (const char *string) | ||
187 | 187 | else if (c == '\n') |
188 | 188 | tui_skip_line = -1; |
189 | 189 | } |
190 | - getyx (w, TUI_CMD_WIN->detail.command_info.cur_line, | |
191 | - TUI_CMD_WIN->detail.command_info.curch); | |
192 | - TUI_CMD_WIN->detail.command_info.start_line | |
193 | - = TUI_CMD_WIN->detail.command_info.cur_line; | |
190 | + TUI_CMD_WIN->detail.command_info.start_line = getcury (w); | |
194 | 191 | } |
195 | 192 | |
196 | 193 | /* Readline callback. |
@@ -271,24 +268,16 @@ tui_redisplay_readline (void) | ||
271 | 268 | waddch (w, c); |
272 | 269 | } |
273 | 270 | if (c == '\n') |
274 | - { | |
275 | - getyx (w, TUI_CMD_WIN->detail.command_info.start_line, | |
276 | - TUI_CMD_WIN->detail.command_info.curch); | |
277 | - } | |
271 | + TUI_CMD_WIN->detail.command_info.start_line = getcury (w); | |
278 | 272 | getyx (w, line, col); |
279 | 273 | if (col < prev_col) |
280 | 274 | height++; |
281 | 275 | prev_col = col; |
282 | 276 | } |
283 | 277 | wclrtobot (w); |
284 | - getyx (w, TUI_CMD_WIN->detail.command_info.start_line, | |
285 | - TUI_CMD_WIN->detail.command_info.curch); | |
278 | + TUI_CMD_WIN->detail.command_info.start_line = getcury (w); | |
286 | 279 | if (c_line >= 0) |
287 | - { | |
288 | - wmove (w, c_line, c_pos); | |
289 | - TUI_CMD_WIN->detail.command_info.cur_line = c_line; | |
290 | - TUI_CMD_WIN->detail.command_info.curch = c_pos; | |
291 | - } | |
280 | + wmove (w, c_line, c_pos); | |
292 | 281 | TUI_CMD_WIN->detail.command_info.start_line -= height - 1; |
293 | 282 | |
294 | 283 | wrefresh (w); |
@@ -371,10 +360,11 @@ static void | ||
371 | 360 | tui_mld_erase_entire_line (const struct match_list_displayer *displayer) |
372 | 361 | { |
373 | 362 | WINDOW *w = TUI_CMD_WIN->generic.handle; |
363 | + int cur_y = getcury (w); | |
374 | 364 | |
375 | - wmove (w, TUI_CMD_WIN->detail.command_info.cur_line, 0); | |
365 | + wmove (w, cur_y, 0); | |
376 | 366 | wclrtoeol (w); |
377 | - wmove (w, TUI_CMD_WIN->detail.command_info.cur_line, 0); | |
367 | + wmove (w, cur_y, 0); | |
378 | 368 | } |
379 | 369 | |
380 | 370 | /* TUI version of displayer.beep. */ |
@@ -521,10 +511,6 @@ tui_cont_sig (int sig) | ||
521 | 511 | /* Force a refresh of the screen. */ |
522 | 512 | tui_refresh_all_win (); |
523 | 513 | |
524 | - /* Update cursor position on the screen. */ | |
525 | - wmove (TUI_CMD_WIN->generic.handle, | |
526 | - TUI_CMD_WIN->detail.command_info.start_line, | |
527 | - TUI_CMD_WIN->detail.command_info.curch); | |
528 | 514 | wrefresh (TUI_CMD_WIN->generic.handle); |
529 | 515 | } |
530 | 516 | signal (sig, tui_cont_sig); |
@@ -601,7 +587,7 @@ tui_getc (FILE *fp) | ||
601 | 587 | user we recognized the command. */ |
602 | 588 | if (rl_end == 0) |
603 | 589 | { |
604 | - wmove (w, TUI_CMD_WIN->detail.command_info.cur_line, 0); | |
590 | + wmove (w, getcury (w), 0); | |
605 | 591 | |
606 | 592 | /* Clear the line. This will blink the gdb prompt since |
607 | 593 | it will be redrawn at the same line. */ |
@@ -614,8 +600,8 @@ tui_getc (FILE *fp) | ||
614 | 600 | /* Move cursor to the end of the command line before emitting the |
615 | 601 | newline. We need to do so because when ncurses outputs a newline |
616 | 602 | it truncates any text that appears past the end of the cursor. */ |
617 | - int px = TUI_CMD_WIN->detail.command_info.curch; | |
618 | - int py = TUI_CMD_WIN->detail.command_info.cur_line; | |
603 | + int px, py; | |
604 | + getyx (w, py, px); | |
619 | 605 | px += rl_end - rl_point; |
620 | 606 | py += px / TUI_CMD_WIN->generic.width; |
621 | 607 | px %= TUI_CMD_WIN->generic.width; |
@@ -627,8 +613,6 @@ tui_getc (FILE *fp) | ||
627 | 613 | /* Handle prev/next/up/down here. */ |
628 | 614 | ch = tui_dispatch_ctrl_char (ch); |
629 | 615 | |
630 | - if (ch == '\n' || ch == '\r' || ch == '\f') | |
631 | - TUI_CMD_WIN->detail.command_info.curch = 0; | |
632 | 616 | if (ch == KEY_BACKSPACE) |
633 | 617 | return '\b'; |
634 | 618 |
@@ -1525,8 +1525,6 @@ make_visible_with_new_height (struct tui_win_info *win_info) | ||
1525 | 1525 | tui_display_all_data (); |
1526 | 1526 | break; |
1527 | 1527 | case CMD_WIN: |
1528 | - win_info->detail.command_info.cur_line = 0; | |
1529 | - win_info->detail.command_info.curch = 0; | |
1530 | 1528 | #ifdef HAVE_WRESIZE |
1531 | 1529 | wresize (TUI_CMD_WIN->generic.handle, |
1532 | 1530 | TUI_CMD_WIN->generic.height, |
@@ -1535,9 +1533,7 @@ make_visible_with_new_height (struct tui_win_info *win_info) | ||
1535 | 1533 | mvwin (TUI_CMD_WIN->generic.handle, |
1536 | 1534 | TUI_CMD_WIN->generic.origin.y, |
1537 | 1535 | TUI_CMD_WIN->generic.origin.x); |
1538 | - wmove (win_info->generic.handle, | |
1539 | - win_info->detail.command_info.cur_line, | |
1540 | - win_info->detail.command_info.curch); | |
1536 | + wmove (win_info->generic.handle, 0, 0); | |
1541 | 1537 | break; |
1542 | 1538 | default: |
1543 | 1539 | break; |