Skip to main content

OutputWrapper

Wrapper around stdout/stderr

Attributes

AttributeTypeDescription
_outfile-like objectThe underlying stream object, such as stdout or stderr, that this wrapper directs output to.
style_funccallableA 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.
endingstring = \nThe 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

NameTypeDescription
outobjectThe output stream object (e.g., stdout or stderr) to wrap.
endingstring = \nThe default string to append to the end of written messages.

Signature

def OutputWrapper(
out: file-like object,
ending: string = \n
)

Parameters

NameTypeDescription
outfile-like objectThe underlying stream (typically stdout or stderr) to which output is written
endingstring = \nThe 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

TypeDescription
callableThe 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

TypeDescription
nullnull

isatty()

@classmethod
def isatty() - > boolean

Checks if the underlying output stream is connected to a terminal device.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
msgstringThe text content to be written to the output stream
style_funccallable = nullAn optional formatting function to wrap the message; defaults to the instance's style_func
endingstring = nullAn optional string to append to the message; defaults to the instance's default ending

Returns

TypeDescription
nullnull