Skip to content

IoConsole

A Console over another Io.

Each write reaches the stream as one write_all of its pieces joined, so a line and its terminator arrive in one write of the stream. Nothing is translated on the way through. capture wraps an Io that is not a console in one of these.

line_ending is "\n", is_tty is false, and geometry() has no dimensions.

Errors

Exception Condition
TypeError The stream is not an Io
StateError The console is closed

Inherits from: Console

Constructor

IoConsole io …

Wraps a stream in a console.

Parameters

NameTypeDescription
io io.Io Stream to write to.
:can_style? Bool Emit ANSI styling. Off by default.

Example

fs.open build.log w do |log|
  term.capture (IoConsole log can_style: true) do
    echo $warning

Fields

writable @ Bool [get]

Whether the console writes, which it does until it is closed.

Methods

close()

Closes the console, leaving the stream open. Closing a closed console does nothing.

flush()

Flushes the stream, if it has a flush.

write *data -> Int

Writes data, given in pieces.

Parameters

NameTypeDescription
*data (Str | Bin) Pieces to write, in order.

Returns

The number of bytes written, which is all of them.