std.io.console
Reading from and writing to the console.
Output needs no capability — it is always available. write and writeln take any type that
satisfies Display; print and println take the string the host boundary is defined in.
print function
pub fn print(value: string)
Writes to standard output without a line break.
Nothing is flushed. A prompt written with print sits in the buffer until flush, which is why
prompt exists.
stdlib/std/io/console.lyr:33
println function
pub fn println(value: string)
Writes to standard output, followed by a line break.
stdlib/std/io/console.lyr:36
eprintln function
pub fn eprintln(value: string)
Writes to standard ERROR, followed by a line break.
Diagnostics belong here rather than in standard output, so a program used in a pipe does not put them into the data.
stdlib/std/io/console.lyr:42
write function
pub fn write<T :: [Display]>(value: T): void
Writes any displayable value without a line break: write(42), write(true), write("hi").
There is no overloading; the Display constraint does the same job and extends to every type
that satisfies it rather than to a fixed list. Monomorphization turns the call into a direct one
per used type, so the generality costs nothing at runtime.
stdlib/std/io/console.lyr:49
writeln function
pub fn writeln<T :: [Display]>(value: T): void
Writes any displayable value, followed by a line break.
stdlib/std/io/console.lyr:54
readLine function
pub fn readLine(): ?string
Reads one line from standard input, without its line break.
null at end of input. Optional rather than an empty string, because EOF is a state and not a
line: a program reading until null stops, one reading until "" never does.
stdlib/std/io/console.lyr:64
readAll function
pub fn readAll(): string
Reads everything up to end of input, for filters that need the whole text.
The input is held in memory in full. lines is the way through a stream larger than that.
stdlib/std/io/console.lyr:69
readChar function
pub fn readChar(): ?char
Reads a single code point, or null at end of input.
stdlib/std/io/console.lyr:72
isInteractive function
pub fn isInteractive(): bool
Whether standard input and output are a terminal rather than a pipe.
A program writing into a pipe should not put a prompt into the stream, and this is how it knows.
stdlib/std/io/console.lyr:77
flush function
pub fn flush(): void
Pushes buffered output to the console.
Needed as soon as something is written without a line break and has to be visible before the program continues — a prompt being the usual case.
stdlib/std/io/console.lyr:83
eprint function
pub fn eprint(value: string)
Writes to standard error without a line break.
stdlib/std/io/console.lyr:86
prompt function
pub fn prompt(text: string): ?string
Writes text, flushes it, and reads one line.
The flush is the point: without it the question would sit in the buffer while the program waits
for an answer nobody knows is expected. null at end of input, as readLine.
stdlib/std/io/console.lyr:97
LineIterator class
pub class LineIterator :: [Iterator<string>]
The iterator lines hands out. Yields each line of standard input until it ends.
done: bool
pub mut fn next(): ?string
The next line, or null once the input has ended. Ends for good after the first null.
stdlib/std/io/console.lyr:104
lines function
pub fn lines(): Iterator<string>
The lines of standard input, as an iterator — the idiomatic shape of a filter:
for (line in console.lines()) { … }
An iterator rather than a string[]: the input can be larger than memory, and a program that
only counts should not have to collect it first.
stdlib/std/io/console.lyr:126