Skip to content

Std.Console

effect Console

Writes a line to standard output (print_line) or standard error (print_error_line).

  • fn print_line(text: String) -> ()

    Writes text and a line ending to standard output.

  • fn print_error_line(text: String) -> ()

    Writes text and a line ending to standard error.

handler SystemConsole: Console

Writes to the host’s standard output and standard error, through the same path as SystemStdout and SystemStderr of Std.Process (JS: file descriptors 1 and 2, or console.log and console.error on a host without them; C stdout and stderr). Stateless.

handler TestConsole: Console
uses { State[List[String]] }

The test handler ([effect.state]). It keeps the printed lines in State[List[String]], so use it inside State.run:

(_, lines) = State.run([], || with TestConsole { greet(1) })
assert lines == ["Hello, alice!"]

print_line appends the line in the printed order. print_error_line drops the line.