Re: TUI enhancement suggestion.

Phi Debian
2020-06-09T15:04:09Z

[-- Attachment #1: Type: text/plain, Size: 302 bytes --]

Here is the patch I made, I spotted a little typo in a comment, I leave it
in there for now, and provide this as a demonstrator.

I never submitted a patch so I don't really know the best practice, I
cutted it on top of 9.2 (latest pull) then the patch)
I used

$ git format-patch -1 HEAD

Cheers,
Phi

[-- Attachment #2: 0001-Implement-point-underline.patch --]
[-- Type: text/x-patch, Size: 5680 bytes --]

From 395ae414f395d58bd07a44077d4586512924d451 Mon Sep 17 00:00:00 2001
From: Phi <phi@kernel-tools.com>
Date: Tue, 9 Jun 2020 11:59:47 +0200
Subject: [PATCH] Implement point underline

---
gdb/tui/tui-io.c | 18 ++++++++++++++++++
gdb/tui/tui-io.h | 3 +++
gdb/tui/tui-win.c | 31 +++++++++++++++++++++++++++++++
gdb/tui/tui-win.h | 3 +++
gdb/tui/tui-winsource.c | 4 ++--
gdb/ui-style.h | 15 ++++++++++++++-
6 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index e7a8ac77bc..7dcc76bab8 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -294,6 +294,7 @@ tui_apply_style (WINDOW *w, ui_file_style style)
/* Reset. */
wattron (w, A_NORMAL);
wattroff (w, A_BOLD);
+ wattroff (w, A_UNDERLINE);
wattroff (w, A_DIM);
wattroff (w, A_REVERSE);
if (last_color_pair != -1)
@@ -330,6 +331,10 @@ tui_apply_style (WINDOW *w, ui_file_style style)
case ui_file_style::NORMAL:
break;

+ case ui_file_style::UNDERLINE:
+ wattron (w, A_UNDERLINE);
+ break;
+
case ui_file_style::BOLD:
wattron (w, A_BOLD);
break;
@@ -423,6 +428,19 @@ tui_set_reverse_mode (WINDOW *w, bool reverse)
tui_apply_style (w, style);
}

+
+void
+tui_set_point_mode (WINDOW *w, bool mode)
+{ ui_file_style style = last_style;
+ if(point_underline==0)
+ { tui_set_reverse_mode(w,mode);
+ }
+ if(point_underline==1)
+ { style.set_underline(mode);
+ tui_apply_style (w, style);
+ }
+}
+
/* Print LENGTH characters from the buffer pointed to by BUF to the
curses command window. The output is buffered. It is up to the
caller to refresh the screen if necessary. */
diff --git a/gdb/tui/tui-io.h b/gdb/tui/tui-io.h
index f28cf4e12d..8aa81b43d8 100644
--- a/gdb/tui/tui-io.h
+++ b/gdb/tui/tui-io.h
@@ -51,6 +51,9 @@ extern gdb::unique_xmalloc_ptr<char> tui_expand_tabs (const char *);
/* Enter/leave reverse video mode. */
extern void tui_set_reverse_mode (WINDOW *w, bool reverse);

+/* Enter/leave point (exec) video mode. */
+extern void tui_set_point_mode (WINDOW *w, bool mode);
+
/* Apply STYLE to the window. */
extern void tui_apply_style (WINDOW *w, ui_file_style style);

diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index a78837fe68..54336e1337 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -823,6 +823,29 @@ tui_show_compact_source (struct ui_file *file, int from_tty,
printf_filtered (_("TUI source window compactness is %s.\n"), value);
}

+
+bool point_underline = false;
+
+/* Callback for "set tui point-underline". */
+
+static void
+tui_set_point_underline (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_point_underline (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ printf_filtered (_("TUI source point underline 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)
@@ -1120,6 +1143,14 @@ the line numbers and uses less horizontal space."),
tui_set_compact_source, tui_show_compact_source,
&tui_setlist, &tui_showlist);

+ add_setshow_boolean_cmd ("point-underline", class_tui,
+ &point_underline, _("\
+Set whether the TUI source point line is underline."), _("\
+Show whether the TUI source point line is underline."), _("\
+This variable controls whether the TUI source point line is underlined.\n"),
+ tui_set_point_underline, tui_show_point_underline,
+ &tui_setlist, &tui_showlist);
+
tui_border_style.changed.attach (tui_rehighlight_all);
tui_active_border_style.changed.attach (tui_rehighlight_all);
}
diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h
index e379184630..d5fbfc5fea 100644
--- a/gdb/tui/tui-win.h
+++ b/gdb/tui/tui-win.h
@@ -57,4 +57,7 @@ struct cmd_list_element **tui_get_cmd_list (void);
/* Whether compact source display should be used. */
extern bool compact_source;

+/* Whether underline point line should be used. */
+extern bool point_underline;
+
#endif /* TUI_TUI_WIN_H */
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index db0add9968..c9f493292a 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -258,12 +258,12 @@ tui_source_window_base::show_source_line (int lineno)

line = &m_content[lineno - 1];
if (line->is_exec_point)
- tui_set_reverse_mode (handle.get (), true);
+ tui_set_point_mode (handle.get (), true);

wmove (handle.get (), lineno, TUI_EXECINFO_SIZE);
tui_puts (line->line.c_str (), handle.get ());
if (line->is_exec_point)
- tui_set_reverse_mode (handle.get (), false);
+ tui_set_point_mode (handle.get (), false);

/* Clear to end of line but stop before the border. */
x = getcurx (handle.get ());
diff --git a/gdb/ui-style.h b/gdb/ui-style.h
index 48ab52d5ea..5566f38c2f 100644
--- a/gdb/ui-style.h
+++ b/gdb/ui-style.h
@@ -135,7 +135,8 @@ struct ui_file_style
{
NORMAL = 0,
BOLD,
- DIM
+ DIM,
+ UNDERLINE
};

ui_file_style () = default;
@@ -210,6 +211,18 @@ struct ui_file_style
m_background = c;
}

+ /* Set the intensity of this style to bold */
+ void set_bold (bool mode)
+ {
+ m_intensity=mode?BOLD:NORMAL;
+ }
+
+ /* Set the intensity of this style to bold */
+ void set_underline (bool mode)
+ {
+ m_intensity=mode?UNDERLINE:NORMAL;
+ }
+
/* Return the intensity of this style. */
intensity get_intensity () const
{
--
2.25.1