std.io.console
Reading from and writing to the console.
Output needs no capability — it is always available. print and println take any type that
satisfies Display: println(42), println(true), println("hi").
print function
pub fn print<T :: [Display]>(value: T): void
Writes any displayable value without a line break: print(42), print("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.
Nothing is flushed. A prompt written with print sits in the buffer until flush, which is why
prompt exists.
stdlib/std/io/console.lyr:45
println function
pub fn println<T :: [Display]>(value: T): void
Writes any displayable value, followed by a line break.
stdlib/std/io/console.lyr:50
eprint function
pub fn eprint<T :: [Display]>(value: T): void
Writes any displayable value to standard ERROR without a line break.
stdlib/std/io/console.lyr:55
eprintln function
pub fn eprintln<T :: [Display]>(value: T): void
Writes any displayable value 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:63
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:73
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:78
readChar function
pub fn readChar(): ?char
Reads a single code point, or null at end of input.
stdlib/std/io/console.lyr:81
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:86
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:92
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:103
LineIterator class
pub class LineIterator :: [Iterator<string>]
The iterator lines hands out. Yields each line of standard input until it ends.
done: bool
Set once readLine answered null; from then on the iterator ends.
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:110
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:133