Skip to content

std.io

The console, text in and out. main asks for a Console. It is the terminal under strata run, and the test’s own output in a test.

capability Terminal {}

The process’s own terminal. Only the runtime makes one, for main.

type Recorder = { input: List[String], out: String, err: List[String] }

A console for tests. It reads input line by line. out is standard output as written. err holds the lines written to standard error.

capability ReplConsole {}

The console of code typed at strata repl. Only strata repl makes one. Its output, standard error included in order, is shown with the line’s result. read_line reads the REPL’s next input.

type InputError = { message: String }

Why reading standard input failed: the system’s message, or that the input isn’t UTF-8 text.

capability trait Console {
/// Writes `text` and a newline to standard output.
fn print(mut self, text: String)
/// Writes `text` to standard output, without a newline.
fn write(mut self, text: String)
/// Writes `text` and a newline to standard error.
fn eprint(mut self, text: String)
/// The next line of standard input without its line ending. `None` at the end of the input.
/// Bytes that aren't UTF-8 read as U+FFFD.
fn read_line(mut self) -> Option[String]
/// The rest of standard input. A recorder gives its lines, each with a newline.
/// An error when a read fails or the input isn't UTF-8 text.
fn read_all(mut self) -> Result[String, InputError]
/// Whether standard input is a terminal rather than a pipe or a file. False for a stand-in.
fn interactive(self) -> Bool
/// A paint for `stream` (std.term), on when it is a terminal that shows colors. Off for a stand-in.
fn paint(self, stream: Stream) -> Paint
}

Text output and input: the terminal, a Recorder, or a mock.

fn recorder(input: List[String]) -> Recorder

A recorder that reads input line by line.

fn printed(r: Recorder) -> List[String]

The lines of a recorder’s standard output.

  • impl Console for Terminal
  • impl Console for Recorder
  • impl Console for ReplConsole