Class ConsoleEngineImpl
- All Implemented Interfaces:
CommandRegistry
,ConsoleEngine
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.jline.console.CommandRegistry
CommandRegistry.CommandSession
Nested classes/interfaces inherited from interface org.jline.console.ConsoleEngine
ConsoleEngine.ExecutionResult, ConsoleEngine.WidgetCreator
-
Field Summary
Fields inherited from interface org.jline.console.ConsoleEngine
VAR_NANORC
-
Constructor Summary
ConstructorsConstructorDescriptionConsoleEngineImpl
(Set<ConsoleEngineImpl.Command> commands, ScriptEngine engine, Printer printer, Supplier<Path> workDir, org.jline.builtins.ConfigurationPath configPath) ConsoleEngineImpl
(ScriptEngine engine, Printer printer, Supplier<Path> workDir, org.jline.builtins.ConfigurationPath configPath) -
Method Summary
Modifier and TypeMethodDescription<T> T
consoleOption
(String option, T defval) Reads a console option value with a default value if the option doesn't exist.Executes a command line that does not contain a command known by the system registry.Executes either a JLine script or a ScriptEngine script with the specified arguments.boolean
executeWidget
(Object function) Executes a widget function.expandCommandLine
(String line) Substitutes a command line with a system registry invoke method call.Object[]
expandParameters
(String[] args) Substitutes argument references with their values.expandToList
(List<String> params) Expands a list of script parameters to a string representation.Returns the value of the alias with the specified name.Returns the names of all named pipes.getPipes()
Returns all defined pipes.getVariable
(String name) Gets the value of a console variable.boolean
Checks if an alias with the specified name exists.boolean
hasVariable
(String name) Tests if a variable with the specified name exists.invoke
(CommandRegistry.CommandSession session, String command, Object... args) Execute a command.boolean
Checks if the console engine is currently executing a script.void
Persists an object to a file.postProcess
(Object result) Post-processes the result of executing a command.postProcess
(String line, Object result, String output) Post-processes the result of executing a command.void
Prints an object to the console.void
purge()
Deletes temporary console variables.void
putVariable
(String name, Object value) Creates or updates a console variable.List
<org.jline.reader.Completer> Returns completers for scripts and variables.scripts()
Returns all scripts found in the PATH environment variable.void
setConsoleOption
(String name, Object value) Sets a console option value.void
setLineReader
(org.jline.reader.LineReader reader) Sets the LineReader instance to be used by this console engine.void
setScriptExtension
(String extension) Sets the file name extension used by console scripts.void
setSystemRegistry
(SystemRegistry systemRegistry) Sets the SystemRegistry instance to be used by this console engine.Reads an object from a file.void
Prints an object if tracing is enabled.Methods inherited from class org.jline.console.impl.JlineCommandRegistry
commandDescription, commandInfo, commandOptions, compileCommandDescription, compileCommandInfo, compileCommandOptions, defaultCompleter, parseOptions
Methods inherited from class org.jline.console.impl.AbstractCommandRegistry
alias, commandAliases, commandNames, compileCompleters, doHelpDesc, getCommandMethods, hasCommand, registerCommands, registerCommands, registeredCommand, rename, saveException
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.jline.console.CommandRegistry
commandAliases, commandDescription, commandInfo, commandNames, compileCompleters, hasCommand, name
Methods inherited from interface org.jline.console.ConsoleEngine
execute, execute
-
Constructor Details
-
ConsoleEngineImpl
public ConsoleEngineImpl(ScriptEngine engine, Printer printer, Supplier<Path> workDir, org.jline.builtins.ConfigurationPath configPath) throws IOException - Throws:
IOException
-
ConsoleEngineImpl
public ConsoleEngineImpl(Set<ConsoleEngineImpl.Command> commands, ScriptEngine engine, Printer printer, Supplier<Path> workDir, org.jline.builtins.ConfigurationPath configPath) throws IOException - Throws:
IOException
-
-
Method Details
-
setLineReader
public void setLineReader(org.jline.reader.LineReader reader) Description copied from interface:ConsoleEngine
Sets the LineReader instance to be used by this console engine.The LineReader is used for reading input from the user and providing features like command history, tab completion, and line editing.
- Specified by:
setLineReader
in interfaceConsoleEngine
- Parameters:
reader
- the LineReader instance to use
-
isExecuting
public boolean isExecuting()Description copied from interface:ConsoleEngine
Checks if the console engine is currently executing a script.This method determines whether the console engine is in the process of executing a script, as opposed to processing interactive commands.
- Specified by:
isExecuting
in interfaceConsoleEngine
- Returns:
- true if the console engine is executing a script, false otherwise
-
setSystemRegistry
Description copied from interface:ConsoleEngine
Sets the SystemRegistry instance to be used by this console engine.The SystemRegistry is used for executing commands and managing the console environment. It provides access to registered commands and handles command execution.
- Specified by:
setSystemRegistry
in interfaceConsoleEngine
- Parameters:
systemRegistry
- the SystemRegistry instance to use
-
setScriptExtension
Description copied from interface:ConsoleEngine
Sets the file name extension used by console scripts.This method configures the file extension that the console engine will recognize as indicating a console script. Files with this extension will be treated as console scripts when executing scripts.
- Specified by:
setScriptExtension
in interfaceConsoleEngine
- Parameters:
extension
- the file extension to use for console scripts (e.g., ".jsh")
-
hasAlias
Description copied from interface:ConsoleEngine
Checks if an alias with the specified name exists.This method determines whether an alias has been defined for the specified name. Aliases can be used to create shortcuts for commands or command sequences.
- Specified by:
hasAlias
in interfaceConsoleEngine
- Parameters:
name
- the alias name to check- Returns:
- true if an alias with the specified name exists, false otherwise
-
getAlias
Description copied from interface:ConsoleEngine
Returns the value of the alias with the specified name.This method retrieves the command or command sequence that the specified alias is defined to represent. Aliases can be used to create shortcuts for commands or command sequences.
- Specified by:
getAlias
in interfaceConsoleEngine
- Parameters:
name
- the alias name- Returns:
- the value of the alias, or null if no alias with the specified name exists
-
getPipes
Description copied from interface:ConsoleEngine
Returns all defined pipes.This method retrieves a map of all pipes defined in the console engine. Pipes are used to connect the output of one command to the input of another.
- Specified by:
getPipes
in interfaceConsoleEngine
- Returns:
- a map of defined pipes, where keys are pipe names and values are pipe definitions
-
getNamedPipes
Description copied from interface:ConsoleEngine
Returns the names of all named pipes.This method retrieves a list of all named pipes defined in the console engine. Named pipes are pipes that have been given a specific name for easier reference.
- Specified by:
getNamedPipes
in interfaceConsoleEngine
- Returns:
- a list of named pipe names
-
scriptCompleters
Description copied from interface:ConsoleEngine
Returns completers for scripts and variables.This method retrieves a list of completers that can be used for tab completion of script names and variable names in the console.
- Specified by:
scriptCompleters
in interfaceConsoleEngine
- Returns:
- a list of completers for scripts and variables
-
scripts
Description copied from interface:ConsoleEngine
Returns all scripts found in the PATH environment variable.This method searches for scripts in the directories specified by the PATH environment variable and returns a map of script names to a boolean indicating whether each script is a console script.
- Specified by:
scripts
in interfaceConsoleEngine
- Returns:
- a map where keys are script file names and values are true if the script is a console script
-
expandParameters
Description copied from interface:ConsoleEngine
Substitutes argument references with their values.This method expands arguments that reference variables or other values, replacing them with their actual values. For example, a reference like "$VAR" might be replaced with the value of the variable "VAR".
- Specified by:
expandParameters
in interfaceConsoleEngine
- Parameters:
args
- the arguments to be expanded- Returns:
- the expanded arguments with references replaced by their values
- Throws:
Exception
- if an error occurs during expansion
-
expandToList
Description copied from interface:ConsoleEngine
Expands a list of script parameters to a string representation.This method converts a list of script parameters into a string that can be used in script execution. The parameters may be expanded or formatted according to the console engine's rules.
- Specified by:
expandToList
in interfaceConsoleEngine
- Parameters:
params
- the list of script parameters to expand- Returns:
- a string representation of the expanded parameters list
-
execute
Description copied from interface:ConsoleEngine
Executes either a JLine script or a ScriptEngine script with the specified arguments.This method executes the specified script file with the specified arguments, determining whether it is a JLine script or a ScriptEngine script based on its extension or content.
- Specified by:
execute
in interfaceConsoleEngine
- Parameters:
script
- the script file to executecmdLine
- the raw command line as entered by the userargs
- the arguments to pass to the script- Returns:
- the result of executing the script
- Throws:
Exception
- if an error occurs during execution
-
expandCommandLine
Description copied from interface:ConsoleEngine
Substitutes a command line with a system registry invoke method call.This method expands a command line by replacing it with a call to the system registry's invoke method. This is used to handle command execution through the system registry.
- Specified by:
expandCommandLine
in interfaceConsoleEngine
- Parameters:
line
- the command line to be expanded- Returns:
- the expanded command line with the system registry invoke method call
-
execute
Description copied from interface:ConsoleEngine
Executes a command line that does not contain a command known by the system registry.This method handles the execution of command lines that are not recognized as commands by the system registry. If the line is neither a JLine script nor a ScriptEngine script, it will be evaluated as a ScriptEngine statement.
- Specified by:
execute
in interfaceConsoleEngine
- Parameters:
cmd
- the parsed command or script nameline
- the raw command line as entered by the userargs
- the parsed arguments of the command- Returns:
- the result of executing the command line
- Throws:
Exception
- if an error occurs during execution
-
purge
public void purge()Description copied from interface:ConsoleEngine
Deletes temporary console variables.This method removes all temporary console variables, which are typically created during command execution and are not meant to persist between commands.
- Specified by:
purge
in interfaceConsoleEngine
-
putVariable
Description copied from interface:ConsoleEngine
Creates or updates a console variable.This method creates a new console variable with the specified name and value, or updates an existing variable if one with the specified name already exists.
- Specified by:
putVariable
in interfaceConsoleEngine
- Parameters:
name
- the name of the variable to create or updatevalue
- the value to assign to the variable
-
getVariable
Description copied from interface:ConsoleEngine
Gets the value of a console variable.This method retrieves the value of the console variable with the specified name.
- Specified by:
getVariable
in interfaceConsoleEngine
- Parameters:
name
- the name of the variable to get- Returns:
- the value of the variable, or null if no variable with the specified name exists
-
hasVariable
Description copied from interface:ConsoleEngine
Tests if a variable with the specified name exists.This method determines whether a console variable with the specified name exists.
- Specified by:
hasVariable
in interfaceConsoleEngine
- Parameters:
name
- the name of the variable to check- Returns:
- true if a variable with the specified name exists, false otherwise
-
executeWidget
Description copied from interface:ConsoleEngine
Executes a widget function.This method executes the specified widget function, which can be used to perform custom actions in the console.
- Specified by:
executeWidget
in interfaceConsoleEngine
- Parameters:
function
- the widget function to execute- Returns:
- true if the function was executed successfully, false otherwise
-
consoleOption
Description copied from interface:ConsoleEngine
Reads a console option value with a default value if the option doesn't exist.This method retrieves the value of a console option, returning a default value if the option doesn't exist. Console options are used to configure the behavior of the console engine and its components.
- Specified by:
consoleOption
in interfaceConsoleEngine
- Type Parameters:
T
- the type of the option value- Parameters:
option
- the name of the option to readdefval
- the default value to return if the option doesn't exist- Returns:
- the value of the option, or the default value if the option doesn't exist
-
setConsoleOption
Description copied from interface:ConsoleEngine
Sets a console option value.This method sets the value of a console option. Console options are used to configure the behavior of the console engine and its components.
- Specified by:
setConsoleOption
in interfaceConsoleEngine
- Parameters:
name
- the name of the option to setvalue
- the value to assign to the option
-
postProcess
Description copied from interface:ConsoleEngine
Post-processes the result of executing a command.This method processes the result of executing a command, handling any special cases such as assigning the result to a console variable. If the result is to be assigned to a console variable, this method will return null.
- Specified by:
postProcess
in interfaceConsoleEngine
- Parameters:
line
- the command line that was executedresult
- the result of executing the commandoutput
- the redirected output of the command, if any- Returns:
- the processed result, or null if the result was assigned to a console variable
-
postProcess
Description copied from interface:ConsoleEngine
Post-processes the result of executing a command.This method processes the result of executing a command, handling any special cases. This is a convenience method that calls
ConsoleEngine.postProcess(String, Object, String)
with a null command line and output.- Specified by:
postProcess
in interfaceConsoleEngine
- Parameters:
result
- the result of executing the command- Returns:
- the processed result
-
invoke
public Object invoke(CommandRegistry.CommandSession session, String command, Object... args) throws Exception Description copied from interface:CommandRegistry
Execute a command.- Specified by:
invoke
in interfaceCommandRegistry
- Overrides:
invoke
in classAbstractCommandRegistry
- Parameters:
session
- the data of the current command sessioncommand
- the name of the commandargs
- arguments of the command- Returns:
- result of the command execution
- Throws:
Exception
- in case of error
-
trace
Description copied from interface:ConsoleEngine
Prints an object if tracing is enabled.This method prints the specified object to the console if tracing is enabled. Tracing can be used for debugging or logging purposes.
- Specified by:
trace
in interfaceConsoleEngine
- Parameters:
object
- the object to print
-
println
Description copied from interface:ConsoleEngine
Prints an object to the console.This method prints the specified object to the console, regardless of whether tracing is enabled.
- Specified by:
println
in interfaceConsoleEngine
- Parameters:
object
- the object to print
-
persist
Description copied from interface:ConsoleEngine
Persists an object to a file.This method serializes the specified object and writes it to the specified file. The object can later be read back using the
ConsoleEngine.slurp(Path)
method.- Specified by:
persist
in interfaceConsoleEngine
- Parameters:
file
- the file to write the object toobject
- the object to persist
-
slurp
Description copied from interface:ConsoleEngine
Reads an object from a file.This method reads and deserializes an object from the specified file. The object should have been written using the
ConsoleEngine.persist(Path, Object)
method.- Specified by:
slurp
in interfaceConsoleEngine
- Parameters:
file
- the file to read the object from- Returns:
- the deserialized object
- Throws:
IOException
- if an I/O error occurs while reading the file
-