From patchwork Wed Aug 19 04:38:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 8283 Received: (qmail 86149 invoked by alias); 19 Aug 2015 04:39:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 85929 invoked by uid 89); 19 Aug 2015 04:39:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qg0-f49.google.com Received: from mail-qg0-f49.google.com (HELO mail-qg0-f49.google.com) (209.85.192.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 19 Aug 2015 04:39:05 +0000 Received: by qgeb6 with SMTP id b6so15364623qge.3 for ; Tue, 18 Aug 2015 21:39:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kLe8OMYujGCOlzWipMS48YdPGDGX3ut9lENuDmQYjvI=; b=duJxEgYD/4s/OGcphO1BF4EPOSSBdEsRcyVC+XhznyvQtfwCDwO8loCuhYLixAfyeV 62SAujPF/aflOVX1w0w/Sdp4xpZNfe+ZM0Z2SN9MNDTC5aMLSEVptfK19qMuZCGYabMA GdfNiUlWchmQflRt+YUV0elAutYFmOY+7hfPe53EkeRgB1Gjhmsg6FgTKtwHNGSzzobt H0fZTIcQdReFs9FJXupKj4P8izOBnCQ9uvn4JwSOcZwQ229W/LqPwNjSQrVRBDRixi4l 0N5vonlO3fNYpIt+sNv6KkvUMGwSJMocQzdJjFiffsaQKbyEixooSipoaMWhqxtw5pmO L0Dg== X-Gm-Message-State: ALoCoQlAZX2Qaamk6KIQVrY+oiRfzF4AbuVD5tcFVIbuAipeRrD9qExpcPIT5xeB5PmLipUE9BOL X-Received: by 10.141.28.2 with SMTP id f2mr20707250qhe.9.1439959143459; Tue, 18 Aug 2015 21:39:03 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by smtp.gmail.com with ESMTPSA id x201sm11553629qkx.28.2015.08.18.21.39.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Aug 2015 21:39:02 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Remove fields curch and cur_line from TUI_CMD_WIN Date: Wed, 19 Aug 2015 00:38:58 -0400 Message-Id: <1439959138-9326-1-git-send-email-patrick@parcs.ath.cx> 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 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. Does this seem like a step in the right direction? These fields like an unnecessary abstraction. Tested on x86_64 Fedora 22, with seemingly 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). --- gdb/tui/tui-data.c | 5 +---- gdb/tui/tui-data.h | 2 -- gdb/tui/tui-io.c | 36 ++++++++++-------------------------- gdb/tui/tui-win.c | 6 +----- 4 files changed, 12 insertions(+), 37 deletions(-) diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c index 0c350d8..f610d9c 100644 --- a/gdb/tui/tui-data.c +++ b/gdb/tui/tui-data.c @@ -212,8 +212,7 @@ tui_clear_win_detail (struct tui_win_info *win_info) win_info->detail.source_info.horizontal_offset = 0; break; case CMD_WIN: - win_info->detail.command_info.cur_line = - win_info->detail.command_info.curch = 0; + wmove (win_info->generic.handle, 0, 0); break; case DATA_WIN: win_info->detail.data_display_info.data_content = @@ -546,8 +545,6 @@ init_win_info (struct tui_win_info *win_info) win_info->detail.data_display_info.current_group = 0; break; case CMD_WIN: - win_info->detail.command_info.cur_line = 0; - win_info->detail.command_info.curch = 0; break; default: win_info->detail.opaque = NULL; diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index 0e7e31e..df1fe6c 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -265,8 +265,6 @@ struct tui_source_info struct tui_command_info { - int cur_line; /* The current line position. */ - int curch; /* The current cursor position. */ int start_line; }; diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 97906ce..f0ff5c0 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -187,10 +187,7 @@ tui_puts (const char *string) 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; + TUI_CMD_WIN->detail.command_info.start_line = getcury (w); } /* Readline callback. @@ -271,24 +268,16 @@ 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); - } + TUI_CMD_WIN->detail.command_info.start_line = getcury (w); 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); 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; - } + wmove (w, c_line, c_pos); TUI_CMD_WIN->detail.command_info.start_line -= height - 1; wrefresh (w); @@ -371,10 +360,11 @@ static void tui_mld_erase_entire_line (const struct match_list_displayer *displayer) { WINDOW *w = TUI_CMD_WIN->generic.handle; + int cur_y = getcury (w); - wmove (w, TUI_CMD_WIN->detail.command_info.cur_line, 0); + wmove (w, cur_y, 0); wclrtoeol (w); - wmove (w, TUI_CMD_WIN->detail.command_info.cur_line, 0); + wmove (w, cur_y, 0); } /* TUI version of displayer.beep. */ @@ -521,10 +511,6 @@ tui_cont_sig (int sig) /* Force a refresh of the screen. */ tui_refresh_all_win (); - /* Update cursor position on the screen. */ - wmove (TUI_CMD_WIN->generic.handle, - TUI_CMD_WIN->detail.command_info.start_line, - TUI_CMD_WIN->detail.command_info.curch); wrefresh (TUI_CMD_WIN->generic.handle); } signal (sig, tui_cont_sig); @@ -601,7 +587,7 @@ tui_getc (FILE *fp) user we recognized the command. */ if (rl_end == 0) { - wmove (w, TUI_CMD_WIN->detail.command_info.cur_line, 0); + wmove (w, getcury (w), 0); /* Clear the line. This will blink the gdb prompt since it will be redrawn at the same line. */ @@ -614,8 +600,8 @@ tui_getc (FILE *fp) /* Move cursor to the end of the command line before emitting the newline. We need to do so because when ncurses outputs a newline it truncates any text that appears past the end of the cursor. */ - int px = TUI_CMD_WIN->detail.command_info.curch; - int py = TUI_CMD_WIN->detail.command_info.cur_line; + int px, py; + getyx (w, py, px); px += rl_end - rl_point; py += px / TUI_CMD_WIN->generic.width; px %= TUI_CMD_WIN->generic.width; @@ -627,8 +613,6 @@ tui_getc (FILE *fp) /* Handle prev/next/up/down here. */ ch = tui_dispatch_ctrl_char (ch); - if (ch == '\n' || ch == '\r' || ch == '\f') - TUI_CMD_WIN->detail.command_info.curch = 0; if (ch == KEY_BACKSPACE) return '\b'; diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 29ad279..6768d35 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -1525,8 +1525,6 @@ make_visible_with_new_height (struct tui_win_info *win_info) tui_display_all_data (); break; case CMD_WIN: - win_info->detail.command_info.cur_line = 0; - win_info->detail.command_info.curch = 0; #ifdef HAVE_WRESIZE wresize (TUI_CMD_WIN->generic.handle, TUI_CMD_WIN->generic.height, @@ -1535,9 +1533,7 @@ make_visible_with_new_height (struct tui_win_info *win_info) mvwin (TUI_CMD_WIN->generic.handle, TUI_CMD_WIN->generic.origin.y, TUI_CMD_WIN->generic.origin.x); - wmove (win_info->generic.handle, - win_info->detail.command_info.cur_line, - win_info->detail.command_info.curch); + wmove (win_info->generic.handle, 0, 0); break; default: break;