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 <keiths@redhat.com>
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
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;
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;
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 ()));
static int
tui_rl_next_keymap (int notused1, int notused2)
{
- if (!tui_active)
- tui_rl_switch_mode ();
+ tui_try_activate ();
if (rl_end)
{