Allow using less horizontal space in TUI source window
authorTom Tromey <tom@tromey.com>
Thu, 11 Jul 2019 23:06:00 +0000 (17:06 -0600)
committerTom Tromey <tom@tromey.com>
Sun, 1 Dec 2019 18:59:23 +0000 (11:59 -0700)
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, so I changed that in an earlier
patch.

However, that change wasn't universally popular.  This patch instead
adds the option to use less horizontal space in the TUI source window.

gdb/ChangeLog
2019-12-01  Tom Tromey  <tom@tromey.com>

* tui/tui-winsource.h (tui_copy_source_line): Add "ndigits"
parameter.
* tui/tui-winsource.c (tui_copy_source_line): Add "ndigits"
parameter.
* tui/tui-win.h (compact_source): Declare.
* tui/tui-win.c (compact_source): New global.
(tui_set_compact_source, tui_show_compact_source): New functions.
(_initialize_tui_win): Add "compact-source" setting.
* tui/tui-source.c (tui_source_window::set_contents): Handle
compact_source setting.
* tui/tui-disasm.c (tui_disasm_window::set_contents): Update.
* NEWS: Document new setting.

gdb/doc/ChangeLog
2019-12-01  Tom Tromey  <tom@tromey.com>

* gdb.texinfo (TUI Configuration): Document new setting.

Change-Id: I46ce9a68b12c9c79332d510f9c14b3c84b7efadd

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/tui/tui-disasm.c
gdb/tui/tui-source.c
gdb/tui/tui-win.c
gdb/tui/tui-win.h
gdb/tui/tui-winsource.c
gdb/tui/tui-winsource.h

index 621cbbbf95938c15d541fae4ce5667ee5715ca12..15f3e6c892455700d90fd28be8bff726cc97ce8b 100644 (file)
@@ -1,3 +1,18 @@
+2019-12-01  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui-winsource.h (tui_copy_source_line): Add "ndigits"
+       parameter.
+       * tui/tui-winsource.c (tui_copy_source_line): Add "ndigits"
+       parameter.
+       * tui/tui-win.h (compact_source): Declare.
+       * tui/tui-win.c (compact_source): New global.
+       (tui_set_compact_source, tui_show_compact_source): New functions.
+       (_initialize_tui_win): Add "compact-source" setting.
+       * tui/tui-source.c (tui_source_window::set_contents): Handle
+       compact_source setting.
+       * tui/tui-disasm.c (tui_disasm_window::set_contents): Update.
+       * NEWS: Document new setting.
+
 2019-11-30  Tom Tromey  <tom@tromey.com>
 
        * dwarf2read.c (dwarf2_add_field): Include field offset when
index e477986d5f57284ab5494f09bca0fb4a6bd4a94b..56d4a3467398696c715de4ea0ace7a9ac96a75b0 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -188,6 +188,14 @@ show print frame-info
   'frame', 'stepi'.  The python frame filtering also respect this setting.
   The 'backtrace' '-frame-info' option can override this global setting.
 
+set tui compact-source
+show tui compact-source
+
+  Enable the "compact" display mode for the TUI source window.  The
+  compact display uses only as much space as is needed for the line
+  numbers in the current file, and only a single space to separate the
+  line numbers from the source.
+
 info modules [-q] [REGEXP]
   Return a list of Fortran modules matching REGEXP, or all modules if
   no REGEXP is given.
index aaac75a50c1e86d3a4a7cf9a4551f43267ca724a..8028f789ea4f0b27f8202d0dcd01815927ffc3c4 100644 (file)
@@ -1,3 +1,7 @@
+2019-12-01  Tom Tromey  <tom@tromey.com>
+
+       * gdb.texinfo (TUI Configuration): Document new setting.
+
 2019-11-30  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
        * gdb.texinfo (Define): Indicate that user-defined prefix can
index 2c30ea657e6aab8715d9b175ed99ab69ebce138e..9b5297ed112a68ed716042e616bc03ddc9d3c49a 100644 (file)
@@ -28017,6 +28017,14 @@ Use extra bright or bold and standout mode.
 Set the width of tab stops to be @var{nchars} characters.  This
 setting affects the display of TAB characters in the source and
 assembly windows.
+
+@item set tui compact-source @r{[}on@r{|}off@r{]}
+@kindex set tui compact-source
+Set whether the TUI source window is displayed in ``compact'' form.
+The default display uses more space for line numbers and starts the
+source text at the next tab stop; the compact display uses only as
+much space as is needed for the line numbers in the current file, and
+only a single space to separate the line numbers from the source.
 @end table
 
 @node Emacs
index 8d5512efb2c980b4605300133eb076d735906a03..9819cb9ecaf1f6cafd112a6e7cd26e470afdd8a9 100644 (file)
@@ -245,7 +245,7 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
           + asm_lines[i].insn);
 
       const char *ptr = line.c_str ();
-      src->line = tui_copy_source_line (&ptr, -1, offset, line_width);
+      src->line = tui_copy_source_line (&ptr, -1, offset, line_width, 0);
 
       src->line_or_addr.loa = LOA_ADDRESS;
       src->line_or_addr.u.addr = asm_lines[i].addr;
index 915f9e36315283dbc7deb9abf8136b37581972f9..32877d7bc87a009205b7a880bf54bd2e9ea7ac98 100644 (file)
@@ -20,6 +20,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include <math.h>
 #include <ctype.h>
 #include "symtab.h"
 #include "frame.h"
@@ -33,6 +34,7 @@
 #include "tui/tui-data.h"
 #include "tui/tui-io.h"
 #include "tui/tui-stack.h"
