|
VLink
2.0.0
A high-performance communication middleware
|
Process-wide buffered stdout writer with TTY detection, ANSI support, and a 1 MiB ring. 更多...
#include <terminal_stream.h>
Public 类型 | |
| using | ManipType = TerminalStream &(*)(TerminalStream &) |
Function-pointer type accepted by operator<<(ManipType) for custom manipulators. 更多... | |
Public 成员函数 | |||
| TerminalStream () noexcept | |||
Constructs the stream with a kDefaultBufferSize buffer and platform stdout fd. 更多... | |||
| ~TerminalStream () noexcept | |||
| Flushes any pending bytes and releases internal storage. 更多... | |||
| TerminalStream (const TerminalStream &) noexcept=delete | |||
| TerminalStream & | operator= (const TerminalStream &) noexcept=delete | ||
| TerminalStream (TerminalStream &&) noexcept=delete | |||
| TerminalStream & | operator= (TerminalStream &&) noexcept=delete | ||
| void | init () noexcept | ||
| Detects the platform stdout descriptor, TTY status, and enables Windows ANSI handling. 更多... | |||
| bool | is_tty () const noexcept | ||
Reports whether stdout was a terminal when init() ran. 更多... | |||
| bool | is_initialized () const noexcept | ||
Reports whether init() has been invoked. 更多... | |||
| void | flush () | ||
| Drains every buffered byte to stdout immediately. 更多... | |||
| TerminalStream & | write_raw (const char *data, size_t len) noexcept | ||
| Appends a raw byte array verbatim to the buffer. 更多... | |||
| TerminalStream & | operator<< (char c) noexcept | ||
| Appends a single character to the buffer. 更多... | |||
| TerminalStream & | operator<< (const char *str) noexcept | ||
| Appends the bytes of a NUL-terminated C string (NUL excluded). 更多... | |||
| TerminalStream & | operator<< (const std::string &str) noexcept | ||
Appends the bytes of str verbatim, including embedded NULs. 更多... | |||
| TerminalStream & | operator<< (std::string_view str) noexcept | ||
Appends the bytes of str verbatim, including embedded NULs. 更多... | |||
| TerminalStream & | operator<< (bool value) noexcept | ||
Appends the literal "true" or "false". 更多... | |||
| TerminalStream & | operator<< (float value) noexcept | ||
Formats a float through snprintf with the "%g" format. 更多... | |||
| TerminalStream & | operator<< (double value) noexcept | ||
Formats a double through snprintf with the "%g" format. 更多... | |||
| TerminalStream & | operator<< (long double value) noexcept | ||
Formats a long double through snprintf with the "%Lg" format. 更多... | |||
| TerminalStream & | operator<< (const void *ptr) noexcept | ||
Formats a pointer using snprintf with the "%p" format. 更多... | |||
| TerminalStream & | operator<< (ManipType manip) noexcept | ||
Applies a custom or built-in ManipType manipulator to the stream. 更多... | |||
| TerminalStream & | operator<< (std::ostream &(*)(std::ostream &)) noexcept | ||
Accepts std::endl and similar standard manipulators. 更多... | |||
Integer overloads | |||
Format a signed or unsigned integer as decimal and append it.
| |||
| TerminalStream & | operator<< (short value) noexcept | ||
| TerminalStream & | operator<< (unsigned short value) noexcept | ||
| TerminalStream & | operator<< (int value) noexcept | ||
| TerminalStream & | operator<< (unsigned int value) noexcept | ||
| TerminalStream & | operator<< (long value) noexcept | ||
| TerminalStream & | operator<< (unsigned long value) noexcept | ||
| TerminalStream & | operator<< (long long value) noexcept | ||
| TerminalStream & | operator<< (unsigned long long value) noexcept | ||
静态 Public 成员函数 | |
| static TerminalStream & | get () noexcept |
| Returns the process-wide singleton, building it on the first call. 更多... | |
| static TerminalStream & | endl (TerminalStream &stream) noexcept |
| Manipulator that appends a newline byte and flushes the buffer. 更多... | |
| static TerminalStream & | flush_manip (TerminalStream &stream) noexcept |
| Manipulator that flushes the buffer without appending any byte. 更多... | |
静态 Public 属性 | |
| static constexpr size_t | kDefaultBufferSize {1024 * 1024 * 1} |
| Default capacity of the internal buffer (1 MiB). 更多... | |
Process-wide buffered stdout writer with TTY detection, ANSI support, and a 1 MiB ring.
Construction is hidden behind get(); copy and move are disabled. Internally the class keeps the buffer, write cursor, file descriptor, and an atomic TTY flag set by init().
| using vlink::TerminalStream::ManipType = TerminalStream& (*)(TerminalStream&) |
Function-pointer type accepted by operator<<(ManipType) for custom manipulators.
|
noexcept |
Constructs the stream with a kDefaultBufferSize buffer and platform stdout fd.
No syscalls run at construction time; init() detects TTY status and enables Windows virtual-terminal processing when invoked separately.
|
noexcept |
Flushes any pending bytes and releases internal storage.
|
deletenoexcept |
|
deletenoexcept |
|
staticnoexcept |
Manipulator that appends a newline byte and flushes the buffer.
| stream | Stream to write to. |
stream for chaining. | void vlink::TerminalStream::flush | ( | ) |
Drains every buffered byte to stdout immediately.
On POSIX TTYs the call additionally invokes tcdrain() so the kernel queue is empty before returning, providing a strong "user can see it now" guarantee.
|
staticnoexcept |
Manipulator that flushes the buffer without appending any byte.
| stream | Stream to flush. |
stream for chaining.
|
staticnoexcept |
Returns the process-wide singleton, building it on the first call.
|
noexcept |
Detects the platform stdout descriptor, TTY status, and enables Windows ANSI handling.
Idempotent and thread-safe; only the first call performs work. Call once early in main() before relying on is_tty() or emitting ANSI escape sequences on Windows.
|
noexcept |
|
noexcept |
|
noexcept |
Appends the literal "true" or "false".
| value | Boolean to print. |
*this for chaining.
|
noexcept |
Appends a single character to the buffer.
| c | Character to append. |
*this for chaining.
|
noexcept |
Appends the bytes of a NUL-terminated C string (NUL excluded).
| str | Source string or nullptr (no-op). |
*this for chaining.
|
noexcept |
Appends the bytes of str verbatim, including embedded NULs.
| str | Source string. |
*this for chaining.
|
noexcept |
Formats a pointer using snprintf with the "%p" format.
| ptr | Pointer to format. |
*this for chaining.
|
noexcept |
Formats a double through snprintf with the "%g" format.
| value | Double to print. |
*this for chaining.
|
noexcept |
Formats a float through snprintf with the "%g" format.
| value | Float to print. |
*this for chaining.
|
noexcept |
|
noexcept |
Formats a long double through snprintf with the "%Lg" format.
| value | Long double to print. |
*this for chaining.
|
noexcept |
|
noexcept |
|
noexcept |
Applies a custom or built-in ManipType manipulator to the stream.
| manip | Function pointer invoked with *this. |
manip returns, normally a reference to *this.
|
noexcept |
|
noexcept |
Accepts std::endl and similar standard manipulators.
Standard manipulators expect a std::ostream; this overload ignores the function pointer and emits a newline followed by a flush, matching TerminalStream::endl.
*this for chaining.
|
noexcept |
Appends the bytes of str verbatim, including embedded NULs.
| str | Source view. |
*this for chaining.
|
noexcept |
|
noexcept |
|
noexcept |
|
noexcept |
|
deletenoexcept |
|
deletenoexcept |
|
noexcept |
Appends a raw byte array verbatim to the buffer.
| data | Pointer to len bytes; not retained beyond the call. |
| len | Number of bytes to append; 0 is a no-op. |
*this for chaining.
|
staticconstexpr |
Default capacity of the internal buffer (1 MiB).
Writes smaller than this accumulate in the buffer until flush() / a flushing manipulator fires or the buffer fills. Writes at or above this threshold bypass the buffer.