1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999-2018 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions.
6 Written by Fernando Nasser for Cygnus.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "completer.h"
27 #include "readline/readline.h"
29 /* These are the CLI output functions */
31 /* Mark beginning of a table */
34 cli_ui_out::do_table_begin (int nbrofcols
, int nr_rows
, const char *tblid
)
37 m_suppress_output
= true;
39 /* Only the table suppresses the output and, fortunately, a table
40 is not a recursive data structure. */
41 gdb_assert (!m_suppress_output
);
44 /* Mark beginning of a table body */
47 cli_ui_out::do_table_body ()
49 if (m_suppress_output
)
52 /* first, close the table header line */
56 /* Mark end of a table */
59 cli_ui_out::do_table_end ()
61 m_suppress_output
= false;
64 /* Specify table header */
67 cli_ui_out::do_table_header (int width
, ui_align alignment
,
68 const std::string
&col_name
,
69 const std::string
&col_hdr
)
71 if (m_suppress_output
)
74 do_field_string (0, width
, alignment
, 0, col_hdr
.c_str ());
77 /* Mark beginning of a list */
80 cli_ui_out::do_begin (ui_out_type type
, const char *id
)
84 /* Mark end of a list */
87 cli_ui_out::do_end (ui_out_type type
)
91 /* output an int field */
94 cli_ui_out::do_field_int (int fldno
, int width
, ui_align alignment
,
95 const char *fldname
, int value
)
97 if (m_suppress_output
)
100 std::string str
= string_printf ("%d", value
);
102 do_field_string (fldno
, width
, alignment
, fldname
, str
.c_str ());
105 /* used to omit a field */
108 cli_ui_out::do_field_skip (int fldno
, int width
, ui_align alignment
,
111 if (m_suppress_output
)
114 do_field_string (fldno
, width
, alignment
, fldname
, "");
117 /* other specific cli_field_* end up here so alignment and field
118 separators are both handled by cli_field_string */
121 cli_ui_out::do_field_string (int fldno
, int width
, ui_align align
,
122 const char *fldname
, const char *string
)
127 if (m_suppress_output
)
130 if ((align
!= ui_noalign
) && string
)
132 before
= width
- strlen (string
);
137 if (align
== ui_right
)
139 else if (align
== ui_left
)
157 fputs_filtered (string
, m_streams
.back ());
162 if (align
!= ui_noalign
)
166 /* Output field containing ARGS using printf formatting in FORMAT. */
169 cli_ui_out::do_field_fmt (int fldno
, int width
, ui_align align
,
170 const char *fldname
, const char *format
,
173 if (m_suppress_output
)
176 std::string str
= string_vprintf (format
, args
);
178 do_field_string (fldno
, width
, align
, fldname
, str
.c_str ());
182 cli_ui_out::do_spaces (int numspaces
)
184 if (m_suppress_output
)
187 print_spaces_filtered (numspaces
, m_streams
.back ());
191 cli_ui_out::do_text (const char *string
)
193 if (m_suppress_output
)
196 fputs_filtered (string
, m_streams
.back ());
200 cli_ui_out::do_message (const char *format
, va_list args
)
202 if (m_suppress_output
)
205 vfprintf_unfiltered (m_streams
.back (), format
, args
);
209 cli_ui_out::do_wrap_hint (const char *identstring
)
211 if (m_suppress_output
)
214 wrap_here (identstring
);
218 cli_ui_out::do_flush ()
220 gdb_flush (m_streams
.back ());
223 /* OUTSTREAM as non-NULL will push OUTSTREAM on the stack of output streams
224 and make it therefore active. OUTSTREAM as NULL will pop the last pushed
225 output stream; it is an internal error if it does not exist. */
228 cli_ui_out::do_redirect (ui_file
*outstream
)
230 if (outstream
!= NULL
)
231 m_streams
.push_back (outstream
);
233 m_streams
.pop_back ();
236 /* local functions */
239 cli_ui_out::field_separator ()
241 fputc_filtered (' ', m_streams
.back ());
244 /* Constructor for cli_ui_out. */
246 cli_ui_out::cli_ui_out (ui_file
*stream
, ui_out_flags flags
)
248 m_suppress_output (false)
250 gdb_assert (stream
!= NULL
);
252 m_streams
.push_back (stream
);
255 cli_ui_out::~cli_ui_out ()
259 /* Initialize private members at startup. */
262 cli_out_new (struct ui_file
*stream
)
264 return new cli_ui_out (stream
, ui_source_list
);
268 cli_ui_out::set_stream (struct ui_file
*stream
)
272 old
= m_streams
.back ();
273 m_streams
.back () = stream
;
278 /* CLI interface to display tab-completion matches. */
280 /* CLI version of displayer.crlf. */
283 cli_mld_crlf (const struct match_list_displayer
*displayer
)
288 /* CLI version of displayer.putch. */
291 cli_mld_putch (const struct match_list_displayer
*displayer
, int ch
)
293 putc (ch
, rl_outstream
);
296 /* CLI version of displayer.puts. */
299 cli_mld_puts (const struct match_list_displayer
*displayer
, const char *s
)
301 fputs (s
, rl_outstream
);
304 /* CLI version of displayer.flush. */
307 cli_mld_flush (const struct match_list_displayer
*displayer
)
309 fflush (rl_outstream
);
312 EXTERN_C
void _rl_erase_entire_line (void);
314 /* CLI version of displayer.erase_entire_line. */
317 cli_mld_erase_entire_line (const struct match_list_displayer
*displayer
)
319 _rl_erase_entire_line ();
322 /* CLI version of displayer.beep. */
325 cli_mld_beep (const struct match_list_displayer
*displayer
)
330 /* CLI version of displayer.read_key. */
333 cli_mld_read_key (const struct match_list_displayer
*displayer
)
335 return rl_read_key ();
338 /* CLI version of rl_completion_display_matches_hook.
339 See gdb_display_match_list for a description of the arguments. */
342 cli_display_match_list (char **matches
, int len
, int max
)
344 struct match_list_displayer displayer
;
346 rl_get_screen_size (&displayer
.height
, &displayer
.width
);
347 displayer
.crlf
= cli_mld_crlf
;
348 displayer
.putch
= cli_mld_putch
;
349 displayer
.puts
= cli_mld_puts
;
350 displayer
.flush
= cli_mld_flush
;
351 displayer
.erase_entire_line
= cli_mld_erase_entire_line
;
352 displayer
.beep
= cli_mld_beep
;
353 displayer
.read_key
= cli_mld_read_key
;
355 gdb_display_match_list (matches
, len
, max
, &displayer
);
356 rl_forced_update_display ();