@eryx/stdio Module

JSON

Standard I/O module -- read/write access to stdin, stdout, and stderr.

Provides both synchronous (blocking) and asynchronous (yielding) APIs for interacting with the process's standard streams.

Quick start

local stdio = require("@eryx/stdio")

-- Prompt the user
stdio.write("Enter your name: ")
stdio.flush()
local name = stdio.readln()
stdio.write("Hello, " .. (name or "stranger") .. "!\n")

-- Write to stderr
stdio.writeerr("warning: something happened\n")

-- Check if running in a terminal
local tty = stdio.isatty()
if tty.stdin then
    print("stdin is a terminal")
end

Summary

Functions

stdio.read(bytes: number?)string?
stdio.readline()string?
stdio.write(data: string)()
stdio.writeerr(data: string)()
stdio.flush()()
stdio.readasync(bytes: number?)string?

API Reference

Functions

stdio.read

Reads up to bytes bytes from stdin (default 4096). Returns nil on EOF.

stdio.read(bytes: number?)string?

stdio.readline

Reads one line from stdin, stripping the trailing newline. Returns nil on EOF.

stdio.readline()string?

stdio.write

Writes a string to stdout.

stdio.write(data: string)()

stdio.writeerr

Writes a string to stderr.

stdio.writeerr(data: string)()

stdio.flush

Flushes the stdout buffer.

stdio.flush()()

stdio.flusherr

Flushes the stderr buffer.

stdio.flusherr()()

stdio.readasync

Yields the current coroutine until data is available on stdin, then returns up to bytes bytes (default 4096). Returns nil on EOF. Only one readasync may be pending at a time.

stdio.readasync(bytes: number?)string?

stdio.isatty

Returns a table indicating whether each standard stream is connected to a terminal (TTY).

stdio.isatty()TtyInfo

Types

TtyInfo

Result of isatty() -- indicates which streams are connected to a terminal.

stdin: boolean
stdout: boolean
stderr: boolean