24#include "gdbsupport/event-loop.h"
44#include "gdbsupport/filestuff.h"
49#include "gdbsupport/gdb-checked-static-cast.h"
54#include "readline/readline.h"
57static SHORT ncurses_norm_attr;
71 ((c) < control_character_threshold && (((c) & 0x80) == 0))
107#define TUI_USE_PIPE_FOR_READLINE
135#ifdef TUI_USE_PIPE_FOR_READLINE
136static int tui_readline_pipe[2];
157 while ((col % 8) != 0);
241 if (init_color (next, rgb[0] * 1000 / 255, rgb[1] * 1000 / 255,
242 rgb[2] * 1000 / 255) == ERR)
248 *result = it->second;
285 if (next >= COLOR_PAIRS)
287 init_pair (next, fg, bg);
300 wattron (w, A_NORMAL);
301 wattroff (w, A_BOLD);
303 wattroff (w, A_REVERSE);
306 wattron (w, COLOR_PAIR (0));
321 fgi = ncurses_norm_attr & 15;
323 bgi = (ncurses_norm_attr >> 4) & 15;
328 wattron (w, COLOR_PAIR (pair));
333 switch (style.get_intensity ())
347 gdb_assert_not_reached (
"invalid intensity");
350 if (style.is_reverse ())
351 wattron (w, A_REVERSE);
368 if (!style.parse (buf, &n_read))
394 if (!style.is_default ())
403 style.set_reverse (
true);
437 style.set_reverse (reverse);
450 std::string copy (buf, length);
466 const char *next = strpbrk (
string,
"\n\1\2\033\t");
469 size_t n_chars = next ==
nullptr ? strlen (
string) : next - string;
471 waddnstr (w,
string, n_chars);
507 gdb_assert_not_reached (
"missing case in tui_puts");
524 while ((c = *
string++) != 0)
526 if (c ==
'\1' || c ==
'\2')
538 string =
string + bytes_read - 1;
548 if (height !=
nullptr)
550 int col = getcurx (w);
591 prompt = rl_display_prompt;
597 wmove (w, start_line, 0);
600 if (prompt !=
nullptr)
603 prev_col = getcurx (w);
604 for (in = 0; in <= rl_end; in++)
610 getyx (w, c_line, c_pos);
616 c = (
unsigned char) rl_line_buffer[in];
620 waddch (w,
CTRL_CHAR (c) ? UNCTRL (c) :
'?');
630 }
while ((col % 8) != 0);
646 wmove (w, c_line, c_pos);
659#ifdef NCURSES_MOUSE_VERSION
661 mousemask (ALL_MOUSE_EVENTS, NULL);
670#ifdef NCURSES_MOUSE_VERSION
675#ifdef TUI_USE_PIPE_FOR_READLINE
679tui_readline_output (
int error, gdb_client_data data)
684 size =
read (tui_readline_pipe[0], buf,
sizeof (buf) - 1);
731 int cur_y = getcury (w);
756 int r = wgetch (win);
780 scoped_restore restore_getc_function
781 = make_scoped_restore (&rl_getc_function,
tui_mld_getc);
782 return rl_read_key ();
793 rl_get_screen_size (&displayer.
height, &displayer.
width);
816 extern int _rl_echoing_p;
840 rl_already_prompted = 0;
877 rl_already_prompted = 0;
893tui_cont_sig (
int sig)
904 signal (sig, tui_cont_sig);
913 signal (SIGCONT, tui_cont_sig);
925#ifdef TUI_USE_PIPE_FOR_READLINE
929 if (gdb_pipe_cloexec (tui_readline_pipe) != 0)
930 error (_(
"Cannot create pipe for readline"));
934 error (_(
"Cannot redirect readline output"));
939 (void) fcntl (tui_readline_pipe[0], F_SETFL, O_NONBLOCK);
942 (void) fcntl (tui_readline_pipe[0], F_SETFL, O_NDELAY);
945 add_file_handler (tui_readline_pipe[0], tui_readline_output, 0,
"tui");
953 HANDLE
hstdout = (HANDLE)_get_osfhandle (fileno (stdout));
955 CONSOLE_SCREEN_BUFFER_INFO csbi;
957 if (
hstdout != INVALID_HANDLE_VALUE
958 && GetConsoleMode (
hstdout, &cmode) != 0
959 && GetConsoleScreenBufferInfo (
hstdout, &csbi))
960 ncurses_norm_attr = csbi.wAttributes;
966#ifdef NCURSES_MOUSE_VERSION
969tui_dispatch_mouse_event ()
972 if (getmouse (&mev) != OK)
976 if (mev.x > wi->x && mev.x < wi->x + wi->
width - 1
977 && mev.y > wi->y && mev.y < wi->y + wi->
height - 1)
979 if ((mev.bstate & BUTTON1_CLICKED) != 0
980 || (mev.bstate & BUTTON2_CLICKED) != 0
981 || (mev.bstate & BUTTON3_CLICKED) != 0)
983 int button = (mev.bstate & BUTTON1_CLICKED) != 0 ? 1
984 : ((mev.bstate & BUTTON2_CLICKED) != 0 ? 2
986 wi->click (mev.x - wi->x - 1, mev.y - wi->y - 1, button);
988#ifdef BUTTON5_PRESSED
989 else if ((mev.bstate & BUTTON4_PRESSED) != 0)
990 wi->backward_scroll (3);
991 else if ((mev.bstate & BUTTON5_PRESSED) != 0)
992 wi->forward_scroll (3);
1009 if (win_info == NULL || !win_info->
can_scroll ())
1061 wmove (w, getcury (w), 0);
1076 px += rl_end - rl_point;
1114#ifdef TUI_USE_PIPE_FOR_READLINE
1116 tui_readline_output (0, 0);
1144#ifdef NCURSES_MOUSE_VERSION
1145 if (ch == KEY_MOUSE)
1147 tui_dispatch_mouse_event ();
1189#if defined __MINGW32__
1200 auto name = gdb::string_view (keyname (ch));
1206 if (
name ==
"kLFT5")
1208 else if (
name ==
"kRIT5")
1210 else if (
name ==
"kDC5")
1214 else if (
name ==
"kLFT3")
1216 else if (
name ==
"kRIT3")
1228 if (ch == KEY_BACKSPACE)
1250 if (ch_pending != ERR)
1252 ungetch (ch_pending);
1277 catch (
const gdb_exception_forced_quit &ex)
1285 catch (
const gdb_exception &ex)
void get_rgb(uint8_t *rgb) const
void gdb_display_match_list(char **matches, int len, int max, const struct match_list_displayer *displayer)
void set_force_quit_flag()
int call_stdin_event_handler_again_p
void exception_print(struct ui_file *file, const struct gdb_exception &e)
ssize_t read(int fd, void *buf, size_t count)
struct ui_file * gdb_stdtarg
struct ui_file * gdb_stdtargerr
bool operator<(const color_pair &o) const
mld_erase_entire_line_ftype * erase_entire_line
mld_read_key_ftype * read_key
void right_scroll(int num_to_scroll)
virtual bool can_scroll() const
void left_scroll(int num_to_scroll)
void backward_scroll(int num_to_scroll)
void forward_scroll(int num_to_scroll)
int gdb_in_secondary_prompt_p(struct ui *ui)
struct tui_win_info * tui_win_with_focus(void)
static std::vector< tui_win_info * > & all_tui_windows()
static const char * cur_seq
static int tui_getc(FILE *fp)
static void tui_deprep_terminal(void)
static int tui_mld_read_key(const struct match_list_displayer *displayer)
static void tui_prep_terminal(int notused1)
static int tui_old_rl_echoing_p
void tui_apply_style(WINDOW *w, ui_file_style style)
static void tui_mld_beep(const struct match_list_displayer *displayer)
static void tui_mld_putch(const struct match_list_displayer *displayer, int ch)
static FILE * tui_old_rl_outstream
static void tui_rl_display_match_list(char **matches, int len, int max)
static int tui_getc_1(FILE *fp)
static void tui_puts_internal(WINDOW *w, const char *string, int *height)
void tui_initialize_io(void)
static ui_file_style::color reverse_save_bg(ui_file_style::NONE)
static bool get_color(const ui_file_style::color &color, int *result)
static int key_is_start_sequence(int ch)
static int get_color_pair(int fg, int bg)
void tui_set_reverse_mode(WINDOW *w, bool reverse)
void tui_setup_io(int mode)
static std::map< ui_file_style::color, int > color_map
static struct ui_file * tui_stdout
static struct ui_file * tui_old_stderr
static void tui_putc(char c)
static size_t apply_ansi_escape(WINDOW *w, const char *buf)
cli_ui_out * tui_old_uiout
static rl_voidfunc_t * tui_old_rl_redisplay_function
static const int curses_colors[]
static rl_getc_func_t * tui_old_rl_getc_function
void tui_puts(const char *string, WINDOW *w)
static int tui_mld_getc(FILE *fp)
static std::map< color_pair, int > color_pair_map
static ui_file_style last_style
static rl_voidfunc_t * tui_old_rl_deprep_terminal
void tui_write(const char *buf, size_t length)
static bool reverse_mode_p
static void update_cmdwin_start_line()
static struct ui_file * tui_old_stdout
void tui_inject_newline_into_command_window()
static struct ui_file * tui_old_stdlog
static void tui_mld_puts(const struct match_list_displayer *displayer, const char *s)
static void tui_mld_erase_entire_line(const struct match_list_displayer *displayer)
static ui_file_style::color reverse_save_fg(ui_file_style::NONE)
static int start_sequence(const char *seq)
static FILE * tui_rl_outstream
static struct ui_file * tui_stderr
static void do_tui_putc(WINDOW *w, char c)
static unsigned int tui_dispatch_ctrl_char(unsigned int ch)
static rl_vintfunc_t * tui_old_rl_prep_terminal
static void tui_mld_flush(const struct match_list_displayer *displayer)
static int last_color_pair
static struct ui_file * tui_stdlog
static void tui_mld_crlf(const struct match_list_displayer *displayer)
static rl_compdisp_func_t * tui_old_rl_display_matches_hook
void tui_redisplay_readline(void)
static int gdb_wgetch(WINDOW *win)
bool style_tui_current_position
void tui_refresh_all_win(void)
void tui_ensure_readline_initialized()
enum tui_key_mode tui_current_key_mode
void tui_set_key_mode(enum tui_key_mode mode)