VLink  2.0.0
A high-performance communication middleware
vlink::TerminalStream类 参考final

Process-wide buffered stdout writer with TTY detection, ANSI support, and a 1 MiB ring. 更多...

#include <terminal_stream.h>

vlink::TerminalStream 的协作图:

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
 
TerminalStreamoperator= (const TerminalStream &) noexcept=delete
 
 TerminalStream (TerminalStream &&) noexcept=delete
 
TerminalStreamoperator= (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. 更多...
 
TerminalStreamwrite_raw (const char *data, size_t len) noexcept
 Appends a raw byte array verbatim to the buffer. 更多...
 
TerminalStreamoperator<< (char c) noexcept
 Appends a single character to the buffer. 更多...
 
TerminalStreamoperator<< (const char *str) noexcept
 Appends the bytes of a NUL-terminated C string (NUL excluded). 更多...
 
TerminalStreamoperator<< (const std::string &str) noexcept
 Appends the bytes of str verbatim, including embedded NULs. 更多...
 
TerminalStreamoperator<< (std::string_view str) noexcept
 Appends the bytes of str verbatim, including embedded NULs. 更多...
 
TerminalStreamoperator<< (bool value) noexcept
 Appends the literal "true" or "false". 更多...
 
TerminalStreamoperator<< (float value) noexcept
 Formats a float through snprintf with the "%g" format. 更多...
 
TerminalStreamoperator<< (double value) noexcept
 Formats a double through snprintf with the "%g" format. 更多...
 
TerminalStreamoperator<< (long double value) noexcept
 Formats a long double through snprintf with the "%Lg" format. 更多...
 
TerminalStreamoperator<< (const void *ptr) noexcept
 Formats a pointer using snprintf with the "%p" format. 更多...
 
TerminalStreamoperator<< (ManipType manip) noexcept
 Applies a custom or built-in ManipType manipulator to the stream. 更多...
 
TerminalStreamoperator<< (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.

参数
valueInteger to print.
返回
Reference to *this for chaining.
TerminalStreamoperator<< (short value) noexcept
 
TerminalStreamoperator<< (unsigned short value) noexcept
 
TerminalStreamoperator<< (int value) noexcept
 
TerminalStreamoperator<< (unsigned int value) noexcept
 
TerminalStreamoperator<< (long value) noexcept
 
TerminalStreamoperator<< (unsigned long value) noexcept
 
TerminalStreamoperator<< (long long value) noexcept
 
TerminalStreamoperator<< (unsigned long long value) noexcept
 

静态 Public 成员函数

static TerminalStreamget () noexcept
 Returns the process-wide singleton, building it on the first call. 更多...
 
static TerminalStreamendl (TerminalStream &stream) noexcept
 Manipulator that appends a newline byte and flushes the buffer. 更多...
 
static TerminalStreamflush_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().

成员类型定义说明

◆ ManipType

Function-pointer type accepted by operator<<(ManipType) for custom manipulators.

构造及析构函数说明

◆ TerminalStream() [1/3]

vlink::TerminalStream::TerminalStream ( )
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.

◆ ~TerminalStream()

vlink::TerminalStream::~TerminalStream ( )
noexcept

Flushes any pending bytes and releases internal storage.

◆ TerminalStream() [2/3]

vlink::TerminalStream::TerminalStream ( const TerminalStream )
deletenoexcept

◆ TerminalStream() [3/3]

vlink::TerminalStream::TerminalStream ( TerminalStream &&  )
deletenoexcept

成员函数说明

◆ endl()

static TerminalStream& vlink::TerminalStream::endl ( TerminalStream stream)
staticnoexcept

Manipulator that appends a newline byte and flushes the buffer.

参数
streamStream to write to.
返回
Reference to stream for chaining.

◆ flush()

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.

◆ flush_manip()

static TerminalStream& vlink::TerminalStream::flush_manip ( TerminalStream stream)
staticnoexcept

Manipulator that flushes the buffer without appending any byte.

参数
streamStream to flush.
返回
Reference to stream for chaining.

◆ get()

static TerminalStream& vlink::TerminalStream::get ( )
staticnoexcept

Returns the process-wide singleton, building it on the first call.

返回
Reference to the singleton instance.

◆ init()

void vlink::TerminalStream::init ( )
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.

◆ is_initialized()

bool vlink::TerminalStream::is_initialized ( ) const
noexcept

Reports whether init() has been invoked.

返回
true once init() completes for the first time.

◆ is_tty()

bool vlink::TerminalStream::is_tty ( ) const
noexcept

Reports whether stdout was a terminal when init() ran.

返回
true when init() saw a TTY; false otherwise.

◆ operator<<() [1/19]

TerminalStream& vlink::TerminalStream::operator<< ( bool  value)
noexcept

Appends the literal "true" or "false".

参数
valueBoolean to print.
返回
Reference to *this for chaining.

◆ operator<<() [2/19]

TerminalStream& vlink::TerminalStream::operator<< ( char  c)
noexcept

Appends a single character to the buffer.

参数
cCharacter to append.
返回
Reference to *this for chaining.

◆ operator<<() [3/19]

TerminalStream& vlink::TerminalStream::operator<< ( const char *  str)
noexcept

Appends the bytes of a NUL-terminated C string (NUL excluded).

参数
strSource string or nullptr (no-op).
返回
Reference to *this for chaining.

◆ operator<<() [4/19]

TerminalStream& vlink::TerminalStream::operator<< ( const std::string &  str)
noexcept

Appends the bytes of str verbatim, including embedded NULs.

参数
strSource string.
返回
Reference to *this for chaining.

◆ operator<<() [5/19]

TerminalStream& vlink::TerminalStream::operator<< ( const void *  ptr)
noexcept

Formats a pointer using snprintf with the "%p" format.

参数
ptrPointer to format.
返回
Reference to *this for chaining.

◆ operator<<() [6/19]

TerminalStream& vlink::TerminalStream::operator<< ( double  value)
noexcept

Formats a double through snprintf with the "%g" format.

参数
valueDouble to print.
返回
Reference to *this for chaining.

◆ operator<<() [7/19]

TerminalStream& vlink::TerminalStream::operator<< ( float  value)
noexcept

Formats a float through snprintf with the "%g" format.

参数
valueFloat to print.
返回
Reference to *this for chaining.

◆ operator<<() [8/19]

TerminalStream& vlink::TerminalStream::operator<< ( int  value)
noexcept

◆ operator<<() [9/19]

TerminalStream& vlink::TerminalStream::operator<< ( long double  value)
noexcept

Formats a long double through snprintf with the "%Lg" format.

参数
valueLong double to print.
返回
Reference to *this for chaining.

◆ operator<<() [10/19]

TerminalStream& vlink::TerminalStream::operator<< ( long long  value)
noexcept

◆ operator<<() [11/19]

TerminalStream& vlink::TerminalStream::operator<< ( long  value)
noexcept

◆ operator<<() [12/19]

TerminalStream& vlink::TerminalStream::operator<< ( ManipType  manip)
noexcept

Applies a custom or built-in ManipType manipulator to the stream.

参数
manipFunction pointer invoked with *this.
返回
Whatever manip returns, normally a reference to *this.

◆ operator<<() [13/19]

TerminalStream& vlink::TerminalStream::operator<< ( short  value)
noexcept

◆ operator<<() [14/19]

TerminalStream& vlink::TerminalStream::operator<< ( std::ostream &  *)(std::ostream &)
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.

返回
Reference to *this for chaining.

◆ operator<<() [15/19]

TerminalStream& vlink::TerminalStream::operator<< ( std::string_view  str)
noexcept

Appends the bytes of str verbatim, including embedded NULs.

参数
strSource view.
返回
Reference to *this for chaining.

◆ operator<<() [16/19]

TerminalStream& vlink::TerminalStream::operator<< ( unsigned int  value)
noexcept

◆ operator<<() [17/19]

TerminalStream& vlink::TerminalStream::operator<< ( unsigned long long  value)
noexcept

◆ operator<<() [18/19]

TerminalStream& vlink::TerminalStream::operator<< ( unsigned long  value)
noexcept

◆ operator<<() [19/19]

TerminalStream& vlink::TerminalStream::operator<< ( unsigned short  value)
noexcept

◆ operator=() [1/2]

TerminalStream& vlink::TerminalStream::operator= ( const TerminalStream )
deletenoexcept

◆ operator=() [2/2]

TerminalStream& vlink::TerminalStream::operator= ( TerminalStream &&  )
deletenoexcept

◆ write_raw()

TerminalStream& vlink::TerminalStream::write_raw ( const char *  data,
size_t  len 
)
noexcept

Appends a raw byte array verbatim to the buffer.

参数
dataPointer to len bytes; not retained beyond the call.
lenNumber of bytes to append; 0 is a no-op.
返回
Reference to *this for chaining.

类成员变量说明

◆ kDefaultBufferSize

constexpr size_t vlink::TerminalStream::kDefaultBufferSize {1024 * 1024 * 1}
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.


该类的文档由以下文件生成: