1 /* Output generating routines for GDB CLI.
3 Copyright (C) 1999-2003, 2005, 2007-2012 Free Software Foundation,
6 Contributed by Cygnus Solutions.
7 Written by Fernando Nasser for Cygnus.
9 This file is part of GDB.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 #include "gdb_string.h"
29 #include "gdb_assert.h"
31 struct tui_ui_out_data
33 struct cli_ui_out_data base
;
38 typedef struct tui_ui_out_data tui_out_data
;
40 /* This is the TUI ui-out implementation functions vector. It is
41 initialized below in _initialize_tui_out, inheriting the CLI
42 version, and overriding a few methods. */
44 static struct ui_out_impl tui_ui_out_impl
;
46 /* Output an int field. */
49 tui_field_int (struct ui_out
*uiout
,
51 enum ui_align alignment
,
55 tui_out_data
*data
= ui_out_data (uiout
);
57 if (data
->base
.suppress_output
)
60 /* Don't print line number, keep it for later. */
61 if (data
->start_of_line
== 0 && strcmp (fldname
, "line") == 0)
63 data
->start_of_line
++;
67 data
->start_of_line
++;
69 (*cli_ui_out_impl
.field_int
) (uiout
, fldno
,
70 width
, alignment
, fldname
, value
);
73 /* Other cli_field_* end up here so alignment and field separators are
74 both handled by tui_field_string. */
77 tui_field_string (struct ui_out
*uiout
,
83 tui_out_data
*data
= ui_out_data (uiout
);
85 if (data
->base
.suppress_output
)
88 if (fldname
&& data
->line
> 0 && strcmp (fldname
, "file") == 0)
90 data
->start_of_line
++;
93 tui_show_source (string
, data
->line
);
98 data
->start_of_line
++;
100 (*cli_ui_out_impl
.field_string
) (uiout
, fldno
,
105 /* This is the only field function that does not align. */
108 tui_field_fmt (struct ui_out
*uiout
, int fldno
,
109 int width
, enum ui_align align
,
114 tui_out_data
*data
= ui_out_data (uiout
);
116 if (data
->base
.suppress_output
)
119 data
->start_of_line
++;
121 (*cli_ui_out_impl
.field_fmt
) (uiout
, fldno
,
123 fldname
, format
, args
);
127 tui_text (struct ui_out
*uiout
, const char *string
)
129 tui_out_data
*data
= ui_out_data (uiout
);
131 if (data
->base
.suppress_output
)
133 data
->start_of_line
++;
136 if (strchr (string
, '\n') != 0)
139 data
->start_of_line
= 0;
143 if (strchr (string
, '\n'))
144 data
->start_of_line
= 0;
146 (*cli_ui_out_impl
.text
) (uiout
, string
);
150 tui_out_new (struct ui_file
*stream
)
154 tui_out_data
*data
= XMALLOC (tui_out_data
);
156 /* Initialize base "class". */
157 cli_out_data_ctor (&data
->base
, stream
);
159 /* Initialize our fields. */
161 data
->start_of_line
= 0;
163 return ui_out_new (&tui_ui_out_impl
, data
, flags
);
166 /* Standard gdb initialization hook. */
168 extern void _initialize_tui_out (void);
171 _initialize_tui_out (void)
173 /* Inherit the CLI version. */
174 tui_ui_out_impl
= cli_ui_out_impl
;
176 /* Override a few methods. */
177 tui_ui_out_impl
.field_int
= tui_field_int
;
178 tui_ui_out_impl
.field_string
= tui_field_string
;
179 tui_ui_out_impl
.field_fmt
= tui_field_fmt
;
180 tui_ui_out_impl
.text
= tui_text
;