From patchwork Fri Aug 16 02:36:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 34136 Received: (qmail 33240 invoked by alias); 16 Aug 2019 02:36:43 -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 33225 invoked by uid 89); 16 Aug 2019 02:36:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.82) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Aug 2019 02:36:41 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 162D113EAE8 for ; Thu, 15 Aug 2019 21:36:40 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id yS6ahPETe2PzOyS6ahQQzB; Thu, 15 Aug 2019 21:36:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=2vZ16fdtgWsvalRt5AUPR9z6L0aQ6ExShrpqp2KIllw=; b=fruGj+5YRUSsQ23NYquAOOb/Gr twKqF/PgZboxhkWUC6GvjP7lQL6NbF1YSOxJJ4f0bOlZUK6NhT8wESD0hIrqj+plvwfmvS84Mp0xW tNseMBG9uFZfJ2o7LhV+/VzNR; Received: from 97-122-178-82.hlrn.qwest.net ([97.122.178.82]:40154 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92) (envelope-from ) id 1hyS6Z-002qCO-R9; Thu, 15 Aug 2019 21:36:39 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Use less horizontal space in source window Date: Thu, 15 Aug 2019 20:36:31 -0600 Message-Id: <20190816023631.26830-1-tom@tromey.com> The source window currently uses a field width of 6 for line numbers, and it further aligns to the next tab stop. This seemed a bit wasteful of horizontal space to me. This patch changes the TUI to compute the maximum field width needed for the current source file, and to only add a single space after the line number. Line numbers are now right justified, as well, which I think also looks better visually when scrolling. gdb/ChangeLog 2019-08-15 Tom Tromey * tui/tui-source.c (tui_set_source_content): Compute width of line numbers. * tui/tui-source.c (copy_source_line): Add "ndigits" parameter. Emit fewer spaces between line number and text. --- gdb/ChangeLog | 7 +++++++ gdb/tui/tui-source.c | 29 ++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 3d88f66d549..e43b8381fe5 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -37,22 +37,22 @@ #include "tui/tui-source.h" #include "gdb_curses.h" +#include + /* A helper function for tui_set_source_content that extracts some - source text from PTR. LINE_NO is the line number; FIRST_COL is the - first column to extract, and LINE_WIDTH is the number of characters - to display. Returns a string holding the desired text. */ + source text from PTR. LINE_NO is the line number; NDIGITS the + number of digits to use for printing; FIRST_COL is the first column + to extract, and LINE_WIDTH is the number of characters to display. + Returns a string holding the desired text. */ static std::string -copy_source_line (const char **ptr, int line_no, int first_col, - int line_width) +copy_source_line (const char **ptr, int line_no, int ndigits, + int first_col, int line_width) { const char *lineptr = *ptr; /* Init the line with the line number. */ - std::string result = string_printf ("%-6d", line_no); - int len = result.size (); - len = len - ((len / tui_tab_width) * tui_tab_width); - result.append (len, ' '); + std::string result = string_printf ("%*d ", ndigits, line_no); int column = 0; char c; @@ -141,8 +141,10 @@ tui_set_source_content (tui_source_window_base *win_info, nlines = (line_no + (win_info->height - 2)) - line_no; std::string srclines; + const std::vector *offsets; if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines, - &srclines)) + &srclines) + || !g_source_cache.get_line_charpos (s, &offsets)) { if (!noerror) { @@ -172,6 +174,11 @@ tui_set_source_content (tui_source_window_base *win_info, win_info->start_line_or_addr.loa = LOA_LINE; cur_line_no = win_info->start_line_or_addr.u.line_no = line_no; + double l = log10 (offsets->size ()); + int digits = (int) l; + if (l > digits) + ++digits; + const char *iter = srclines.c_str (); win_info->content.resize (nlines); while (cur_line < nlines) @@ -181,7 +188,7 @@ tui_set_source_content (tui_source_window_base *win_info, std::string text; if (*iter != '\0') - text = copy_source_line (&iter, cur_line_no, + text = copy_source_line (&iter, cur_line_no, digits, win_info->horizontal_offset, line_width);