velt/process: standard input
import { lines, readLine } from "velt/process". Reads standard input. The sync and async readers
share one buffered stream. Text is UTF-8, and invalid bytes become U+FFFD. Before a read waits
for input, what the program wrote to standard output is flushed, as in Node: a prompt printed
with console.log is on the screen while the program waits for the answer.
readLine(): Promise<string | null>/readLineSync(): the line without\n/\r\n, or null at end of input.lines(): AsyncGenerator<string, IoError>: the remaining lines, asreadLinereads them, forfor await (const line of lines())(in Node:for await (const line of readline.createInterface({ input: process.stdin }))).readAll(): Promise<string>/readAllSync(): everything left on standard input.readAllBytes(): Promise<u8[]>/readAllBytesSync(): the same, as raw bytes.stdin.isTTY: whether standard input is a terminal (velt/process).
ts
import { lines } from "velt/process";
let n = 0;
for await (const line of lines()) {
n++;
console.log(`${n}: ${line}`);
}ts
import { readLine } from "velt/process";
console.log("Your name?");
const name = (await readLine()) ?? "stranger";
console.log(`Hello, ${name}`);