FixIO Documentation

Back to summary

import "io/console";

Console class

Console provides an advanced access to the console. To use the console it must be activated first. This gives an exclusive access to the console and changes how it behaves. This is incompatible with basic functions such as print and log and they are therefore disabled when the console is active. It is highly recommended to use the set_log_function to implement custom logging.

Due to the historical reasons and a huge variety of various terminal emulators both the printing of various characters outside ASCII and ability to recognize various keys and their modifiers can be limited. What works on one platform or a terminal emulator may not work in another.

Use the global functions to use the console in a simple way.

Constants

COLOR_BLACK        =  0 (0)
COLOR_DARK_RED     =  1 (1)
COLOR_DARK_GREEN   =  2 (2)
COLOR_DARK_YELLOW  =  3 (3)
COLOR_DARK_BLUE    =  4 (4)
COLOR_DARK_MAGENTA =  5 (5)
COLOR_DARK_CYAN    =  6 (6)
COLOR_LIGHT_GRAY   =  7 (7)
COLOR_DARK_GRAY    =  8 (8)
COLOR_RED          =  9 (9)
COLOR_GREEN        = 10 (A)
COLOR_YELLOW       = 11 (B)
COLOR_BLUE         = 12 (C)
COLOR_MAGENTA      = 13 (D)
COLOR_CYAN         = 14 (E)
COLOR_WHITE        = 15 (F)
The available colors.

Initialization

static function is_present(): Boolean
Returns true when the console is present. A direct access to the console is not possible when the standard streams are redirected or when the platform doesn't support such functionality.
static function set_active(active: Boolean)
Activates or deactivates the console access. When activated the normal printing and logging functions are disabled as they are incompatible with direct console access. It is highly recommended to use the set_log_function to implement custom logging.
static function is_active(): Boolean
Returns true when the console is activated.

Properties

static function get_width(): Integer
static function get_height(): Integer
Returns the size of the console (can be called even when the console is not activated, may return 0 when the size can't be determined).

Drawing

static function clear()
Clears the whole console and puts the cursor to the top-left position.
static function put_text(text: String)
static function put_text(text: String, off: Integer, len: Integer)
Puts a text (or it's portion) at the current cursor position and advances the cursor. Wrapping to new lines is disabled.
static function get_cursor(): Integer[]
Returns the position of the cursor. On Windows the cursor Y can be negative when the console window has not enough of history.
static function set_cursor(x: Integer, y: Integer)
Sets the position of the cursor.
static function move_cursor(rel_x: Integer, rel_y: Integer)
Moves the cursor in a relative way.
static function show_cursor()
static function hide_cursor()
Shows or hides the cursor.
static function reset_color()
Resets the current color to the default.
static function set_color(background: Integer, foreground: Integer)
Sets the current color.
static function scroll(rel_y: Integer)
Scrolls the console contents. When scrolling down (positive Y) new lines are inserted at the bottom and the whole content including the history is moved upwards. The newly uncovered area is set to the current color. In the opposite direction only the currently visible portion is scrolled. The history is not affected, creating a discontinuity. For this reason it is not recommended to scroll up.

Events

static function get_event(): ConsoleEvent
static function get_event(timeout: Integer): ConsoleEvent
Waits for an event and returns it. Optionally you can set a timeout in milliseconds (0 returns immediatelly, negative means indefinite waiting).