From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 2/3] [gdb/tui] Factor out init_ncurses
Date: Mon, 11 May 2026 12:35:48 +0200 [thread overview]
Message-ID: <20260511103549.2641036-3-tdevries@suse.de> (raw)
In-Reply-To: <20260511103549.2641036-1-tdevries@suse.de>
Factor out init_ncurses out of tui_enable, and make sure calling it twice is
harmless.
---
gdb/tui/tui.c | 43 ++++++++++++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index c1457e148a2..11bcba813bc 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -428,6 +428,34 @@ require_tui_terminal ()
#endif
}
+/* Initialize ncurses, if necessary. */
+
+static SCREEN *
+init_ncurses ()
+{
+ static SCREEN *tui_screen = nullptr;
+ if (tui_screen != nullptr)
+ {
+ /* Init ncurses only once. */
+ return tui_screen;
+ }
+
+ tui_screen = newterm (nullptr, stdout, stdin);
+
+#ifdef __MINGW32__
+ /* The MinGW port of ncurses requires $TERM to be unset in order
+ to activate the Windows console driver. */
+ if (tui_screen == nullptr)
+ tui_screen = newterm ((char *) "unknown", stdout, stdin);
+#endif
+
+ if (tui_screen == nullptr)
+ error (_("Cannot enable the TUI: error opening terminal [TERM=%s]"),
+ gdb_getenv_term ());
+
+ return tui_screen;
+}
+
/* Enter in the tui mode (curses).
When in normal mode, it installs the tui hooks in gdb, redirects
the gdb output, configures the readline to work in tui mode.
@@ -455,7 +483,6 @@ tui_enable (void)
if (tui_finish_init == TRIBOOL_TRUE)
{
WINDOW *w;
- SCREEN *s;
/* If the top level interpreter is not the console/tui (e.g.,
MI), enabling curses will certainly lose. */
@@ -467,19 +494,9 @@ tui_enable (void)
/* Don't try initialization again. */
tui_finish_init = TRIBOOL_UNKNOWN;
- s = newterm (NULL, stdout, stdin);
-#ifdef __MINGW32__
- /* The MinGW port of ncurses requires $TERM to be unset in order
- to activate the Windows console driver. */
- if (s == NULL)
- s = newterm ((char *) "unknown", stdout, stdin);
-#endif
- if (s == NULL)
- {
- error (_("Cannot enable the TUI: error opening terminal [TERM=%s]"),
- gdb_getenv_term ());
- }
+ SCREEN *s = init_ncurses ();
w = stdscr;
+
if (has_colors ())
{
#ifdef HAVE_USE_DEFAULT_COLORS
--
2.51.0
next prev parent reply other threads:[~2026-05-11 10:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 10:35 [PATCH v2 0/3] [gdb/tui] Allow second tui enable if first fails Tom de Vries
2026-05-11 10:35 ` [PATCH v2 1/3] [gdb/tui] Factor out require_tui_terminal Tom de Vries
2026-05-11 10:35 ` Tom de Vries [this message]
2026-05-11 10:35 ` [PATCH v2 3/3] [gdb/tui] Allow second tui enable if first fails Tom de Vries
2026-05-19 18:52 ` [PATCH v2 0/3] " Tom Tromey
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=20260511103549.2641036-3-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/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