Change the pager to a ui_file
[binutils-gdb.git] / gdb / pager.h
1 /* Output pager for gdb
2 Copyright (C) 2021, 2022 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #ifndef GDB_PAGER_H
20 #define GDB_PAGER_H
21
22 #include "ui-file.h"
23
24 /* A ui_file that implements output paging and unfiltered output. */
25
26 class pager_file : public ui_file
27 {
28 public:
29 /* Create a new pager_file. The new object takes ownership of
30 STREAM. */
31 explicit pager_file (ui_file *stream)
32 : m_stream (stream)
33 {
34 }
35
36 DISABLE_COPY_AND_ASSIGN (pager_file);
37
38 void write (const char *buf, long length_buf) override;
39
40 void puts (const char *str) override;
41
42 void write_async_safe (const char *buf, long length_buf) override
43 {
44 m_stream->write_async_safe (buf, length_buf);
45 }
46
47 bool term_out () override
48 {
49 return m_stream->term_out ();
50 }
51
52 bool isatty () override
53 {
54 return m_stream->isatty ();
55 }
56
57 bool can_emit_style_escape () override
58 {
59 return m_stream->can_emit_style_escape ();
60 }
61
62 void emit_style_escape (const ui_file_style &style) override;
63 void reset_style () override;
64
65 void flush () override;
66
67 int fd () const override
68 {
69 return m_stream->fd ();
70 }
71
72 void wrap_here (int indent) override;
73
74 void puts_unfiltered (const char *str) override
75 {
76 flush_wrap_buffer ();
77 m_stream->puts_unfiltered (str);
78 }
79
80 private:
81
82 void prompt_for_continue ();
83
84 /* Flush the wrap buffer to STREAM, if necessary. */
85 void flush_wrap_buffer ();
86
87 /* Contains characters which are waiting to be output (they have
88 already been counted in chars_printed). */
89 std::string m_wrap_buffer;
90
91 /* Amount to indent by if the wrap occurs. */
92 int m_wrap_indent = 0;
93
94 /* Column number on the screen where wrap_buffer begins, or 0 if
95 wrapping is not in effect. */
96 int m_wrap_column = 0;
97
98 /* The style applied at the time that wrap_here was called. */
99 ui_file_style m_wrap_style;
100
101 /* The unfiltered output stream. */
102 ui_file_up m_stream;
103
104 /* This is temporarily set when paging. This will cause some
105 methods to change their behavior to ignore the wrap buffer. */
106 bool m_paging = false;
107 };
108
109 #endif /* GDB_PAGER_H */