FixIO Documentation

Back to summary

import "io/console";

PromptHandler class

PromptHandler is used for providing dynamic functionality in console prompts.

Implementations of prompts can access the internal properties using the PromptHandlerImpl class.

Initialization

static function create(): PromptHandler
static function create(max_history_size: Integer): PromptHandler
Creates a new prompt handler. You can optionally set the maximum history size (default is 100).

Properties

function set_replacement_char(char: Integer)
Sets the replacement character. This is used when entering a password. You can also use 0 to disable showing the length of the password. The default value is -1. When this feature is used special security precautions are used.
function get_replacement_char(): Integer
Returns the replacement character.
function set_max_length(size: Integer)
Sets the maximum length. The default value is 0x7FFFFFFF (the maximum length).
function get_max_length(): Integer
Returns the maximum length.
function set_search_label(label: String)
Sets the search label that is displayed in search mode. You can put %s at the place where you want to show the current search text. Use %% to display a single % character.
function get_search_label(): String
Returns the search label.
function is_done(): Boolean
Returns true when the prompt was closed using Ctrl+D. This allow to distinguish between an individual prompt cancel and finishing entering of more values.
function set_text(text: String)
function set_text(text: String, cursor: Integer)
function set_cursor(cursor: Integer)
Sets the current text and cursor position. Setting the cursor to a negative number puts the cursor after the end of the text. It can be either set before using the prompt to set the initial value, during handling of a completion or handling of an event.
function get_text(): String
function get_cursor(): Integer
Gets the current text and cursor position. It is used during the handling of a completion, handling of an event or after the prompt has finished.
function get_choice(cnt: Integer): Integer
Returns the choice for given number of completions. The returned value is a floor remainder of the internal choice number divided by the count.

Methods

virtual function get_history_size(): Integer
virtual function get_history_value(idx: Integer): String
virtual function add_history_value(value: String)
Provides access to the history. When adding it should remove an identical previous entry from the history to prevent duplicates. The default implementation uses an internal array but can be changed to use another source of data.
virtual function get_completion(input: String): String
Provides a completion for given input. The choice property is incremented or decremented every time the user presses the TAB key for the same completion attempt. Use the get_choice method to obtain the current choice based on the number of valid choices. The returned value is the whole input string including the completion. You can also return null in case there are no completion choices available.
virtual function handle_completion(): Boolean
The more advanced completion variant. By default it just calls the simpler get_completion method. Allows more control about the completion: it can change the whole text and move the cursor at any position. Returns true when a completion was provided.
virtual function handle_event(event: ConsoleEvent): Boolean
Handles an event before it is processed. Returns true when it was handled and the changes to the text or cursor needs to be applied. The handler is not called during completion or in search mode.