More updated translations
[binutils-gdb.git] / gdb / tui / tui-interp.c
blob25761befc65186a8960921acce1d53c305a7d6db
1 /* TUI Interpreter definitions for GDB, the GNU debugger.
3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "cli/cli-interp.h"
21 #include "interps.h"
22 #include "ui.h"
23 #include "event-top.h"
24 #include "ui-out.h"
25 #include "cli-out.h"
26 #include "tui/tui-win.h"
27 #include "tui/tui.h"
28 #include "tui/tui-io.h"
29 #include "inferior.h"
30 #include "main.h"
32 /* Set to true when the TUI mode must be activated when we first start
33 gdb. */
34 static bool tui_start_enabled = false;
36 class tui_interp final : public cli_interp_base
38 public:
39 explicit tui_interp (const char *name)
40 : cli_interp_base (name)
43 void init (bool top_level) override;
44 void resume () override;
45 void suspend () override;
46 void exec (const char *command_str) override;
47 ui_out *interp_ui_out () override;
49 bool supports_new_ui () const override
50 { return false; }
53 /* Cleanup the tui before exiting. */
55 static void
56 tui_exit (void)
58 /* Disable the tui. Curses mode is left leaving the screen in a
59 clean state (see endwin()). */
60 tui_disable ();
63 /* These implement the TUI interpreter. */
65 void
66 tui_interp::init (bool top_level)
68 /* Install exit handler to leave the screen in a good shape. */
69 atexit (tui_exit);
71 tui_initialize_io ();
72 if (gdb_stdout->isatty ())
74 tui_ensure_readline_initialized ();
76 /* This installs the SIGWINCH signal handler. The handler needs to do
77 readline calls (to rl_resize_terminal), so it must not be installed
78 unless readline is properly initialized. */
79 tui_initialize_win ();
83 /* Used as the command handler for the tui. */
85 static void
86 tui_command_line_handler (gdb::unique_xmalloc_ptr<char> &&rl)
88 /* When a tui enabled GDB is running in either tui mode or cli mode then
89 it is always the tui interpreter that is in use. As a result we end
90 up in here even in standard cli mode.
92 We only need to do any special actions when the tui is in use
93 though. When the tui is active the users return is not echoed to the
94 screen as a result the display will not automatically move us to the
95 next line. Here we manually insert a newline character and move the
96 cursor. */
97 if (tui_active)
98 tui_inject_newline_into_command_window ();
100 /* Now perform GDB's standard CLI command line handling. */
101 command_line_handler (std::move (rl));
104 void
105 tui_interp::resume ()
107 struct ui *ui = current_ui;
108 struct ui_file *stream;
110 /* gdb_setup_readline will change gdb_stdout. If the TUI was
111 previously writing to gdb_stdout, then set it to the new
112 gdb_stdout afterwards. */
114 stream = tui_old_uiout->set_stream (gdb_stdout);
115 if (stream != gdb_stdout)
117 tui_old_uiout->set_stream (stream);
118 stream = NULL;
121 gdb_setup_readline (1);
123 ui->input_handler = tui_command_line_handler;
125 if (stream != NULL)
126 tui_old_uiout->set_stream (gdb_stdout);
128 if (tui_start_enabled)
129 tui_enable ();
132 void
133 tui_interp::suspend ()
135 gdb_disable_readline ();
136 tui_start_enabled = tui_active;
137 tui_disable ();
140 ui_out *
141 tui_interp::interp_ui_out ()
143 if (tui_active)
144 return tui_out;
145 else
146 return tui_old_uiout;
149 void
150 tui_interp::exec (const char *command_str)
152 internal_error (_("tui_exec called"));
156 /* Factory for TUI interpreters. */
158 static struct interp *
159 tui_interp_factory (const char *name)
161 return new tui_interp (name);
164 void _initialize_tui_interp ();
165 void
166 _initialize_tui_interp ()
168 interp_factory_register (INTERP_TUI, tui_interp_factory);
170 if (interpreter_p == INTERP_TUI)
171 tui_start_enabled = true;
173 if (interpreter_p == INTERP_CONSOLE)
174 interpreter_p = INTERP_TUI;
176 /* There are no observers here because the CLI interpreter's
177 observers work for the TUI interpreter as well. See
178 cli-interp.c. */