This module contains functions related to input/output operations for communicating with the console.

Include using

var io = use("std:io");

print

print(value = "")

Prints a value to the console without a trailing newline.

  • Parameters:
    • value (Any, optional): The value to be printed to the output stream. Defaults to "".
  • Returns: (Nil)
var io = use("std:io");

io.print("hello, world!\n");

println

println(value = "")

Prints a value to the console, automatically appending a newline at the end.

  • Parameters:
    • value (Any, optional): The value to be printed. Defaults to "".
  • Returns: (Nil)
var io = use("std:io");

io.println("hello, world!");

input

input(prompt = "")

Prompts the user for input and returns the entered text as a string.

  • Parameters:
    • prompt (String, optional): The display prompt string. Defaults to "".
  • Returns: (String) The text entered by the user.
var io = use("std:io");

var name = io.input("enter your name: ");
io.println("hello, ${name}!");

read_secret

read_secret(prompt = "")

Prompts the user for sensitive input (such as passwords or API keys) without displaying characters on the screen.

  • Parameters:
    • prompt (String, optional): The display prompt string. Defaults to "".
  • Returns: (String) The secret text entered by the user.
var io = use("std:io");

var password = io.read_secret("enter password: ");

color

color(text, color_name)

Wraps text in ANSI color control escape codes for styled terminal output.

Supported color names: "red", "green", "yellow", "blue", "magenta", "cyan", "bold", "dim".

  • Parameters:
    • text (Any): The text or object to style.
    • color_name (String): The name of the target color or style.
  • Returns: (String) An ANSI colorized string.
var io = use("std:io");

echo io.color("SUCCESS: File saved!", "green");
echo io.color("ERROR: File missing!", "red");

clear

clear()

Clears the terminal screen and resets the cursor to the top-left corner.

var io = use("std:io");

io.clear();

flush

flush()

Manually flushes the standard output buffer (stdout).

var io = use("std:io");

io.print("Processing...");
io.flush();

is_tty

is_tty()

Returns true if the standard output stream is attached to an interactive terminal TTY.

  • Returns: (Bool) true if connected to a TTY, otherwise false.
var io = use("std:io");

if (io.is_tty()) {
    echo "Running in terminal";
}

set_cursor

set_cursor(x, y)

Positions the terminal cursor at column x and row y using ANSI positioning sequences.

  • Parameters:
    • x (Number): The column coordinate (1-indexed).
    • y (Number): The row coordinate (1-indexed).
var io = use("std:io");

io.set_cursor(1, 1); // Move cursor to top-left

write_err

write_err(value = "")

Prints a value directly to standard error (stderr), appending a newline.

var io = use("std:io");

io.write_err("error: process failed");