24#include "gdbsupport/event-loop.h"
43#include "gdbsupport/filestuff.h"
48#include "gdbsupport/gdb-checked-static-cast.h"
53#include "readline/readline.h"
56static SHORT ncurses_norm_attr;
70 ((c) < control_character_threshold && (((c) & 0x80) == 0))
106#define TUI_USE_PIPE_FOR_READLINE
134#ifdef TUI_USE_PIPE_FOR_READLINE
135static int tui_readline_pipe[2];
156 while ((col % 8) != 0);
240 if (init_color (next, rgb[0] * 1000 / 255, rgb[1] * 1000 / 255,
241 rgb[2] * 1000 / 255) == ERR)
247 *result = it->second;
284 if (next >= COLOR_PAIRS)
286 init_pair (next, fg, bg);
299 wattron (w, A_NORMAL);
300 wattroff (w, A_BOLD);
302 wattroff (w, A_REVERSE);
305 wattron (w, COLOR_PAIR (0));
320 fgi = ncurses_norm_attr & 15;
322 bgi = (ncurses_norm_attr >> 4) & 15;
327 wattron (w, COLOR_PAIR (pair));
332 switch (style.get_intensity ())
346 gdb_assert_not_reached (
"invalid intensity");
349 if (style.is_reverse ())
350 wattron (w, A_REVERSE);
367 if (!style.parse (buf, &n_read))
393 if (!style.is_default ())
402 style.set_reverse (
true);
436 style.set_reverse (reverse);
449 std::string copy (buf, length);
465 const char *next = strpbrk (
string,
"\n\1\2\033\t");
468 size_t n_chars = next ==
nullptr ? strlen (
string) : next - string;
470 waddnstr (w,
string, n_chars);
506 gdb_assert_not_reached (
"missing case in tui_puts");
523 while ((c = *
string++) != 0)
528 if (c ==
'\1' || c ==
'\2')
540 string =
string + bytes_read - 1;
546 if (height !=
nullptr)
548 int col = getcurx (w);
589 prompt = rl_display_prompt;
595 wmove (w, start_line, 0);
598 if (prompt !=
nullptr)
601 prev_col = getcurx (w);
602 for (in = 0; in <= rl_end; in++)
608 getyx (w, c_line, c_pos);
614 c = (
unsigned char) rl_line_buffer[in];
618 waddch (w,
CTRL_CHAR (c) ? UNCTRL (c) :
'?');
628 }
while ((col % 8) != 0);
644 wmove (w, c_line, c_pos);
657#ifdef NCURSES_MOUSE_VERSION
658 mousemask (ALL_MOUSE_EVENTS, NULL);
667#ifdef NCURSES_MOUSE_VERSION
672#ifdef TUI_USE_PIPE_FOR_READLINE
676tui_readline_output (
int error, gdb_client_data data)
681 size =
read (tui_readline_pipe[0], buf,
sizeof (buf) - 1);
728 int cur_y = getcury (w);
753 int r = wgetch (win);
776 rl_getc_func_t *prev = rl_getc_function;
782 rl_getc_function = prev;
794 rl_get_screen_size (&displayer.
height, &displayer.
width);
817 extern int _rl_echoing_p;
841 rl_already_prompted = 0;
878 rl_already_prompted = 0;
894tui_cont_sig (
int sig)
905 signal (sig, tui_cont_sig);
914 signal (SIGCONT, tui_cont_sig);
926#ifdef TUI_USE_PIPE_FOR_READLINE
930 if (gdb_pipe_cloexec (tui_readline_pipe) != 0)
931 error (_(
"Cannot create pipe for readline"));
935 error (_(
"Cannot redirect readline output"));
940 (void) fcntl (tui_readline_pipe[0], F_SETFL, O_NONBLOCK);
943 (void) fcntl (tui_readline_pipe[0], F_SETFL, O_NDELAY);
946 add_file_handler (tui_readline_pipe[0], tui_readline_output, 0,
"tui");
954 HANDLE
hstdout = (HANDLE)_get_osfhandle (fileno (stdout));
956 CONSOLE_SCREEN_BUFFER_INFO csbi;
958 if (
hstdout != INVALID_HANDLE_VALUE
959 && GetConsoleMode (
hstdout, &cmode) != 0
960 && GetConsoleScreenBufferInfo (
hstdout, &csbi))
961 ncurses_norm_attr = csbi.wAttributes;
967#ifdef NCURSES_MOUSE_VERSION
970tui_dispatch_mouse_event ()
973 if (getmouse (&mev) != OK)
977 if (mev.x > wi->x && mev.x < wi->x + wi->
width - 1
978 && mev.y > wi->y && mev.y < wi->y + wi->
height - 1)
980 if ((mev.bstate & BUTTON1_CLICKED) != 0
981 || (mev.bstate & BUTTON2_CLICKED) != 0
982 || (mev.bstate & BUTTON3_CLICKED) != 0)
984 int button = (mev.bstate & BUTTON1_CLICKED) != 0 ? 1
985 : ((mev.bstate & BUTTON2_CLICKED) != 0 ? 2
987 wi->click (mev.x - wi->x - 1, mev.y - wi->y - 1, button);
989#ifdef BUTTON5_PRESSED
990 else if ((mev.bstate & BUTTON4_PRESSED) != 0)
991 wi->backward_scroll (3);
992 else if ((mev.bstate & BUTTON5_PRESSED) != 0)
993 wi->forward_scroll (3);
1010 if (win_info == NULL || !win_info->
can_scroll ())
1062 wmove (w, getcury (w), 0);
1077 px += rl_end - rl_point;
1115#ifdef TUI_USE_PIPE_FOR_READLINE
1117 tui_readline_output (0, 0);
1145#ifdef NCURSES_MOUSE_VERSION
1146 if (ch == KEY_MOUSE)
1148 tui_dispatch_mouse_event ();
1190#if defined __MINGW32__
1201 auto name = gdb::string_view (keyname (ch));
1207 if (
name ==
"kLFT5")
1209 else if (
name ==
"kRIT5")
1211 else if (
name ==
"kDC5")
1215 else if (
name ==
"kLFT3")
1217 else if (
name ==
"kRIT3")
1229 if (ch == KEY_BACKSPACE)
1251 if (ch_pending != ERR)
1253 ungetch (ch_pending);
1278 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)
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)