Console

Console

Console provides utilities for interacting with a text console. Console#readInt, Console#readFloat, Console#readBoolean, and Console#readLine prompt the user for input and parse it to the corresponding type. This prompt will use the blocking browser prompt by default, but can be configured using Console#onInput. Console also exposes Console#print and Console#println, which are used for emitting output. By default the output will print to the console, but can be configured using Console#onOutput.

Constructor

new Console(options)

Source:
Initialize the console class, additionally configuring any event handlers.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
input function Function invoked when asking for user input asynchronously. This function is invoked with the string of the prompt, i.e. readIntAsync('give me an int!'). The result of invoking onPrompt will be awaited, then parsed to configrm it's the appropriate data type (a float, in the case of readFloat, for example). If onPrompt is undefined, window.prompt is used as a fallback.
output function Function invoked when printing. This function is invoked with any output, either in the case of explicit calls to `print` or `println` or internal calls within the library. If onPrint is undefined, console.log is used as a fallback.
clear function Function invoked when clear() is called.
prompt function Function that transforms the prompt string to a function like `readInt` before it is passed to `prompt`.

Members

onClear

Source:
Function invoked when Console#clear is called.

onInput :function

Source:
Function invoked when asking for asynchronous user input with the read*Async functions. This function is invoked with the string of the prompt, i.e. readIntAsync('give me an int!'). The result of invoking onPrompt will be awaited, then parsed to configrm it's the appropriate data type (a float, in the case of readFloat, for example). If onPrompt is undefined, window.prompt is used as a fallback.
Type:
  • function

onOutput :function

Source:
Function invoked when printing. This function is invoked with any output, either in the case of explicit calls to `print` or `println` or internal calls within the library. If onPrint is undefined, console.log is used as a fallback.
Type:
  • function

Methods

configure(options)

Source:
Configure the Console instance, providing methods it invokes when prompting for input and emitting output.
Parameters:
Name Type Description
options Object
Properties
Name Type Description
input function Function invoked when asking for user input asynchronously. This function is invoked with the string of the prompt, i.e. readIntAsync('give me an int!'). The result of invoking onPrompt will be awaited, then parsed to configrm it's the appropriate data type (a float, in the case of readFloat, for example). If onPrompt is undefined, window.prompt is used as a fallback.
output function Function invoked when printing. This function is invoked with any output, either in the case of explicit calls to `print` or `println` or internal calls within the library. If onPrint is undefined, console.log is used as a fallback.
clear function Function invoked when clear() is called.
prompt function Function that transforms the prompt string to a function like `readInt` before it is passed to `prompt`.

readLinePrivate(promptString)

Source:
Private method used to read a line.
Parameters:
Name Type Description
promptString string The line to be printed before prompting.

readLinePrivateAsync(promptString)

Source:
Private method used to read a line using the read*Async methods.
Parameters:
Name Type Description
promptString string The line to be printed before prompting.