[binutils-gdb] [gdb/tui] Add tui_try_activate
Tom de Vries via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f7467b51e64686fccbd1f8229178f8af8a11a70f commit f7467b51e64686fccbd1f8229178f8af8a11a70f Author: Tom de Vries <[email protected]> Date: Thu Mar 19 10:55:46 2026 +0100 [gdb/tui] Add tui_try_activate In tui/tui.c, there this type of pattern related to activating TUI: ... static int tui_rl_delete_other_windows (int notused1, int notused2) { if (!tui_active) tui_rl_switch_mode (); if (tui_active) tui_remove_some_windows (); return 0; } ... Add a new function tui_try_activate that allows us to write the shorter: ... static int tui_rl_delete_other_windows (int notused1, int notused2) { if (tui_try_activate ()) tui_remove_some_windows (); return 0; } ... Tested on x86_64-linux. Reviewed-By: Keith Seitz <[email protected]> Diff: --- gdb/tui/tui.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index 5b322db5bdf..677a8c04b53 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -178,6 +178,18 @@ tui_rl_switch_mode (int notused1 = 0, int notused2 = 0) return 0; } +/* Try to switch into TUI mode, if not already active. Return if TUI mode + is active. */ + +static bool +tui_try_activate () +{ + if (!tui_active) + tui_rl_switch_mode (); + + return tui_active; +} + /* TUI readline command. Change the TUI layout to show a next layout. This function is bound to CTRL-X 2. It is intended to provide @@ -185,10 +197,7 @@ tui_rl_switch_mode (int notused1 = 0, int notused2 = 0) static int tui_rl_change_windows (int notused1, int notused2) { - if (!tui_active) - tui_rl_switch_mode (); - - if (tui_active) + if (tui_try_activate ()) tui_next_layout (); return 0; @@ -199,10 +208,7 @@ tui_rl_change_windows (int notused1, int notused2) static int tui_rl_delete_other_windows (int notused1, int notused2) { - if (!tui_active) - tui_rl_switch_mode (); - - if (tui_active) + if (tui_try_activate ()) tui_remove_some_windows (); return 0; @@ -213,8 +219,7 @@ tui_rl_delete_other_windows (int notused1, int notused2) static int tui_rl_other_window (int count, int key) { - if (!tui_active) - tui_rl_switch_mode (); + tui_try_activate (); tui_set_win_focus_to (tui_next_win (tui_win_with_focus ())); @@ -266,8 +271,7 @@ tui_rl_command_mode (int count, int key) static int tui_rl_next_keymap (int notused1, int notused2) { - if (!tui_active) - tui_rl_switch_mode (); + tui_try_activate (); if (rl_end) {