FixIO Documentation

Back to summary

import "io/console"; // not needed for print/progress/beep and the simple variant of prompt

Console input/output

These functions provide basic access to the console. The functions are designed in a way to be both programmer and user friendly. They are synchronized so multiple tasks (threads) won't print over in a middle of the line and the output is locked during an active prompt. The built-in log function is augmented with this behavior as well.

The state is tracked so for example the progress function (which replaces the current line if called repeatedly) will be correctly cleared when the other functions are called or when the process exits.

The functions don't allow to use control characters (these are converted to '?'). The only supported control characters are a tab ('\t') and a newline ('\n') characters. The progress function disallows newlines as they can't work with it. If you need to output arbitrary characters use the ProcessStream class.

Use the Console class to use the console in an advanced way.

Global functions

function print(value)
Prints given string (other values are converted) to the standard output stream with added newline.
Use the built-in log function to print to the standard error stream instead.
function prompt(msg: String): String
function prompt(msg: String, handler: PromptHandler): String
Shows a prompt with the given message (without newline) and returns the entered value from the user. Optionally you can provide a prompt handler to support autocomplete functionality or other customization.
function progress(msg: String)
Shows a progress, repeated calls updates the same line.
function beep()
Emits a beep sound or an alternative notification such as blinking of the console.

Custom logging

function set_log_function(func)
Sets a new logging function. The logging function receives a single parameter, it should convert any non-string values into a string using the to_string built-in function. The function can use the log function to produce an output (it will use the default implementation when called from the custom log handler). To revert back to the default logging function just pass null as a function.

Utility functions

function prompt_int(msg: String): Integer
function prompt_long(msg: String): Long
function prompt_float(msg: String): Float
function prompt_double(msg: String): Double
A variant of a prompt that returns the entered value as a specific type. You need to check if a valid value was entered by using the built-in functions (is_int and is_float) or checking for null for the Long and Double variants.
function prompt_password(msg: String): String
function prompt_password(msg: String, replacement_char: Integer): String
function prompt_password(msg: String, replacement_char: Integer, max_length: Integer): String
Shows a prompt for entering a password. By default the '*' character is used as a replacement character. You can also specify 0 to disable showing the length of the password.

Note: Special security precautions are used to make sure the password is only at one place in the memory and is properly cleared on cancellation or an internal error. The maximum length is 256 by default. When setting a different maximum length keep in mind that the maximum capacity is allocated before use. It is advised to explicitly overwrite the password after use.