xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/tui/tui-out.h (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1 /* Copyright (C) 2016-2023 Free Software Foundation, Inc.
2 
3    This file is part of GDB.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17 
18 #ifndef TUI_TUI_OUT_H
19 #define TUI_TUI_OUT_H
20 
21 #include "cli-out.h"
22 
23 /* A ui_out class for the TUI.  This is just like the CLI's ui_out,
24    except that it overrides output methods to detect when a source
25    line is being printed and show the source in the TUI's source
26    window instead of printing the line in the console window.  */
27 class tui_ui_out : public cli_ui_out
28 {
29 public:
30 
31   explicit tui_ui_out (ui_file *stream);
32 
33 protected:
34 
35   void do_field_signed (int fldno, int width, ui_align align, const char *fldname,
36 			LONGEST value) override;
37   void do_field_string (int fldno, int width, ui_align align, const char *fldname,
38 			const char *string, const ui_file_style &style) override;
39   void do_field_fmt (int fldno, int width, ui_align align, const char *fldname,
40 		     const ui_file_style &style,
41 		     const char *format, va_list args) override
42     ATTRIBUTE_PRINTF (7, 0);
43   void do_text (const char *string) override;
44 
45 private:
46 
47   /* These fields are used to make print_source_lines show the source
48      in the TUI's source window instead of in the console.
49      M_START_OF_LINE is incremented whenever something is output to
50      the ui_out.  If an integer field named "line" is printed on the
51      ui_out, and nothing else has been printed yet (both
52      M_START_OF_LINE and M_LINE are still 0), we assume
53      print_source_lines is starting to print a source line, and thus
54      record the line number in M_LINE.  Afterwards, when we see a
55      string field named "fullname" being output, we take the fullname
56      and the recorded line and show the source line in the TUI's
57      source window.  tui_ui_out::do_text() suppresses text output
58      until it sees an endline being printed, at which point these
59      variables are reset back to 0.  */
60   int m_line = 0;
61   int m_start_of_line = 0;
62 };
63 
64 #endif /* TUI_TUI_OUT_H */
65