OutputWrapper
Wrapper around stdout/stderr
Attributes
| Attribute | Type | Description |
|---|---|---|
| _out | file-like object | The underlying stream object, such as stdout or stderr, that this wrapper directs output to. |
| style_func | callable | A callable used to format or colorize output strings before they are written to the stream, defaulting to a pass-through lambda if the stream is not a TTY. |
| ending | string = \n | The character sequence appended to the end of messages if not already present, typically used for line endings. |
Constructor
Signature
def OutputWrapper(
out: object,
ending: string = \n
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| out | object | The output stream object (e.g., stdout or stderr) to wrap. |
| ending | string = \n | The default string to append to the end of written messages. |
Signature
def OutputWrapper(
out: file-like object,
ending: string = \n
)
Parameters
| Name | Type | Description |
|---|---|---|
| out | file-like object | The underlying stream (typically stdout or stderr) to which output is written |
| ending | string = \n | The default character or string to append to messages if they do not already end with it |
Methods
style_func()
@classmethod
def style_func() - > callable
Gets or sets the function used to format output text; it defaults to a no-op lambda if the output is not a TTY.
Returns
| Type | Description |
|---|---|
callable | The current function used to apply styles or formatting to output strings |
flush()
@classmethod
def flush() - > null
Triggers a flush operation on the underlying stream if it supports the flush method.
Returns
| Type | Description |
|---|---|
null | null |
isatty()
@classmethod
def isatty() - > boolean
Checks if the underlying output stream is connected to a terminal device.
Returns
| Type | Description |
|---|---|
boolean | True if the stream is a TTY and supports the isatty method, False otherwise |
write()
@classmethod
def write(
msg: string,
style_func: callable = null,
ending: string = null
) - > null
Writes a message to the stream, optionally applying a style function and appending a specific line ending.
Parameters
| Name | Type | Description |
|---|---|---|
| msg | string | The text content to be written to the output stream |
| style_func | callable = null | An optional formatting function to wrap the message; defaults to the instance's style_func |
| ending | string = null | An optional string to append to the message; defaults to the instance's default ending |
Returns
| Type | Description |
|---|---|
null | null |