public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] [gdb/tui] Make tui compact-source more compact
Date: Wed, 10 May 2023 08:20:15 +0200	[thread overview]
Message-ID: <20230510062015.20974-1-tdevries@suse.de> (raw)

I noticed with tui compact-source on, that when reducing the height of the
src window we go from:
...
|___09_  i++;                          |
|___10_  i++;                          |
+--------------------------------------+
...
to:
...
|___09_  i++;                          |
+--------------------------------------+
...
In other words, the digits used to print 9 remains 2, even though only 1 is
needed.

This is due to this line in tui_source_window::set_contents:
...
      int max_line_nr = std::max (lines_in_file, last_line_nr_in_window);
...
which takes both the last line in the window and the total lines in the source
file into account.

Make "tui compact-source" more compact by just using:
...
      int max_line_nr = last_line_nr_in_window;
...
such that we have:
...
|___9_  i++;                           |
+--------------------------------------+
...

Tested on x86_64-linux.
---
 gdb/testsuite/gdb.tui/compact-source-2.exp | 68 ++++++++++++++++++++++
 gdb/tui/tui-source.c                       |  3 +-
 2 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 gdb/testsuite/gdb.tui/compact-source-2.exp

diff --git a/gdb/testsuite/gdb.tui/compact-source-2.exp b/gdb/testsuite/gdb.tui/compact-source-2.exp
new file mode 100644
index 00000000000..416c76e1d26
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/compact-source-2.exp
@@ -0,0 +1,68 @@
+# Copyright 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that "set tui compact-source on" has the intended effect.
+
+require allow_tui_tests
+
+tuiterm_env
+
+standard_testfile
+
+# Let's generate the source file.  We want a short file, with more than 10
+# lines, but with the first line in main below 10.
+set src_list \
+    [list \
+	 "int" \
+	 "main (void)" \
+	 "{" \
+	 "  int i = 1;" \
+	 "  i++;" \
+	 "  i++;" \
+	 "  i++;" \
+	 "  i++;" \
+	 "  i++;" \
+	 "  return 0;" \
+	 "}"]
+set line_four [lindex $src_list 3]
+set src_txt [join $src_list "\n"]
+set srcfile [standard_output_file $srcfile]
+set fd [open $srcfile w]
+puts $fd $src_txt
+close $fd
+
+if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} {
+    return -1
+}
+
+Term::clean_restart 17 80 $binfile
+
+gdb_test_no_output "maint set tui-left-margin-verbose on"
+gdb_test_no_output "set tui compact-source on"
+
+if {![Term::enter_tui]} {
+    unsupported "TUI not supported"
+    return
+}
+
+set re_border "\\|"
+Term::check_contents "compact source format" \
+    "${re_border}___04_$line_four *$re_border"
+
+with_test_prefix window-resize=1 {
+    Term::command "wh src -1"
+    Term::check_contents "compact source" \
+	"${re_border}___4_$line_four *$re_border"
+}
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 1233e945cab..bef3d3163dd 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -79,9 +79,8 @@ tui_source_window::set_contents (struct gdbarch *arch,
     {
       /* Solaris 11+gcc 5.5 has ambiguous overloads of log10, so we
 	 cast to double to get the right one.  */
-      int lines_in_file = offsets->size ();
       int last_line_nr_in_window = line_no + nlines - 1;
-      int max_line_nr = std::max (lines_in_file, last_line_nr_in_window);
+      int max_line_nr = last_line_nr_in_window;
       int digits_needed = 1 + (int)log10 ((double) max_line_nr);
       int trailing_space = 1;
       m_digits = digits_needed + trailing_space;

base-commit: 2093c2af3c58da1fe63807dfea07d56afc6e7a8a
-- 
2.35.3


             reply	other threads:[~2023-05-10  6:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-10  6:20 Tom de Vries [this message]
2023-05-10  9:03 ` Andrew Burgess
2023-05-10 15:09   ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230510062015.20974-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).