Index: tui.c =================================================================== RCS file: /cvs/src/src/gdb/tui/tui.c,v retrieving revision 1.21 diff -u -p -r1.21 tui.c --- tui.c 25 Aug 2002 21:44:41 -0000 1.21 +++ tui.c 25 Aug 2002 22:02:55 -0000 @@ -72,7 +72,35 @@ int tui_active = 0; static int tui_finish_init = 1; -/* Switch the output mode between TUI/standard gdb. */ +int tui_single_key_mode = 0; + +struct tui_char_command +{ + unsigned char key; + char* cmd; +}; + +/* Key mapping to gdb commands when the TUI is using the single key mode. */ +struct tui_char_command tui_commands[] = { + { 's', "step" }, + { 'n', "next" }, + { 'c', "continue" }, + { 'u', "up" }, + { 'd', "down" }, + { 'f', "finish" }, + { 'r', "run" }, + { 'v', "info locals" }, + { 'w', "where" }, + { 0, 0 }, +}; + +static Keymap tui_keymap; +static Keymap tui_ctlx_keymap; +static Keymap tui_readline_standard_keymap; +static Keymap tui_readline_ctrlx_keymap; + +/* TUI readline command. + Switch the output mode between TUI/standard gdb. */ static int tui_rl_switch_mode (void) { @@ -193,19 +221,132 @@ 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) + { + execute_command (tui_commands[i].cmd, TRUE); + return 0; + } + } + return 0; +} + +/* TUI readline command. + Temporarily leave the TUI fast key mode to allow editing + of a gdb command with the normal readline. Once the command + is executed, the TUI fast key mode is installed back. */ +static int +tui_rl_command_mode (int count, int key) +{ + tui_single_key_mode = 2; + rl_set_keymap (tui_readline_standard_keymap); + tuiShowLocatorContent (); + return rl_insert (count, key); +} + + +/* TUI readline command. + Switch between TUI fast key mode and gdb readline editing. */ +static int +tui_rl_next_keymap (void) +{ + if (tui_single_key_mode == 0) + tui_enter_key_mode (); + else + tui_leave_key_mode (); + tuiShowLocatorContent (); + return 0; +} + +int +tui_rl_startup_hook () +{ + rl_already_prompted = (tui_single_key_mode != 0); + if (rl_already_prompted) + { + tui_single_key_mode = 1; + tui_redisplay_readline (); + } + return 0; +} + +/* Enter in the TUI fast key mode. */ +void +tui_enter_key_mode () +{ + tui_single_key_mode = 1; + rl_set_keymap (tui_keymap); + tuiShowLocatorContent (); +} + +/* Leave the TUI fast key mode to use the gdb plain readline. */ +void +tui_leave_key_mode () +{ + tui_single_key_mode = 0; + rl_set_keymap (tui_readline_standard_keymap); +} + /* Initialize readline and configure the keymap for the switching key shortcut. */ void tui_initialize_readline () { + int i; + 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 (); + + 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); + + 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); + + tui_readline_standard_keymap = rl_get_keymap (); + tui_readline_ctrlx_keymap = rl_make_bare_keymap (); + + rl_bind_key_in_map ('x', tui_rl_next_keymap, tui_keymap); + rl_bind_key_in_map (CTRL ('O'), tui_rl_next_keymap, emacs_ctlx_keymap); } /* Enter in the tui mode (curses). @@ -255,6 +396,7 @@ tui_enable (void) /* Install the TUI specific hooks. */ tui_install_hooks (); + rl_startup_hook = tui_rl_startup_hook; tui_update_variables (); @@ -281,6 +423,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 (); Index: tui.h =================================================================== RCS file: /cvs/src/src/gdb/tui/tui.h,v retrieving revision 1.14 diff -u -p -r1.14 tui.h --- tui.h 25 Aug 2002 19:19:50 -0000 1.14 +++ tui.h 25 Aug 2002 22:02:55 -0000 @@ -84,6 +84,8 @@ TuiWinType, *TuiWinTypePtr; } TuiPoint, *TuiPointPtr; +extern int tui_single_key_mode; + /* GENERAL TUI FUNCTIONS */ /* tui.c */ extern void tuiFree (char *); @@ -101,6 +103,12 @@ extern void tui_enable (void); /* Leave the tui mode. */ extern void tui_disable (void); + +/* Leave the TUI fast key mode to use the gdb plain readline. */ +extern void tui_leave_key_mode (void); + +/* Enter in the TUI fast key mode. */ +extern void tui_enter_key_mode (void); extern void tui_initialize_io (void); Index: tuiIO.c =================================================================== RCS file: /cvs/src/src/gdb/tui/tuiIO.c,v retrieving revision 1.12 diff -u -p -r1.12 tuiIO.c --- tuiIO.c 1 Mar 2002 06:19:28 -0000 1.12 +++ tuiIO.c 25 Aug 2002 22:02:55 -0000 @@ -55,6 +55,7 @@ #include "tuiGeneralWin.h" #include "tui-file.h" #include "ui-out.h" +#include "event-top.h" #include "cli-out.h" #include #include @@ -144,10 +145,17 @@ tui_puts (const char *string) fflush (stdout); } +static void +tui_after_char_processing_restart_key_mode (void) +{ + after_char_processing_hook = 0; + tui_enter_key_mode (); +} + /* 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; @@ -160,7 +168,10 @@ tui_redisplay_readline (void) char *prompt; int start_line; - prompt = get_prompt (); + if (tui_single_key_mode == 1) + prompt = ""; + else + prompt = get_prompt (); c_pos = -1; c_line = -1; @@ -432,7 +443,10 @@ tui_getc (FILE *fp) { /* Handle prev/next/up/down here */ ch = tuiDispatchCtrlChar (ch); } - + + if (ch == '\n' && tui_single_key_mode == 2) + after_char_processing_hook = tui_after_char_processing_restart_key_mode; + if (ch == '\n' || ch == '\r' || ch == '\f') cmdWin->detail.commandInfo.curch = 0; #if 0