+/* TUI readline command.
+ Switch the active window to give the focus to a next window. */
+static int
+tui_rl_other_window (int count, int key)
+{
+ struct tui_win_info *win_info;
+
+ if (!tui_active)
+ tui_rl_switch_mode (0 /* notused */, 0 /* notused */);
+
+ win_info = tui_next_win (tui_win_with_focus ());
+ if (win_info)
+ {
+ tui_set_win_focus_to (win_info);
+ if (TUI_DATA_WIN && TUI_DATA_WIN->generic.is_visible)
+ tui_refresh_data_win ();
+ keypad (TUI_CMD_WIN->generic.handle, (win_info != TUI_CMD_WIN));
+ }
+ return 0;
+}
+
+/* TUI readline command.
+ Execute the gdb command bound to the specified key. */
+static int
+tui_rl_command_key (int count, int key)
+{
+ int i;
+
+ reinitialize_more_filter ();
+ for (i = 0; tui_commands[i].cmd; i++)
+ {
+ if (tui_commands[i].key == key)
+ {
+ /* Insert the command in the readline buffer.
+ Avoid calling the gdb command here since it creates
+ a possible recursion on readline if prompt_for_continue
+ is called (See PR 9584). The command will also appear
+ in the readline history which turns out to be better. */
+ rl_insert_text (tui_commands[i].cmd);
+ rl_newline (1, '\n');
+
+ /* Switch to gdb command mode while executing the command.
+ This way the gdb's continue prompty will be displayed. */
+ tui_set_key_mode (TUI_ONE_COMMAND_MODE);
+ return 0;
+ }
+ }
+ return 0;
+}
+
+/* TUI readline command.
+ Temporarily leave the TUI SingleKey mode to allow editing
+ a gdb command with the normal readline. Once the command
+ is executed, the TUI SingleKey mode is installed back. */
+static int
+tui_rl_command_mode (int count, int key)
+{
+ tui_set_key_mode (TUI_ONE_COMMAND_MODE);
+ return rl_insert (count, key);
+}
+
+/* TUI readline command.
+ Switch between TUI SingleKey mode and gdb readline editing. */
+static int
+tui_rl_next_keymap (int notused1, int notused2)
+{
+ if (!tui_active)
+ tui_rl_switch_mode (0 /* notused */, 0 /* notused */);
+
+ tui_set_key_mode (tui_current_key_mode == TUI_COMMAND_MODE
+ ? TUI_SINGLE_KEY_MODE : TUI_COMMAND_MODE);
+ return 0;
+}
+
+/* Readline hook to redisplay ourself the gdb prompt.
+ In the SingleKey mode, the prompt is not printed so that
+ the command window is cleaner. It will be displayed if
+ we temporarily leave the SingleKey mode. */
+static int
+tui_rl_startup_hook (void)
+{
+ rl_already_prompted = 1;
+ if (tui_current_key_mode != TUI_COMMAND_MODE && immediate_quit == 0)
+ tui_set_key_mode (TUI_SINGLE_KEY_MODE);
+ tui_redisplay_readline ();
+ return 0;
+}
+
+/* Change the TUI key mode by installing the appropriate readline
+ keymap. */
+void
+tui_set_key_mode (enum tui_key_mode mode)
+{
+ tui_current_key_mode = mode;
+ rl_set_keymap (mode == TUI_SINGLE_KEY_MODE
+ ? tui_keymap : tui_readline_standard_keymap);
+ tui_show_locator_content ();
+}
+