Module: io.console

Source: ./io/console.reef


Overview

io/console - Console input/output operations

Provides functions for reading from stdin and writing to stdout/stderr


Functions

fn readLine(): option.Option[string]

Reads a line from standard input Returns Some(line) with trailing newline removed, or None if stdin is at EOF/closed. A blank line (user just pressed Enter) is Some("") -- distinct from None: fgets writes nothing and leaves the buffer empty on EOF, whereas a blank line still gets the "\n" written, so we distinguish the two by checking reef_feof() only when the buffer came back empty.

fn readLinePrompt(prompt: string): option.Option[string]

Reads a line with a prompt Returns Some(line) or None on EOF/stdin-closed -- see readLine().

fn reef_getch(): int

FFI declaration for the runtime helper

fn getchar_raw(): int

Read a single character without echo and without waiting for Enter Returns the character code as int (-1 on error)

fn getch(): option.Option[char]

Read a single character without echo, returns as char type 0.9.2 C16: Some(ch) or None at EOF.

This collapsed libc EOF into '\0'. char has no out-of-band value, so no caller COULD distinguish end-of-input from a real NUL byte, and neither in-stdlib caller did: confirm() reads in an unbounded loop and tests only Y/y/Enter and N/n, so on a closed stdin it re-prompted forever. That is the shape that made getch_demo emit gigabytes when run with stdin at /dev/null.

DELIBERATELY NO getch_or. None here means EOF, not an absent lookup. getch_or(c) would turn end-of-stream into a real character -- which IS the defect C16 fixed here (EOF collapsed to '\0', and confirm() looped forever on it, filling a 47 GB tmpfs during reef-lang#53's own corpus run). A default would reintroduce it through the front door.

fn confirm(prompt: string): bool

Confirmation prompt with default Yes Accepts: Y, y, Enter -> true Accepts: N, n -> false Other keys: re-prompt

fn confirm_default_no(prompt: string): bool

Confirmation prompt with default No Accepts: Y, y -> true Accepts: N, n, Enter -> false


Procedures

proc flushOutput()

Flushes stdout buffer

proc printErr(message: string)

Prints to stderr


Generated by reefc doc