Skip to content

console

The console package controls the terminal: text and background colors, clearing the screen, showing or hiding the cursor, reading single keys, and reading passwords without echoing them.

fg(color) sets the text color and bg(color) the background; reset() restores the defaults. Color names are case-insensitive:

black, dark_blue, dark_green, dark_cyan, dark_red, dark_magenta, dark_yellow, gray, dark_gray, blue, green, cyan, red, magenta, yellow, white

console::fg("green")
println "Build passed"
console::reset()
console::fg("white")
console::bg("dark_red")
println " FAILED "
console::reset()

For labeled status messages, cli::success and friends handle the colors for you.

console::clear()
console::title("Kiwi monitor")
console::cursor_visible(false)
size = console::size()
println "Terminal is ${size["width"]}x${size["height"]}"
repeat 5 as i do
print "\rWorking... ${i * 20}%"
task::sleep(200)
end
println ""
console::cursor_visible(true)

To print at a specific position, use the printxy statement.

name = console::read("Name: ")
password = console::read_secret("Password: ", "*") # echoes * for each key
key = console::readkey() # one key press, no Enter needed
console::bg(color: string)

Sets the terminal background color.

ParameterTypeDefaultDescription
colorstringThe color name (e.g., "RED", "BLUE"). See console::get_colors().
console::fg(color: string)

Sets the terminal foreground (text) color.

ParameterTypeDefaultDescription
colorstringThe color name (e.g., "GREEN", "WHITE"). See console::get_colors().
console::map_color(name: string): integer

Maps a color name to its integer code.

ParameterTypeDefaultDescription
namestringThe color name (case-insensitive).

Returns integer — The color code, or 0 (black) if the name is not recognized.

console::get_colors(): hashmap

Returns a hashmap of supported color names to their integer codes.

Returns hashmap — A map of color name strings to integer codes.

colors = console::get_colors()
println(colors["RED"]) # 12
console::reset()

Resets the terminal foreground and background colors to their defaults.

console::clear()

Clears the terminal screen.

console::cursor_visible(is_visible: boolean)

Shows or hides the terminal cursor.

ParameterTypeDefaultDescription
is_visiblebooleanPass true to show the cursor, false to hide it.
console::size()

Returns the current terminal window size.

Returns hashmap — A hashmap with width and height keys.

console::title(new_title: string)

Sets the terminal window title.

ParameterTypeDefaultDescription
new_titlestringThe title to display in the terminal window.
console::read(msg: string = "")

Reads a line of input from the console with an optional prompt.

ParameterTypeDefaultDescription
msgstring""An optional prompt to display before reading input.

Returns string — The input entered by the user.

console::readline(msg: string = "")

Reads a line of input from the console with an optional prompt.

ParameterTypeDefaultDescription
msgstring""An optional prompt to display before reading input.

Returns string — The input entered by the user.

console::read_secret(msg: string = "", mask: string = "")

Reads a line of secret input (e.g., a password) without echoing characters.

ParameterTypeDefaultDescription
msgstring""An optional prompt to display.
maskstring""An optional mask character to display in place of input (default none).

Returns string — The secret input entered by the user.

console::readkey(intercept: boolean = true)

Reads a single keypress from the console.

ParameterTypeDefaultDescription
interceptbooleantrueIf true, the key is not echoed to the console (default true).

Returns hashmap — A hashmap with key info (e.g., key, modifiers).

console::read_key(intercept: boolean = true)

Reads a single keypress from the console.

ParameterTypeDefaultDescription
interceptbooleantrueIf true, the key is not echoed to the console (default true).

Returns hashmap — A hashmap with key info (e.g., key, modifiers).

console::write(msg: string = "")

Writes a message to the console without a trailing newline.

ParameterTypeDefaultDescription
msgstring""The message to write.
console::writeln(msg: string = "")

Writes a message to the console followed by a newline.

ParameterTypeDefaultDescription
msgstring""The message to write.
console::writeline(msg: string = "")

Writes a message to the console followed by a newline.

ParameterTypeDefaultDescription
msgstring""The message to write.