Skip to content

REPL Console Customization

mattirn edited this page Apr 12, 2020 · 9 revisions

REPL console is customized by using init script, config files and console variables. In order to work correctly some JLine commands and configurations require that application ConfigurationPath has been set in application startup.

Console

Init script

Application console enviroment is initialized using SystemRegistry method initialize(File initScript). Initialization script can be used to create:

  1. custom pipes
  2. command and pipe aliases
  3. custom widgets and key bindings
  4. prnt command default options and highlight rules

An initialization script example, see REPL demo init.jline.

Variables

PATH

A list of directories from where ConsoleEngine is searching scripts.

CONSOLE_OPTIONS

A map that contains console options:

  • maxValueNames maximum number of pipeline names that are persisted so that they can be reused in later sessions. Pipeline names are used by PipelineCompleter to offer tab completions.
  • no-splittedOutput as a default ConsoleEngine will split multiline command output to the String array. This will facilate the use of pipe operations.
  • trace ConsoleEngine trace level. Valid values: 0 - 2. Default value 0 (no trace).

prnt command

NANORC

The command prnt can use Nano SyntaxHighlighter to highlight object output. The nanorc configuration file is searched from

  1. ConfigurationPath: jnanorc file is first looked from the user-config path, if the file is not found then it is looked from the application-config path.
  2. NANORC console variable: full name of the nanorc file
  3. /etc/nanorc

PRNT_OPTIONS

A map that contains prnt command default options.

In a console the evaluated command result is converted to the Map<String,Object> or in a case of collection to the List<Map<String,Object>> before printing it to the console. The collection result is printed out as a table if the collection map key sets match sufficiently well with each other. If the collection map key sets differ too much the original result list (List<Object>) is used and the list elements are printed using the result of the ScriptEngine method toString(Object object).

In addition to the prnt command options REPL console print method has some 'hidden' options that can be used to customize object printing:

  • columnsIn, a list of map keys. These map values will be added to the table before all the other keys.
  • columnsOut, a list of map keys. These map values will not be inserted to the table.
  • highlightValue, a map<regex, function>. If command result map key matches with regex the highlight function is applied to the corresponding map value. The regex =* is processed after all the other regexes and the highlight function will be applied to all map values that have not been already highlighted.
  • mapSimilarity default value 0.8 i.e. if at least of 4 of the 5 results map keys match with reference key set the result will be printed out as a table.
  • objectToMap, a map<class, function>. Overrides the ScriptEngine toMap() method.
  • objectToString, a map<class, function>. Overrides the ScriptEngine toString() method.
Clone this wiki locally