APIConsole

Console

The program’s standard streams as the Console effect.

print, write, and readLine are the prelude’s; writeTo reaches standard error, and source and sink adapt the streams for Reader and Writer. None of them raises an error: the runner owns failure. A program’s main runs under runSystem unless it installs another runner, and runTest answers from bytes and captures the output exactly.

import Bytes
import Console

captured = Console.runTest (Bytes.fromString "Ana\n") {
    print "Your name?"
    case readLine() of
        Nothing -> print "No input"
        Just line -> print ("Hello, " ++ line.text)
    }

captured.stdout == Bytes.fromString "Your name?\nHello, Ana\n"
captured.remaining == Bytes.empty

Output

type Output    = Stdout    | StderrSource

A standard output stream.

Constructors

Stdout

Stdout : OutputSource

Standard output.

Stderr

Stderr : OutputSource

Standard error.

Instances:

Eq Output
Show Output

Transcript

type Transcript a =    { value : a    , stdout : Bytes    , stderr : Bytes    , remaining : Bytes    }Source

What runTest observed: the action’s result, each output stream exactly as written, and the input it did not consume.

Fields

value

value : aSource

The action’s result.

stdout

stdout : BytesSource

Everything written to standard output.

stderr

stderr : BytesSource

Everything written to standard error.

remaining

remaining : BytesSource

The input left unread.

Console

effect ConsoleSource

The standard streams. Handlers answer every operation; none reports an error.

Operations

readLine

readLine : () ->{Console} Maybe LineSource

The next line of standard input with its ending, or Nothing at the end of input.

readBytes

readBytes : Int ->{Console} Maybe BytesSource

Up to count bytes of standard input, which may be fewer, or Nothing at the end of input. A count of zero or less answers empty bytes while input remains.

writeBytes

writeBytes : Output -> Bytes ->{Console} ()Source

Writes all the bytes to the stream.

print

print : Display a => a ->{Console} ()Source

Writes the value’s display text and a newline to standard output.

runSystem

runSystem : (() ->{Console, e} a) ->{IO, e} aSource

Answers Console with the process’s standard streams, or the REPL session’s. A stream error ends the program with the error’s description on the host’s diagnostic channel.

runTest

runTest : Bytes -> (() ->{Console, e} a) ->{e} Transcript aSource

Answers reads from input, at its end as at the end of a stream, and captures each output stream exactly, without adding or normalizing newlines. Writes always succeed.

Tasks that inherit the runner share its streams. Each read consumes its input exactly once and each write is captured whole, but writes and reads from different tasks interleave in scheduling order.

import Bytes
import Console exposing (Output(..))

warned = Console.runTest Bytes.empty { Console.writeTo Stderr "warning\n" }

warned.stderr == Bytes.fromString "warning\n"
warned.stdout == Bytes.empty

sink

sink : Output -> Sink {Console}Source

An output stream as a byte sink for Writer.

source

source : Source {Console}Source

Standard input as a byte source for Reader.

write

write : String ->{Console} ()Source

Writes the text to standard output as it is, without a newline.

writeTo

writeTo : Output -> String ->{Console} ()Source

Writes the text to the stream as it is, without a newline.