summaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorStephane Carrez <stcarrez@nerim.fr>2002-08-31 12:02:14 +0000
committerStephane Carrez <stcarrez@nerim.fr>2002-08-31 12:02:14 +0000
commite5513c40917cc9e14bc9523c0e64b4985261ead8 (patch)
tree7f85b520dface97d1703033c485febeeea6ab50c /gdb/tui
parent9981f738e5624efb7688cdcf4314aa27336c995c (diff)
downloadgdb-e5513c40917cc9e14bc9523c0e64b4985261ead8.tar.gz
2002-08-31 Stephane Carrez <stcarrez@nerim.fr>
* tui.c (tui_commands): Table of single key commands. (tui_rl_command_key): New function to execute gdb command. (tui_rl_command_mode): New function to temporarily leave SingleKey. (tui_rl_next_keymap): New function to enter/leave the SingleKey mode. (tui_rl_startup_hook): New function to avoid prompt display by readline functions. (tui_set_key_mode): New function to set the key mode and install the readline keymap. (tui_initialize_readline): Create TUI SingleKey readline map. (tui_enable): Install rl_startup_hook. (tui_disable): Remove it. * tui.h (enum tui_key_mode): Declare. (tui_set_key_mode, tui_current_key_mode): Declare. * tuiIO.c (tui_redisplay_readline): Don't display the prompt in SingleKey mode. * tuiIO.h (tui_redisplay_readline): Declare.
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/ChangeLog19
-rw-r--r--gdb/tui/tui.c140
-rw-r--r--gdb/tui/tui.h17
-rw-r--r--gdb/tui/tuiIO.c8
-rw-r--r--gdb/tui/tuiIO.h7
5 files changed, 187 insertions, 4 deletions
diff --git a/gdb/tui/ChangeLog b/gdb/tui/ChangeLog
index 04e94bf9c59..514c4143e62 100644
--- a/gdb/tui/ChangeLog
+++ b/gdb/tui/ChangeLog
@@ -1,5 +1,24 @@
2002-08-31 Stephane Carrez <stcarrez@nerim.fr>
+ * tui.c (tui_commands): Table of single key commands.
+ (tui_rl_command_key): New function to execute gdb command.
+ (tui_rl_command_mode): New function to temporarily leave SingleKey.
+ (tui_rl_next_keymap): New function to enter/leave the SingleKey mode.
+ (tui_rl_startup_hook): New function to avoid prompt display by
+ readline functions.
+ (tui_set_key_mode): New function to set the key mode and install
+ the readline keymap.
+ (tui_initialize_readline): Create TUI SingleKey readline map.
+ (tui_enable): Install rl_startup_hook.
+ (tui_disable): Remove it.
+ * tui.h (enum tui_key_mode): Declare.
+ (tui_set_key_mode, tui_current_key_mode): Declare.
+ * tuiIO.c (tui_redisplay_readline): Don't display the prompt in
+ SingleKey mode.
+ * tuiIO.h (tui_redisplay_readline): Declare.
+
+2002-08-31 Stephane Carrez <stcarrez@nerim.fr>
+
* tuiSourceWin.c (tuiSetIsExecPointAt): Redraw the previous and
current line.
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index ab2c201fba6..bb2590af2dd 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -72,7 +72,33 @@
int tui_active = 0;
static int tui_finish_init = 1;
-/* Switch the output mode between TUI/standard gdb. */
+enum tui_key_mode tui_current_key_mode = tui_command_mode;
+
+struct tui_char_command
+{
+ unsigned char key;
+ const char* cmd;
+};
+
+/* Key mapping to gdb commands when the TUI is using the single key mode. */
+static const struct tui_char_command tui_commands[] = {
+ { 'c', "continue" },
+ { 'd', "down" },
+ { 'f', "finish" },
+ { 'n', "next" },
+ { 'r', "run" },
+ { 's', "step" },
+ { 'u', "up" },
+ { 'v', "info locals" },
+ { 'w', "where" },
+ { 0, 0 },
+};
+
+static Keymap tui_keymap;
+static Keymap tui_readline_standard_keymap;
+
+/* TUI readline command.
+ Switch the output mode between TUI/standard gdb. */
static int
tui_rl_switch_mode (void)
{
@@ -193,19 +219,128 @@ tui_rl_delete_other_windows (void)
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)
+ {
+ /* Must save the command because it can be modified
+ by execute_command. */
+ char* cmd = alloca (strlen (tui_commands[i].cmd) + 1);
+ strcpy (cmd, tui_commands[i].cmd);
+ execute_command (cmd, TRUE);
+ 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 (void)
+{
+ 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 ()
+{
+ rl_already_prompted = (tui_current_key_mode != tui_command_mode);
+ if (rl_already_prompted)
+ {
+ 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);
+ tuiShowLocatorContent ();
+}
+
/* Initialize readline and configure the keymap for the switching
key shortcut. */
void
tui_initialize_readline ()
{
+ int i;
+ Keymap tui_ctlx_keymap;
+
rl_initialize ();
rl_add_defun ("tui-switch-mode", tui_rl_switch_mode, -1);
+ rl_add_defun ("gdb-command", tui_rl_command_key, -1);
+ rl_add_defun ("next-keymap", tui_rl_next_keymap, -1);
+
+ tui_keymap = rl_make_bare_keymap ();
+ tui_ctlx_keymap = rl_make_bare_keymap ();
+ tui_readline_standard_keymap = rl_get_keymap ();
+
+ for (i = 0; tui_commands[i].cmd; i++)
+ rl_bind_key_in_map (tui_commands[i].key, tui_rl_command_key, tui_keymap);
+
+ rl_generic_bind (ISKMAP, "\\C-x", (char*) tui_ctlx_keymap, tui_keymap);
+
+ /* Bind all other keys to tui_rl_command_mode so that we switch
+ temporarily from SingleKey mode and can enter a gdb command. */
+ for (i = ' ' + 1; i < 0x7f; i++)
+ {
+ int j;
+
+ for (j = 0; tui_commands[j].cmd; j++)
+ if (tui_commands[j].key == i)
+ break;
+
+ if (tui_commands[j].cmd)
+ continue;
+
+ rl_bind_key_in_map (i, tui_rl_command_mode, tui_keymap);
+ }
+
rl_bind_key_in_map ('a', tui_rl_switch_mode, emacs_ctlx_keymap);
+ rl_bind_key_in_map ('a', tui_rl_switch_mode, tui_ctlx_keymap);
rl_bind_key_in_map ('A', tui_rl_switch_mode, emacs_ctlx_keymap);
+ rl_bind_key_in_map ('A', tui_rl_switch_mode, tui_ctlx_keymap);
rl_bind_key_in_map (CTRL ('A'), tui_rl_switch_mode, emacs_ctlx_keymap);
+ rl_bind_key_in_map (CTRL ('A'), tui_rl_switch_mode, tui_ctlx_keymap);
rl_bind_key_in_map ('1', tui_rl_delete_other_windows, emacs_ctlx_keymap);
+ rl_bind_key_in_map ('1', tui_rl_delete_other_windows, tui_ctlx_keymap);
rl_bind_key_in_map ('2', tui_rl_change_windows, emacs_ctlx_keymap);
+ rl_bind_key_in_map ('2', tui_rl_change_windows, tui_ctlx_keymap);
+ rl_bind_key_in_map ('q', tui_rl_next_keymap, tui_keymap);
+ rl_bind_key_in_map ('s', tui_rl_next_keymap, emacs_ctlx_keymap);
+ rl_bind_key_in_map ('s', tui_rl_next_keymap, tui_ctlx_keymap);
}
/* Enter in the tui mode (curses).
@@ -255,6 +390,7 @@ tui_enable (void)
/* Install the TUI specific hooks. */
tui_install_hooks ();
+ rl_startup_hook = tui_rl_startup_hook;
tui_update_variables ();
@@ -284,6 +420,8 @@ tui_disable (void)
/* Remove TUI hooks. */
tui_remove_hooks ();
+ rl_startup_hook = 0;
+ rl_already_prompted = 0;
/* Leave curses and restore previous gdb terminal setting. */
endwin ();
diff --git a/gdb/tui/tui.h b/gdb/tui/tui.h
index 9cc538d1568..e6cb4b866f1 100644
--- a/gdb/tui/tui.h
+++ b/gdb/tui/tui.h
@@ -102,6 +102,23 @@ extern void tui_enable (void);
/* Leave the tui mode. */
extern void tui_disable (void);
+enum tui_key_mode
+{
+ /* Plain command mode to enter gdb commands. */
+ tui_command_mode,
+
+ /* SingleKey mode with some keys bound to gdb commands. */
+ tui_single_key_mode,
+
+ /* Read/edit one command and return to SingleKey after it's processed. */
+ tui_one_command_mode
+};
+
+extern enum tui_key_mode tui_current_key_mode;
+
+/* Change the TUI key mode by installing the appropriate readline keymap. */
+extern void tui_set_key_mode (enum tui_key_mode mode);
+
extern void tui_initialize_io (void);
extern void tui_initialize_readline (void);
diff --git a/gdb/tui/tuiIO.c b/gdb/tui/tuiIO.c
index fe389af28fe..c48565ceb1f 100644
--- a/gdb/tui/tuiIO.c
+++ b/gdb/tui/tuiIO.c
@@ -44,6 +44,7 @@
#include "terminal.h"
#include "target.h"
#include "event-loop.h"
+#include "event-top.h"
#include "command.h"
#include "top.h"
#include "readline/readline.h"
@@ -151,7 +152,7 @@ tui_puts (const char *string)
/* Readline callback.
Redisplay the command line with its prompt after readline has
changed the edited text. */
-static void
+void
tui_redisplay_readline (void)
{
int prev_col;
@@ -164,7 +165,10 @@ tui_redisplay_readline (void)
char *prompt;
int start_line;
- prompt = get_prompt ();
+ if (tui_current_key_mode == tui_single_key_mode)
+ prompt = "";
+ else
+ prompt = get_prompt ();
c_pos = -1;
c_line = -1;
diff --git a/gdb/tui/tuiIO.h b/gdb/tui/tuiIO.h
index 2ad92ce81f1..49c26fd79c0 100644
--- a/gdb/tui/tuiIO.h
+++ b/gdb/tui/tuiIO.h
@@ -1,5 +1,5 @@
/* TUI support I/O functions.
- Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
Contributed by Hewlett-Packard Company.
This file is part of GDB.
@@ -36,6 +36,11 @@ extern void tui_initialize_io (void);
/* Get a character from the command window. */
extern int tui_getc (FILE*);
+/* Readline callback.
+ Redisplay the command line with its prompt after readline has
+ changed the edited text. */
+extern void tui_redisplay_readline (void);
+
#define m_tuiStartNewLine tuiStartNewLines(1)
#define m_isStartSequence(ch) (ch == 27)