Read-Eval-Print Loop (REPL) environment.
A Read-Eval-Print Loop (REPL) environment is an interactive programming environment which takes individual user inputs (e.g., single expressions), evaluates those inputs, and returns the result. Accordingly, a program written in a REPL environment is executed piecewise and sequentially.
REPL environments find common use in exploratory programming, prototyping, and debugging.
The REPL environment exposed here is available both as a standalone application and as a library which is embeddable in other libraries and applications.
var REPL = require( '@stdlib/repl/ctor' );Returns a REPL instance.
// Create a new REPL:
var repl = new REPL();
// ...
// Close the REPL:
repl.close();The function accepts the following options:
- input: input (readable) stream. Default:
stdin. - output: output (writable) stream. Default:
stdout. - sandbox:
booleanindicating whether to run a REPL in a sandboxed context. Default:false. - timeout: number of milliseconds to execute a command before terminating execution. Default:
4294967295. - isTTY:
booleanindicating whether the input and output streams should be treated like a TTY (terminal) and whether the REPL should use ANSI/VT100 escape codes when writing to the output stream. - inputPrompt: input prompt. If the input prompt includes the character sequence
%d, the input prompt includes line numbers. Default:'In [%d]: '. - outputPrompt: output prompt. If the output prompt includes the character sequence
%d, the output prompt includes line numbers. Default:'Out[%d]: '. - welcome: welcome message.
- padding: number of empty lines between consecutive commands. Default:
1. - load: file path specifying a JavaScript file to load and evaluate line-by-line (e.g., a previous REPL history file).
- save: file path specifying where to save REPL command history.
- log: file path specifying where to save REPL commands and printed output.
- quiet:
booleanindicating whether log information, confirmation messages, and other possible REPL diagnostics should be silenced. Default:false.
Returns a REPL context.
// TODOResets a REPL's execution context.
// TODOClears a REPL's history.
// TODOLoads and evaluates a JavaScript file line-by-line.
// TODOResets a REPL.
// TODOClears the entire REPL screen and scrollback history.
// TODOThis method is only applicable for TTY REPLs. In non-TTY REPLs, this method is a non-operation.
Clears the current line.
// TODOThis method is only applicable for TTY REPLs. In non-TTY REPLs, this method is a non-operation.
Clears the current REPL command buffer (i.e., clear any command which has been buffered but not yet executed).
// TODOCloses a REPL.
// TODOREPL instances support the following commands...
Returns the package name associated with a provided alias or class instance.
// TODO
Note: only direct instances of documented built-in constructors are supported.
Returns aliases related to a specified alias or class instance.
// TODO
Note: only direct instances of documented built-in constructors are supported.
Result of the last successfully executed command.
// TODO
Reads a value from a specified workspace.
// TODO
Assigns a value to a variable in a specified workspace.
// TODO
Clears the entire REPL screen and scrollback history.
// TODO
Note: this function is only applicable for TTY REPLs. In non-TTY REPLs, this function is a non-operation.
Clears the REPL history.
// TODO
Deletes user-defined documentation.
// TODO
The function supports the following options:
-
include: inclusion filter. May be either an array-like
objector a regular expression. -
exclude: exclusion filter. May be either an array-like
objector a regular expression. -
filter: filter type. This option is only applicable for array-like
objectfilters. Must be one of the following values:'alias': filter based on documentation alias. If a filter matches a documentation alias, the user-defined documentation is removed.'value': filter based on object reference. If a filter matches an associated object reference, the user-defined documentation is removed.'*': filter based on both documentation alias and object reference. If a filter matches either a documentation alias or an associated object reference, the user-defined documentation is removed.
Default:
'*'.
// TODO
Deletes user-defined variables in the current workspace.
// TODO
The function supports the following options:
- include: variable name inclusion filter. May be either an array-like
objector a regular expression. - exclude: variable name exclusion filter. May be either an array-like
objector a regular expression.
// TODO
Deletes user-defined variables in a specified workspace.
// TODO
By default, the function clears user-defined variables in the current workspace. To clear user-defined variables in a different workspace, provide a workspace name.
// TODO
The function supports the following options:
- include: variable name inclusion filter. May be either an array-like
objector a regular expression. - exclude: variable name exclusion filter. May be either an array-like
objector a regular expression.
// TODO
Returns the name of the current workspace.
// TODO
Deletes a workspace.
// TODO
If not provided an argument, the REPL deletes the current workspace and switches to the 'base' workspace.
// TODO
Note: the 'base' workspace cannot be deleted.
Evaluates an expression in a specified workspace.
// TODO
Runs examples for a specified alias, property, or class instance.
// TODO
Note: only direct instances of documented built-in constructors are supported.
Prints help text.
// TODO
To print help text for an alias,
// TODO
To print help text for a property,
// TODO
To print help text for a class instance,
// TODO
Note: only direct instances of documented built-in constructors are supported.
Prints abbreviated help text for a provided alias, property, or class instance.
// TODO
Note: only direct instances of documented built-in constructors are supported.
Returns a boolean indicating whether a string is a reserved keyword in the REPL environment.
// TODO
Loads and evaluates a JavaScript file, such as a REPL history file, line-by-line.
// TODO
Loads variables from a specified workspace into the current workspace.
// TODO
The function supports the following options:
- **include: variable name inclusion filter. May be either an array-like
objector a regular expression. - **exclude: variable name exclusion filter. May be either an array-like
objector a regular expression. - override:
booleanindicating whether to override existing workspace variables. Default:true.
// TODO
Starts logging commands and printed output to a specified file path.
// TODO
Stops logging commands and printed output to a file path associated with a specified record identifier.
// TODO
Renames a workspace.
// TODO
Note: the new workspace name must not already exist. The only exception is when the old name and the new name are the same; in which case, invoking this command is a non-operation.
Note: as a 'base' workspace must always exist, when renaming the 'base' workspace, variables from the 'base' workspace are simply copied to a new workspace and the 'base' workspace cleared of user-defined variables.
Exits the REPL.
// TODO
Reruns previous commands.
// TODO
By default, the command re-executes the previous command. If provided an integer, the previous n commands are re-executed.
// TODO
If provided a regular expression, the most recent command matching the regular expression is rerun.
// TODO
If provided an array of command identifiers, the command corresponding to each identifier is rerun.
// TODO
If provided a subsequence string, the command corresponding to each resolved command identifier is rerun.
// TODO
WARNING: be careful when re-evaluating previously executed rerun commands, as this can lead to infinite execution loops.
Resets the REPL.
// TODO
Saves previous commands to a specified file path.
// TODO
Starts saving commands to a specified file path.
// TODO
Stops saving commands to a file path associated with a specified record identifier.
// TODO
Adds user-defined documentation.
// TODO
If user-defined documentation already exists for the provided alias, the current documentation is overwritten.
// TODO
Returns a list of variable names in the current workspace.
// TODO
The function supports the following options:
- include: regular expression variable name inclusion filter.
- exclude: regular expression variable name exclusion filter.
- types: array-like
objectcontaining variable type inclusion filter(s). - details:
booleanindicating whether to include additional variable details, such as variable type, contents, etc. Default:false.
// TODO
Returns a list of variable names in a specified workspace.
// TODO
The function supports the following options:
- include: regular expression variable name inclusion filter.
- exclude: regular expression variable name exclusion filter.
- types: array-like
objectcontaining variable type inclusion filter(s). - details:
booleanindicating whether to include additional variable details, such as variable type, contents, etc. Default:false.
// TODO
Switch to a specified workspace.
// TODO
If a workspace with the specified name does not exist, the workspace is created.
// TODO
Returns a list of workspace names.
// TODO
The function supports the following options:
- include: regular expression workspace name inclusion filter.
- exclude: regular expression workspace name exclusion filter.
- details:
booleanindicating whether to include additional workspace details, such as variable names, types, contents, etc. Default:false.
// TODO
var join = require( 'path' ).join;
var REPL = require( '@stdlib/repl/ctor' );
function onExit() {
console.log( '' );
console.log( 'REPL closed.' );
}
// Create a new REPL:
var repl = new REPL();
repl.on( 'exit', onExit );
// Load a history file:
repl.load( join( __dirname, 'examples', 'history.txt' ) );
// Close the REPL:
repl.close();Usage: stdlib-repl [options]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--welcome <message> Welcome message.
--input_prompt <prompt> Input prompt. Default: 'In [%d]: '.
--output_prompt <prompt> Output prompt. Default: 'Out[%d]: '.
--padding <padding> Empty lines between commands. Default: 1.
--load <filepath> JavaScript file to evaluate line-by-line.
--save <filepath> File to save REPL command history.
--logfile <filepath> File to log REPL commands and printed output.
--timeout <timeout> Milliseconds before terminating a command.
--quiet Disable printing of REPL logs and diagnostics.
$ stdlib-repl