-
Notifications
You must be signed in to change notification settings - Fork 218
REPL Console Customization
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.
Application console enviroment is initialized using SystemRegistry method initialize(File initScript)
. Initialization script can be used to create:
- custom pipes
- command and pipe aliases
- custom widgets and key bindings
-
prnt
command default options and highlight rules
An initialization script example, see REPL demo init.jline.
A list of directories from where ConsoleEngine
is searching scripts.
A map that contains console options:
- HELP_COLORS string variable that defines command help highlighting.
- LS_COLORS string variable that defines file names highlighting.
-
PRNT_COLORS string variable that defines
prnt
command output highlighting. -
docs a
map<regex, url>
. Commanddoc
configuration. If command parameter full class name matchesregex
the javadoc url will be constructed and open in the browser. -
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 facilitate the use of pipe operations. -
trace
ConsoleEngine
trace level. Valid values: 0 - 2. Default value 0 (no trace).
The command prnt
can use Nano SyntaxHighlighter to highlight object output. The nanorc configuration file is searched from
-
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. - NANORC console variable: full name of the nanorc file
- /etc/nanorc
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 theScriptEngine
toMap()
method. -
objectToString, a
map<class, function>
. Overrides theScriptEngine
toString()
method.
COLORS (HELP_COLORS, LS_COLORS and PRNT_COLORS) can be defined either in CONSOLE_OPTIONS map or as shell environment variables. COLORS environment variable will be used only in a case when the variable is not defined in CONSOLE_OPTIONS map. JLine system default will be used when COLORS variable is not defined.
COLORS environment variables are a colon separated list of key=colour pairs, where color is semicolon separated list of color codes that in its full extend is defined as style;fgcolor;bgcolor
default = "ti=1;34:co=1:ar=3:op=33"
Key | Comment |
---|---|
ar | argument |
co | command |
op | option |
ti | title |
There are two types of keys: file types and file extensions.
default = "di=1;91:ex=1;92:ln=1;96:fi="
Key | Comment |
---|---|
di | directory |
ex | executable |
ln | symbolic link |
fi | normal file |
*.extension | file extension (ex. *.jpg) |
default = "th=1;34:rn=1;34:mk=1;34:em=31:vs=32"
Key | Comment |
---|---|
th | table header |
rn | row numbers |
mk | map keys |
em | error message |
vs | script line output when executing console script using -v option |
In addition to the PRNT_COLORS variable prnt
command has two other highlight options used for object printing: highlightValue (see above) and valueStyle. Option valueStyle use Nano SyntaxHighlighter and it will be applied only to the strings that do not have spaces or are enclosed by quotes or any type of parenthesis.
In highlighting the first will be performed highlightValue option and after only if the value is not highlighted will be applied valueStyle option.