Message ID | 20230629173242.151691-1-tom@tromey.com |
---|---|
State | New |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 233713858438 for <patchwork@sourceware.org>; Thu, 29 Jun 2023 17:33:15 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from alt-proxy28.mail.unifiedlayer.com (alt-proxy28.mail.unifiedlayer.com [74.220.216.123]) by sourceware.org (Postfix) with ESMTPS id 5D5B33858D35 for <gdb-patches@sourceware.org>; Thu, 29 Jun 2023 17:33:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D5B33858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw14.mail.unifiedlayer.com (unknown [10.0.90.129]) by progateway1.mail.pro1.eigbox.com (Postfix) with ESMTP id 4CEE41003898E for <gdb-patches@sourceware.org>; Thu, 29 Jun 2023 17:32:52 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id EvVkqLIPXLmMcEvVkqHEdT; Thu, 29 Jun 2023 17:32:52 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=GtGHRm5C c=1 sm=1 tr=0 ts=649dc044 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=of4jigFt-DYA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=tTLXf_SQsSrnMxIS_GgA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type: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=BNxgF2RcOu/VTWAAmfFsZIyUNtZGpqXth2RpSWBKqT4=; b=AGh1s9CJwLEqHHDFDAgpzm/mYQ DuUXHcsScz/cDjwR2YpBgS5ah5QrLu8zmmImqj6PU7Iz/55lERbOLQGGTkN1SAQDQMGy76ifX9HZ/ qr6QgrB0gEK0lxncVVtkQZroq; Received: from 71-211-136-248.hlrn.qwest.net ([71.211.136.248]:37684 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from <tom@tromey.com>) id 1qEvVj-0000jm-3D; Thu, 29 Jun 2023 11:32:52 -0600 From: Tom Tromey <tom@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey <tom@tromey.com> Subject: [PATCH] Update TUI window title when changed Date: Thu, 29 Jun 2023 11:32:42 -0600 Message-ID: <20230629173242.151691-1-tom@tromey.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.136.248 X-Source-L: No X-Exim-ID: 1qEvVj-0000jm-3D X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-136-248.hlrn.qwest.net (localhost.localdomain) [71.211.136.248]:37684 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
Update TUI window title when changed
|
|
Commit Message
Tom Tromey
June 29, 2023, 5:32 p.m. UTC
I wrote a TUI window in Python, and I noticed that setting its title did not result in a refresh, so the new title did not appear. This patch corrects this problem. --- gdb/python/py-tui.c | 2 +- gdb/testsuite/gdb.python/tui-window.exp | 4 ++++ gdb/testsuite/gdb.python/tui-window.py | 5 +++++ gdb/tui/tui-data.c | 11 +++++++++++ gdb/tui/tui-data.h | 4 ++++ 5 files changed, 25 insertions(+), 1 deletion(-)
Comments
Tom Tromey <tom@tromey.com> writes: > I wrote a TUI window in Python, and I noticed that setting its title > did not result in a refresh, so the new title did not appear. This > patch corrects this problem. This looks fine, but I wonder if we should just go all the way and make the window title private and force users to make use of the set_title API? The patch at the bottom of this email applies on top of yours and implements this idea, what do you think? Thanks, Andrew > --- > gdb/python/py-tui.c | 2 +- > gdb/testsuite/gdb.python/tui-window.exp | 4 ++++ > gdb/testsuite/gdb.python/tui-window.py | 5 +++++ > gdb/tui/tui-data.c | 11 +++++++++++ > gdb/tui/tui-data.h | 4 ++++ > 5 files changed, 25 insertions(+), 1 deletion(-) > > diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c > index 84a435ead68..c52b04f9a51 100644 > --- a/gdb/python/py-tui.c > +++ b/gdb/python/py-tui.c > @@ -531,7 +531,7 @@ gdbpy_tui_set_title (PyObject *self, PyObject *newvalue, void *closure) > if (value == nullptr) > return -1; > > - win->window->title = value.get (); > + win->window->set_title (value.get ()); > return 0; > } > > diff --git a/gdb/testsuite/gdb.python/tui-window.exp b/gdb/testsuite/gdb.python/tui-window.exp > index 9b5d17c35d4..defc8c68b25 100644 > --- a/gdb/testsuite/gdb.python/tui-window.exp > +++ b/gdb/testsuite/gdb.python/tui-window.exp > @@ -54,6 +54,10 @@ Term::check_contents "error message after trying to delete title" \ > Term::check_contents "title is unchanged" \ > "This Is The Title" > > +Term::command "python change_window_title ()" > +Term::check_contents "test new title" \ > + "New Title" > + > Term::resize 51 51 > # Remember that a resize request actually does two resizes... > Term::check_contents "Window was updated" "Test: 2" > diff --git a/gdb/testsuite/gdb.python/tui-window.py b/gdb/testsuite/gdb.python/tui-window.py > index 401cb5197ff..dc72cc4c0f7 100644 > --- a/gdb/testsuite/gdb.python/tui-window.py > +++ b/gdb/testsuite/gdb.python/tui-window.py > @@ -53,4 +53,9 @@ def failwin(win): > raise RuntimeError("Whoops") > > > +# Change the title of the window. > +def change_window_title(): > + the_window.win.title = "New Title" > + > + > gdb.register_window_type("fail", failwin) > diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c > index 0daed32b6e6..abd2ec2b5fd 100644 > --- a/gdb/tui/tui-data.c > +++ b/gdb/tui/tui-data.c > @@ -152,6 +152,17 @@ tui_prev_win (struct tui_win_info *cur_win) > return *iter; > } > > +/* See tui-data.h. */ > + > +void > +tui_win_info::set_title (const char *new_title) > +{ > + if (title != new_title) > + { > + title = new_title; > + check_and_display_highlight_if_needed (); > + } > +} > > void > tui_win_info::rerender () > diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h > index c92e85c9da1..030ce2a5438 100644 > --- a/gdb/tui/tui-data.h > +++ b/gdb/tui/tui-data.h > @@ -146,6 +146,10 @@ struct tui_win_info > > void check_and_display_highlight_if_needed (); > > + /* A helper function to change the title and then redraw the > + surrounding box, if needed. */ > + void set_title (const char *new_title); > + > /* Window handle. */ > std::unique_ptr<WINDOW, curses_deleter> handle; > /* Window width. */ > -- > 2.41.0 --- diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c index c52b04f9a51..f47f2278dda 100644 --- a/gdb/python/py-tui.c +++ b/gdb/python/py-tui.c @@ -509,7 +509,7 @@ gdbpy_tui_title (PyObject *self, void *closure) { gdbpy_tui_window *win = (gdbpy_tui_window *) self; REQUIRE_WINDOW (win); - return host_string_to_python_string (win->window->title.c_str ()).release (); + return host_string_to_python_string (win->window->title ().c_str ()).release (); } /* Set the title of the TUI window. */ diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c index abd2ec2b5fd..fc90df25ddd 100644 --- a/gdb/tui/tui-data.c +++ b/gdb/tui/tui-data.c @@ -155,11 +155,11 @@ tui_prev_win (struct tui_win_info *cur_win) /* See tui-data.h. */ void -tui_win_info::set_title (const char *new_title) +tui_win_info::set_title (std::string &&new_title) { - if (title != new_title) + if (m_title != new_title) { - title = new_title; + m_title = new_title; check_and_display_highlight_if_needed (); } } diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index 030ce2a5438..d0e8d56fa07 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -148,7 +148,11 @@ struct tui_win_info /* A helper function to change the title and then redraw the surrounding box, if needed. */ - void set_title (const char *new_title); + void set_title (std::string &&new_title); + + /* Return a reference to the current window title. */ + const std::string &title () const + { return m_title; } /* Window handle. */ std::unique_ptr<WINDOW, curses_deleter> handle; @@ -160,9 +164,6 @@ struct tui_win_info int x = 0; int y = 0; - /* Window title to display. */ - std::string title; - /* Is this window highlighted? */ bool is_highlighted = false; @@ -175,6 +176,10 @@ struct tui_win_info /* Scroll the contents horizontally. This is only called via left_scroll and right_scroll. */ virtual void do_scroll_horizontal (int num_to_scroll) = 0; + +private: + /* Window title to display. */ + std::string m_title; }; /* Constant definitions. */ diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 3a8fcfa5d27..1a351e60cee 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -210,7 +210,7 @@ tui_data_window::show_register_group (const reggroup *group, int regnum, pos; /* Make a new title showing which group we display. */ - title = string_printf ("Register group: %s", group->name ()); + this->set_title (string_printf ("Register group: %s", group->name ())); /* See how many registers must be displayed. */ nr_regs = 0; diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 55cde258882..6625f0cf088 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -65,7 +65,7 @@ tui_source_window::set_contents (struct gdbarch *arch, int cur_line_no, cur_line; const char *s_filename = symtab_to_filename_for_display (s); - title = s_filename; + set_title (s_filename); m_fullname = make_unique_xstrdup (symtab_to_fullname (s)); diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c index 385e6e5d68d..27006869931 100644 --- a/gdb/tui/tui-wingeneral.c +++ b/gdb/tui/tui-wingeneral.c @@ -106,19 +106,19 @@ box_win (struct tui_win_info *win_info, #else box (win, tui_border_vline, tui_border_hline); #endif - if (!win_info->title.empty ()) + if (!win_info->title ().empty ()) { /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on the left. */ int max_len = win_info->width - 2 - 2; - if (win_info->title.size () <= max_len) - mvwaddstr (win, 0, 2, win_info->title.c_str ()); + if (win_info->title ().size () <= max_len) + mvwaddstr (win, 0, 2, win_info->title ().c_str ()); else { std::string truncated - = "..." + win_info->title.substr (win_info->title.size () - - max_len + 3); + = "..." + win_info->title ().substr (win_info->title ().size () + - max_len + 3); mvwaddstr (win, 0, 2, truncated.c_str ()); } }
>> I wrote a TUI window in Python, and I noticed that setting its title >> did not result in a refresh, so the new title did not appear. This >> patch corrects this problem. Andrew> This looks fine, but I wonder if we should just go all the way and make Andrew> the window title private and force users to make use of the set_title Andrew> API? Andrew> The patch at the bottom of this email applies on top of yours and Andrew> implements this idea, what do you think? Looks good to me. Approved-By: Tom Tromey <tom@tromey.com> I'm going to check my patch in now. Tom
Tom Tromey <tom@tromey.com> writes: >>> I wrote a TUI window in Python, and I noticed that setting its title >>> did not result in a refresh, so the new title did not appear. This >>> patch corrects this problem. > > Andrew> This looks fine, but I wonder if we should just go all the way and make > Andrew> the window title private and force users to make use of the set_title > Andrew> API? > > Andrew> The patch at the bottom of this email applies on top of yours and > Andrew> implements this idea, what do you think? > > Looks good to me. > > Approved-By: Tom Tromey <tom@tromey.com> Thanks. Below is what I pushed, no code changes, but this includes the commit message. Thanks, Andrew --- commit 6c1e84f5c6f36263998ef1934bf3132c8cebe75e Author: Andrew Burgess <aburgess@redhat.com> Date: Mon Jul 10 15:56:47 2023 +0100 gdb/tui: make tui_win_info::title private This commit builds on this earlier work: commit 9fe01a376b2fb096e4836e985ba316ce9dc02399 Date: Thu Jun 29 11:26:55 2023 -0600 Update TUI window title when changed and makes tui_win_info::title private, renaming to m_title at the same time. There's a new tui_win_info::title() member function to provide read-only access to the title. There should be no user visible changes after this commit. Approved-By: Tom Tromey <tom@tromey.com> diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c index c52b04f9a51..f47f2278dda 100644 --- a/gdb/python/py-tui.c +++ b/gdb/python/py-tui.c @@ -509,7 +509,7 @@ gdbpy_tui_title (PyObject *self, void *closure) { gdbpy_tui_window *win = (gdbpy_tui_window *) self; REQUIRE_WINDOW (win); - return host_string_to_python_string (win->window->title.c_str ()).release (); + return host_string_to_python_string (win->window->title ().c_str ()).release (); } /* Set the title of the TUI window. */ diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c index abd2ec2b5fd..fc90df25ddd 100644 --- a/gdb/tui/tui-data.c +++ b/gdb/tui/tui-data.c @@ -155,11 +155,11 @@ tui_prev_win (struct tui_win_info *cur_win) /* See tui-data.h. */ void -tui_win_info::set_title (const char *new_title) +tui_win_info::set_title (std::string &&new_title) { - if (title != new_title) + if (m_title != new_title) { - title = new_title; + m_title = new_title; check_and_display_highlight_if_needed (); } } diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index 030ce2a5438..d0e8d56fa07 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -148,7 +148,11 @@ struct tui_win_info /* A helper function to change the title and then redraw the surrounding box, if needed. */ - void set_title (const char *new_title); + void set_title (std::string &&new_title); + + /* Return a reference to the current window title. */ + const std::string &title () const + { return m_title; } /* Window handle. */ std::unique_ptr<WINDOW, curses_deleter> handle; @@ -160,9 +164,6 @@ struct tui_win_info int x = 0; int y = 0; - /* Window title to display. */ - std::string title; - /* Is this window highlighted? */ bool is_highlighted = false; @@ -175,6 +176,10 @@ struct tui_win_info /* Scroll the contents horizontally. This is only called via left_scroll and right_scroll. */ virtual void do_scroll_horizontal (int num_to_scroll) = 0; + +private: + /* Window title to display. */ + std::string m_title; }; /* Constant definitions. */ diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 3a8fcfa5d27..1a351e60cee 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -210,7 +210,7 @@ tui_data_window::show_register_group (const reggroup *group, int regnum, pos; /* Make a new title showing which group we display. */ - title = string_printf ("Register group: %s", group->name ()); + this->set_title (string_printf ("Register group: %s", group->name ())); /* See how many registers must be displayed. */ nr_regs = 0; diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c index 55cde258882..6625f0cf088 100644 --- a/gdb/tui/tui-source.c +++ b/gdb/tui/tui-source.c @@ -65,7 +65,7 @@ tui_source_window::set_contents (struct gdbarch *arch, int cur_line_no, cur_line; const char *s_filename = symtab_to_filename_for_display (s); - title = s_filename; + set_title (s_filename); m_fullname = make_unique_xstrdup (symtab_to_fullname (s)); diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c index 2b63499683e..5e1b3d2e62e 100644 --- a/gdb/tui/tui-wingeneral.c +++ b/gdb/tui/tui-wingeneral.c @@ -102,19 +102,19 @@ box_win (struct tui_win_info *win_info, tui_border_hline, tui_border_hline, tui_border_ulcorner, tui_border_urcorner, tui_border_llcorner, tui_border_lrcorner); - if (!win_info->title.empty ()) + if (!win_info->title ().empty ()) { /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on the left. */ int max_len = win_info->width - 2 - 2; - if (win_info->title.size () <= max_len) - mvwaddstr (win, 0, 2, win_info->title.c_str ()); + if (win_info->title ().size () <= max_len) + mvwaddstr (win, 0, 2, win_info->title ().c_str ()); else { std::string truncated - = "..." + win_info->title.substr (win_info->title.size () - - max_len + 3); + = "..." + win_info->title ().substr (win_info->title ().size () + - max_len + 3); mvwaddstr (win, 0, 2, truncated.c_str ()); } }
diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c index 84a435ead68..c52b04f9a51 100644 --- a/gdb/python/py-tui.c +++ b/gdb/python/py-tui.c @@ -531,7 +531,7 @@ gdbpy_tui_set_title (PyObject *self, PyObject *newvalue, void *closure) if (value == nullptr) return -1; - win->window->title = value.get (); + win->window->set_title (value.get ()); return 0; } diff --git a/gdb/testsuite/gdb.python/tui-window.exp b/gdb/testsuite/gdb.python/tui-window.exp index 9b5d17c35d4..defc8c68b25 100644 --- a/gdb/testsuite/gdb.python/tui-window.exp +++ b/gdb/testsuite/gdb.python/tui-window.exp @@ -54,6 +54,10 @@ Term::check_contents "error message after trying to delete title" \ Term::check_contents "title is unchanged" \ "This Is The Title" +Term::command "python change_window_title ()" +Term::check_contents "test new title" \ + "New Title" + Term::resize 51 51 # Remember that a resize request actually does two resizes... Term::check_contents "Window was updated" "Test: 2" diff --git a/gdb/testsuite/gdb.python/tui-window.py b/gdb/testsuite/gdb.python/tui-window.py index 401cb5197ff..dc72cc4c0f7 100644 --- a/gdb/testsuite/gdb.python/tui-window.py +++ b/gdb/testsuite/gdb.python/tui-window.py @@ -53,4 +53,9 @@ def failwin(win): raise RuntimeError("Whoops") +# Change the title of the window. +def change_window_title(): + the_window.win.title = "New Title" + + gdb.register_window_type("fail", failwin) diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c index 0daed32b6e6..abd2ec2b5fd 100644 --- a/gdb/tui/tui-data.c +++ b/gdb/tui/tui-data.c @@ -152,6 +152,17 @@ tui_prev_win (struct tui_win_info *cur_win) return *iter; } +/* See tui-data.h. */ + +void +tui_win_info::set_title (const char *new_title) +{ + if (title != new_title) + { + title = new_title; + check_and_display_highlight_if_needed (); + } +} void tui_win_info::rerender () diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h index c92e85c9da1..030ce2a5438 100644 --- a/gdb/tui/tui-data.h +++ b/gdb/tui/tui-data.h @@ -146,6 +146,10 @@ struct tui_win_info void check_and_display_highlight_if_needed (); + /* A helper function to change the title and then redraw the + surrounding box, if needed. */ + void set_title (const char *new_title); + /* Window handle. */ std::unique_ptr<WINDOW, curses_deleter> handle; /* Window width. */