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