stdio
Built-in standard input / output & utility functions
Example usage
Section titled “Example usage”local stdio = require("@lune/stdio")
-- Prompting the user for basic inputlocal text: string = stdio.prompt("text", "Please write some text")local confirmed: boolean = stdio.prompt("confirm", "Please confirm this action")
-- Writing directly to stdout or stderr, without the auto-formatting of print/warn/errorstdio.write("Hello, ")stdio.write("World! ")stdio.write("All on the same line")stdio.ewrite("\nAnd some error text, too")
-- Reading a single line from stdinlocal line = stdio.readLine()
-- Reading the entire input from stdinlocal input = stdio.readToEnd()Functions
Section titled “Functions”prompt
Section titled “prompt”must_use
Prompts for user input using the wanted kind of prompt:
"text"- Prompts for a plain text string from the user"confirm"- Prompts the user to confirm with y / n (yes / no)"select"- Prompts the user to select one value from a list"multiselect"- Prompts the user to select one or more values from a listnil- Equivalent to"text"with no extra arguments
Parameters
kind- The kind of prompt to usemessage- The message to show the userdefaultOrOptions- The default value for the prompt, or options to choose from for selection prompts
function stdio.color(color: Color): stringmust_use
Return an ANSI string that can be used to modify the persistent output color.
Pass "reset" to get a string that can reset the persistent output color.
Example usage
stdio.write(stdio.color("red"))print("This text will be red")stdio.write(stdio.color("reset"))print("This text will be normal")Parameters
color- The color to use
Returns
- A printable ANSI string
function stdio.style(style: Style): stringmust_use
Return an ANSI string that can be used to modify the persistent output style.
Pass "reset" to get a string that can reset the persistent output style.
Example usage
stdio.write(stdio.style("bold"))print("This text will be bold")stdio.write(stdio.style("reset"))print("This text will be normal")Parameters
style- The style to use
Returns
- A printable ANSI string
format
Section titled “format”function stdio.format(...: any): stringmust_use
Formats arguments into a human-readable string with syntax highlighting for tables.
Parameters
...- The values to format
Returns
- The formatted string
function stdio.write(s: string) endWrites a string directly to stdout, without any newline.
Parameters
s- The string to write to stdout
ewrite
Section titled “ewrite”function stdio.ewrite(s: string) endWrites a string directly to stderr, without any newline.
Parameters
s- The string to write to stderr
readLine
Section titled “readLine”function stdio.readLine(): stringmust_use
Reads a single line from stdin.
If stdin is closed, returns all input up until its closure.
Returns
- The input from stdin
readToEnd
Section titled “readToEnd”function stdio.readToEnd(): stringmust_use
Reads the entire input from stdin.
Returns
- The input from stdin
