|
VLink 2.0.0
A high-performance communication middleware
|
Singleton buffered stdout writer with thread-safety and TTY detection. More...
#include <terminal_stream.h>
Public Types | |
| using | ManipType = TerminalStream& (*)(TerminalStream&) |
| Type alias for stream manipulator functions. | |
Public Member Functions | |
| TerminalStream () noexcept | |
Constructs the stream with a kDefaultBufferSize internal buffer. | |
| ~TerminalStream () noexcept | |
| Destructor – flushes any remaining buffered data to stdout. | |
| TerminalStream (const TerminalStream &) noexcept=delete | |
| TerminalStream & | operator= (const TerminalStream &) noexcept=delete |
| TerminalStream (TerminalStream &&) noexcept=delete | |
| TerminalStream & | operator= (TerminalStream &&) noexcept=delete |
| void | init () noexcept |
| Initialises the stream: detects the file descriptor and TTY status. | |
| bool | is_tty () const noexcept |
Returns true if stdout is connected to a terminal (TTY). | |
| bool | is_initialized () const noexcept |
Returns true if init() has been called. | |
| void | flush () |
| Flushes all buffered data to stdout immediately. | |
| TerminalStream & | write_raw (const char *data, size_t len) noexcept |
Writes a raw byte array of len bytes to the buffer. | |
| TerminalStream & | operator<< (char c) noexcept |
| Writes a single character to the buffer. | |
| TerminalStream & | operator<< (const char *str) noexcept |
| Writes a NUL-terminated C string to the buffer. | |
| TerminalStream & | operator<< (const std::string &str) noexcept |
Writes a std::string to the buffer. | |
| TerminalStream & | operator<< (std::string_view str) noexcept |
Writes a std::string_view to the buffer. | |
| TerminalStream & | operator<< (bool value) noexcept |
Writes "true" or "false". | |
| TerminalStream & | operator<< (short value) noexcept |
| Writes a short integer. | |
| TerminalStream & | operator<< (unsigned short value) noexcept |
| Writes an unsigned short integer. | |
| TerminalStream & | operator<< (int value) noexcept |
| Writes an int. | |
| TerminalStream & | operator<< (unsigned int value) noexcept |
| Writes an unsigned int. | |
| TerminalStream & | operator<< (long value) noexcept |
| Writes a long. | |
| TerminalStream & | operator<< (unsigned long value) noexcept |
| Writes an unsigned long. | |
| TerminalStream & | operator<< (long long value) noexcept |
| Writes a long long. | |
| TerminalStream & | operator<< (unsigned long long value) noexcept |
| Writes an unsigned long long. | |
| TerminalStream & | operator<< (float value) noexcept |
Writes a float using "%g" format. | |
| TerminalStream & | operator<< (double value) noexcept |
Writes a double using "%g" format. | |
| TerminalStream & | operator<< (long double value) noexcept |
Writes a long double using "%Lg" format. | |
| TerminalStream & | operator<< (const void *ptr) noexcept |
| Writes a pointer address as a hex string. | |
| TerminalStream & | operator<< (ManipType manip) noexcept |
Applies a ManipType manipulator function to the stream. | |
| TerminalStream & | operator<< (std::ostream &(*)(std::ostream &)) noexcept |
Accepts std::endl and similar std::ostream manipulators. | |
Static Public Member Functions | |
| static TerminalStream & | get () noexcept |
Returns the process-global TerminalStream singleton. | |
| static TerminalStream & | endl (TerminalStream &stream) noexcept |
| Stream manipulator that appends a newline and flushes the buffer. | |
| static TerminalStream & | flush_manip (TerminalStream &stream) noexcept |
| Stream manipulator that flushes the buffer without appending a newline. | |
Static Public Attributes | |
| static constexpr size_t | kDefaultBufferSize {1024 * 1024 * 1} |
| Default internal buffer size (1 MiB). | |
Singleton buffered stdout writer with thread-safety and TTY detection.
Obtain the singleton with TerminalStream::get(). Copy and move are disabled.
| using vlink::TerminalStream::ManipType = TerminalStream& (*)(TerminalStream&) |
Type alias for stream manipulator functions.
|
inlinenoexcept |
Constructs the stream with a kDefaultBufferSize internal buffer.
|
inlinenoexcept |
Destructor – flushes any remaining buffered data to stdout.
|
deletenoexcept |
|
deletenoexcept |
|
inlinestaticnoexcept |
Stream manipulator that appends a newline and flushes the buffer.
Usage: stream << TerminalStream::endl;
| stream | The TerminalStream to write to. |
stream.
|
inline |
Flushes all buffered data to stdout immediately.
On non-Windows TTY outputs, also calls tcdrain() to wait for the terminal.
|
inlinestaticnoexcept |
Stream manipulator that flushes the buffer without appending a newline.
Usage: stream << TerminalStream::flush_manip;
| stream | The TerminalStream to flush. |
stream.
|
inlinestaticnoexcept |
Returns the process-global TerminalStream singleton.
Implementation Details.
|
inlinenoexcept |
Initialises the stream: detects the file descriptor and TTY status.
Must be called once before using is_tty(). On Windows, enables virtual terminal processing (ANSI escape codes). Subsequent calls are no-ops.
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Returns true if stdout is connected to a terminal (TTY).
Only meaningful after init() has been called.
true if stdout is a TTY.
|
inlinenoexcept |
Writes "true" or "false".
*this.
|
inlinenoexcept |
Writes a single character to the buffer.
| c | Character to write. |
*this.
|
inlinenoexcept |
Writes a NUL-terminated C string to the buffer.
Null-pointer check is performed; passing nullptr is a no-op.
| str | C string to write. |
*this.
|
inlinenoexcept |
Writes a std::string to the buffer.
| str | String to write. |
*this.
|
inlinenoexcept |
Writes a pointer address as a hex string.
*this.
|
inlinenoexcept |
Writes a double using "%g" format.
*this.
|
inlinenoexcept |
Writes a float using "%g" format.
*this.
|
inlinenoexcept |
Writes an int.
*this.
|
inlinenoexcept |
Writes a long double using "%Lg" format.
*this.
|
inlinenoexcept |
Writes a long long.
*this.
|
inlinenoexcept |
Writes a long.
*this.
|
inlinenoexcept |
Applies a ManipType manipulator function to the stream.
Compatible with TerminalStream::endl and TerminalStream::flush_manip.
| manip | Manipulator function pointer. |
*this.
|
inlinenoexcept |
Writes a short integer.
*this.
|
inlinenoexcept |
Accepts std::endl and similar std::ostream manipulators.
When std::endl is passed, writes a newline and flushes the buffer.
*this.
|
inlinenoexcept |
Writes a std::string_view to the buffer.
| str | String view to write. |
*this.
|
inlinenoexcept |
Writes an unsigned int.
*this.
|
inlinenoexcept |
Writes an unsigned long long.
*this.
|
inlinenoexcept |
Writes an unsigned long.
*this.
|
inlinenoexcept |
Writes an unsigned short integer.
*this.
|
deletenoexcept |
|
deletenoexcept |
|
inlinenoexcept |
Writes a raw byte array of len bytes to the buffer.
| data | Pointer to data to write. |
| len | Number of bytes to write. |
*this for chaining.
|
staticconstexpr |
Default internal buffer size (1 MiB).