GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pager.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// 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.
14//
15// Octave is distributed in the hope that it will be useful, but
16// 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.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_pager_h)
27#define octave_pager_h 1
28
29#include "octave-config.h"
30
31#include <fstream>
32#include <iosfwd>
33#include <sstream>
34#include <string>
35
36class octave_value;
38
40
41class interpreter;
42class oprocstream;
43
44class OCTINTERP_API pager_buf : public std::stringbuf
45{
46public:
47
48 pager_buf () : std::stringbuf (), m_diary_skip (0) { }
49
50 OCTAVE_DISABLE_COPY_MOVE (pager_buf)
51
52 ~pager_buf () = default;
53
54 void flush_current_contents_to_diary ();
55
56 void set_diary_skip ();
57
58protected:
59
60 int sync ();
61
62private:
63
64 std::size_t m_diary_skip;
65};
66
67class OCTINTERP_API pager_stream : public std::ostream
68{
69public:
70
71 pager_stream ();
72
73 OCTAVE_DISABLE_COPY_MOVE (pager_stream)
74
76
77 void flush_current_contents_to_diary ();
78
79 void set_diary_skip ();
80
81 std::ostream& stream ();
82
83 void reset ();
84
85private:
86
87 pager_buf *m_pb;
88};
89
90class OCTINTERP_API diary_buf : public std::stringbuf
91{
92public:
93
94 OCTAVE_DEFAULT_CONSTRUCT_DELETE (diary_buf)
95 OCTAVE_DISABLE_COPY_MOVE (diary_buf)
96
97protected:
98
99 int sync ();
100};
101
102class OCTINTERP_API diary_stream : public std::ostream
103{
104public:
105
106 diary_stream ();
107
108 OCTAVE_DISABLE_COPY_MOVE (diary_stream)
109
110 ~diary_stream ();
111
112 std::ostream& stream ();
113
114 void reset ();
115
116private:
117
118 diary_buf *m_db;
119};
120
121extern OCTINTERP_API void flush_stdout ();
122
124{
125public:
126
127 output_system (interpreter& interp);
128
129 OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (output_system)
130
131 ~output_system () = default;
132
133 pager_stream& pager () { return m_pager_stream; }
134
135 diary_stream& diary () { return m_diary_stream; }
136
137 std::string diary_file_name () const { return m_diary_file_name; }
138
139 std::string diary_file_name (const std::string& nm)
140 {
141 std::string val = m_diary_file_name;
142 m_diary_file_name = nm.empty () ? "diary" : nm;
143 return val;
144 }
145
146 octave_value PAGER (const octave_value_list& args, int nargout);
147
148 std::string PAGER () const { return m_PAGER; }
149
150 std::string PAGER (const std::string& s)
151 {
152 std::string val = m_PAGER;
153 m_PAGER = s;
154 return val;
155 }
156
157 octave_value PAGER_FLAGS (const octave_value_list& args, int nargout);
158
159 std::string PAGER_FLAGS () const { return m_PAGER_FLAGS; }
160
161 std::string PAGER_FLAGS (const std::string& s)
162 {
163 std::string val = m_PAGER_FLAGS;
164 m_PAGER_FLAGS = s;
165 return val;
166 }
167
169 int nargout);
170
172 {
173 return m_page_output_immediately;
174 }
175
176 bool page_output_immediately (bool flag)
177 {
178 bool val = m_page_output_immediately;
179 m_page_output_immediately = flag;
180 return val;
181 }
182
184 int nargout);
185
186 bool page_screen_output () const { return m_page_screen_output; }
187
188 bool page_screen_output (bool flag)
189 {
190 bool val = m_page_screen_output;
191 m_page_screen_output = flag;
192 return val;
193 }
194
196 {
197 return m_write_to_diary_file;
198 }
199
200 bool write_to_diary_file (bool flag)
201 {
202 bool val = m_write_to_diary_file;
203 m_write_to_diary_file = flag;
204 return val;
205 }
206
208 {
209 return m_really_flush_to_pager;
210 }
211
212 bool really_flush_to_pager (bool flag)
213 {
214 bool val = m_really_flush_to_pager;
215 m_really_flush_to_pager = flag;
216 return val;
217 }
218
220 {
221 return m_flushing_output_to_pager;
222 }
223
225 {
226 bool val = m_flushing_output_to_pager;
227 m_flushing_output_to_pager = flag;
228 return val;
229 }
230
231 std::string pager_command () const;
232
233 std::ofstream& external_diary_file () { return m_external_diary_file; }
234
235 void reset ();
236
237 void flush_stdout ();
238
239 bool sync (const char *msg, int len);
240
241 void clear_external_pager ();
242
243 void open_diary ();
244
245 void close_diary ();
246
247 std::ostream& __stdout__ () { return m_pager_stream.stream (); }
248
249 std::ostream& __diary__ () { return m_diary_stream.stream (); }
250
251private:
252
253 interpreter& m_interpreter;
254
255 pager_stream m_pager_stream;
256
257 diary_stream m_diary_stream;
258
259 // Our actual connection to the external pager.
260 oprocstream *m_external_pager = nullptr;
261
262 // The diary file.
263 std::ofstream m_external_diary_file;
264
265 // The name of the current diary file.
266 std::string m_diary_file_name;
267
268 // The shell command to run as the pager.
269 std::string m_PAGER;
270
271 // The options to pass to the pager.
272 std::string m_PAGER_FLAGS;
273
274 // TRUE means that if output is going to the pager, it is sent as soon
275 // as it is available. Otherwise, it is buffered and only sent to the
276 // pager when it is time to print another prompt.
277 bool m_page_output_immediately;
278
279 // TRUE means all output intended for the screen should be passed
280 // through the pager.
281 bool m_page_screen_output;
282
283 // TRUE means we write to the diary file.
284 bool m_write_to_diary_file;
285
286 bool m_really_flush_to_pager;
287
288 bool m_flushing_output_to_pager;
289
290 void start_external_pager ();
291
292 void do_sync (const char *msg, int len, bool bypass_pager);
293};
294
295extern OCTINTERP_API std::ostream& __stdout__ ();
296
297extern OCTINTERP_API std::ostream& __diary__ ();
298
299OCTAVE_END_NAMESPACE(octave)
300
301#define octave_stdout (octave::__stdout__ ())
302
303#define octave_diary (octave::__diary__ ())
304
305#endif
std::ostream & stream()
Definition pager.cc:248
~output_system()=default
void close_diary()
Definition pager.cc:355
bool page_output_immediately(bool flag)
Definition pager.h:176
std::string PAGER_FLAGS() const
Definition pager.h:159
void open_diary()
Definition pager.cc:378
bool page_screen_output() const
Definition pager.h:186
bool page_output_immediately() const
Definition pager.h:171
void flush_stdout()
Definition pager.cc:336
bool flushing_output_to_pager(bool flag)
Definition pager.h:224
std::string diary_file_name() const
Definition pager.h:137
diary_stream & diary()
Definition pager.h:135
pager_stream & pager()
Definition pager.h:133
std::ofstream & external_diary_file()
Definition pager.h:233
std::ostream & __stdout__()
Definition pager.h:247
bool write_to_diary_file(bool flag)
Definition pager.h:200
std::string PAGER(const std::string &s)
Definition pager.h:150
bool really_flush_to_pager(bool flag)
Definition pager.h:212
bool sync(const char *msg, int len)
Definition pager.cc:394
void reset()
Definition pager.cc:327
bool flushing_output_to_pager() const
Definition pager.h:219
void clear_external_pager()
Definition pager.cc:426
bool really_flush_to_pager() const
Definition pager.h:207
std::ostream & __diary__()
Definition pager.h:249
std::string diary_file_name(const std::string &nm)
Definition pager.h:139
bool write_to_diary_file() const
Definition pager.h:195
std::string pager_command() const
Definition pager.cc:316
std::string PAGER_FLAGS(const std::string &s)
Definition pager.h:161
bool page_screen_output(bool flag)
Definition pager.h:188
std::string PAGER() const
Definition pager.h:148
~pager_buf()=default
pager_buf()
Definition pager.h:48
std::ostream & stream()
Definition pager.cc:201
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::ostream & __stdout__()
Definition pager.cc:512
void flush_stdout()
Definition pager.cc:268
std::ostream & __diary__()
Definition pager.cc:520
F77_RET_T len
Definition xerbla.cc:61