/* A ui_file that implements output paging and unfiltered output. */
-class pager_file : public ui_file
+class pager_file : public wrapped_file
{
public:
/* Create a new pager_file. The new object takes ownership of
STREAM. */
explicit pager_file (ui_file *stream)
- : m_stream (stream)
+ : wrapped_file (stream)
{
}
+ ~pager_file ()
+ {
+ delete m_stream;
+ }
+
DISABLE_COPY_AND_ASSIGN (pager_file);
void write (const char *buf, long length_buf) override;
m_stream->write_async_safe (buf, length_buf);
}
- bool term_out () override
- {
- return m_stream->term_out ();
- }
-
- bool isatty () override
- {
- return m_stream->isatty ();
- }
-
- bool can_emit_style_escape () override
- {
- return m_stream->can_emit_style_escape ();
- }
-
void emit_style_escape (const ui_file_style &style) override;
void reset_style () override;
void flush () override;
- int fd () const override
- {
- return m_stream->fd ();
- }
-
void wrap_here (int indent) override;
void puts_unfiltered (const char *str) override
/* The style applied at the time that wrap_here was called. */
ui_file_style m_wrap_style;
- /* The unfiltered output stream. */
- ui_file_up m_stream;
-
/* This is temporarily set when paging. This will cause some
methods to change their behavior to ignore the wrap buffer. */
bool m_paging = false;
}
};
-/* A ui_file that optionally puts a timestamp at the start of each
- line of output. */
+/* A base class for ui_file types that wrap another ui_file. */
-class timestamped_file : public ui_file
+class wrapped_file : public ui_file
{
public:
- explicit timestamped_file (ui_file *stream)
- : m_stream (stream)
- {
- }
+
+ bool isatty () override
+ { return m_stream->isatty (); }
+
+ bool term_out () override
+ { return m_stream->term_out (); }
bool can_emit_style_escape () override
{ return m_stream->can_emit_style_escape (); }
+ void flush () override
+ { m_stream->flush (); }
+
+ void wrap_here (int indent) override
+ { m_stream->wrap_here (indent); }
+
+ void emit_style_escape (const ui_file_style &style) override
+ { m_stream->emit_style_escape (style); }
+
+ /* Rest the current output style to the empty style. */
+ void reset_style () override
+ { m_stream->reset_style (); }
+
+ int fd () const override
+ { return m_stream->fd (); }
+
+ void puts_unfiltered (const char *str) override
+ { m_stream->puts_unfiltered (str); }
+
void write_async_safe (const char *buf, long length_buf) override
{ return m_stream->write_async_safe (buf, length_buf); }
+protected:
+
+ /* Note that this class does not assume ownership of the stream.
+ However, a subclass may choose to, by adding a 'delete' to its
+ destructor. */
+ explicit wrapped_file (ui_file *stream)
+ : m_stream (stream)
+ {
+ }
+
+ /* The underlying stream. */
+ ui_file *m_stream;
+};
+
+/* A ui_file that optionally puts a timestamp at the start of each
+ line of output. */
+
+class timestamped_file : public wrapped_file
+{
+public:
+ explicit timestamped_file (ui_file *stream)
+ : wrapped_file (stream)
+ {
+ }
+
DISABLE_COPY_AND_ASSIGN (timestamped_file);
void write (const char *buf, long len) override;
private:
- /* Output is sent here. */
- ui_file *m_stream;
-
/* True if the next output should be timestamped. */
bool m_needs_timestamp = true;
};