+#include "tui/tui-win.h"
 #include "tui/tui-winsource.h"
 #include "tui/tui-source.h"
 #include "gdb_curses.h"
@@ -59,8 +61,10 @@ tui_source_window::set_contents (struct gdbarch *arch,
       nlines = (line_no + (height - 2)) - line_no;
 
       std::string srclines;
+      const std::vector<off_t> *offsets;
       if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines,
-                                           &srclines))
+                                           &srclines)
+         || !g_source_cache.get_line_charpos (s, &offsets))
        ret = TUI_FAILURE;
       else
        {
@@ -78,6 +82,13 @@ tui_source_window::set_contents (struct gdbarch *arch,
          start_line_or_addr.loa = LOA_LINE;
          cur_line_no = start_line_or_addr.u.line_no = line_no;
 
+         int digits = 0;
+         if (compact_source)
+           {
+             double l = log10 (offsets->size ());
+             digits = 1 + (int) l;
+           }
+
          const char *iter = srclines.c_str ();
          content.resize (nlines);
          while (cur_line < nlines)
@@ -89,7 +100,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
              if (*iter != '\0')
                text = tui_copy_source_line (&iter, cur_line_no,
                                             horizontal_offset,
-                                            line_width);
+                                            line_width, digits);
 
              /* Set whether element is the execution point
                 and whether there is a break point on it.  */
index f47dad80a2bc59fb67851c97f2990319cc10be11..576f9a543dd7fc241ea81a17b6376f41240c56a9 100644 (file)
@@ -927,6 +927,29 @@ tui_show_tab_width (struct ui_file *file, int from_tty,
 
 }
 
+/* See tui-win.h.  */
+
+bool compact_source = false;
+
+/* Callback for "set tui compact-source".  */
+
+static void
+tui_set_compact_source (const char *ignore, int from_tty,
+                       struct cmd_list_element *c)
+{
+  if (TUI_SRC_WIN != nullptr)
+    TUI_SRC_WIN->refill ();
+}
+
+/* Callback for "show tui compact-source".  */
+
+static void
+tui_show_compact_source (struct ui_file *file, int from_tty,
+                        struct cmd_list_element *c, const char *value)
+{
+  printf_filtered (_("TUI source window compactness is %s.\n"), value);
+}
+
 /* Set the tab width of the specified window.  */
 static void
 tui_set_tab_width_command (const char *arg, int from_tty)
@@ -1484,4 +1507,14 @@ When enabled GDB will print a message when the terminal is resized."),
                           show_tui_resize_message,
                           &maintenance_set_cmdlist,
                           &maintenance_show_cmdlist);
+
+  add_setshow_boolean_cmd ("compact-source", class_tui,
+                          &compact_source, _("\
+Set whether the TUI source window is compact."), _("\
+Show whether the TUI source window is compact."), _("\
+This variable controls whether the TUI source window is shown\n\
+in a compact form.  The compact form puts the source closer to\n\
+the line numbers and uses less horizontal space."),
+                          tui_set_compact_source, tui_show_compact_source,
+                          &tui_setlist, &tui_showlist);
 }
index 81b7dacb1502752574485ccc21812459884db122..1ffe683107a47f58fba45a670469f8503c7b2074 100644 (file)
@@ -54,4 +54,7 @@ extern void tui_update_gdb_sizes (void);
 /* Create or get the TUI command list.  */
 struct cmd_list_element **tui_get_cmd_list (void);
 
+/* Whether compact source display should be used.  */
+extern bool compact_source;
+
 #endif /* TUI_TUI_WIN_H */
index 3ca723c8b2609adb9f7b39a4dfd5564f5686c201..81937c100c563c94677d364754b0e708964aa798 100644 (file)
@@ -69,7 +69,7 @@ tui_display_main ()
 
 std::string
 tui_copy_source_line (const char **ptr, int line_no, int first_col,
-                     int line_width)
+                     int line_width, int ndigits)
 {
   const char *lineptr = *ptr;
 
@@ -78,10 +78,15 @@ tui_copy_source_line (const char **ptr, int line_no, int first_col,
 
   if (line_no > 0)
     {
-      result = string_printf ("%-6d", line_no);
-      int len = result.size ();
-      len = len - ((len / tui_tab_width) * tui_tab_width);
-      result.append (len, ' ');
+      if (ndigits > 0)
+       result = string_printf ("%*d ", ndigits, line_no);
+      else
+       {
+         result = string_printf ("%-6d", line_no);
+         int len = result.size ();
+         len = len - ((len / tui_tab_width) * tui_tab_width);
+         result.append (len, ' ');
+       }
     }
 
   int column = 0;
index 7c3c626add16cfd47b384cc1bea1bcae5dfb261b..8b9620034feafe01c5fabffde2a3cd25dea5b74f 100644 (file)
@@ -238,12 +238,16 @@ extern void tui_update_source_windows_with_line (struct symtab *,
 /* Extract some source text from PTR.  LINE_NO is the line number.  If
    it is positive, it is printed at the start of the line.  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.
-   PTR is updated to point to the start of the next line.  */
+   characters to display.  NDIGITS is used to format the line number
+   (if it is positive).  If NDIGITS is greater than 0, then that many
+   digits are used; otherwise the line number is formatted with 6
+   digits and the text is aligned to the next tab stop.  Returns a
+   string holding the desired text.  PTR is updated to point to the
+   start of the next line.  */
 
 extern std::string tui_copy_source_line (const char **ptr,
                                         int line_no, int first_col,
-                                        int line_width);
+                                        int line_width, int ndigits);
 
 /* Constant definitions. */
 #define SCROLL_THRESHOLD 2     /* Threshold for lazy scroll.  */
This page took 0.052653 seconds and 4 git commands to generate.