-
Notifications
You must be signed in to change notification settings - Fork 219
Highlighting and parsing
The LineReader
can be given an implementation of the Highlighter and Parser interfaces which are responsible for highlighting and parsing of the command line.
DefaultHighlighter is JLine provided implementation of Highlighter
interface.
SystemHighlighter extends DefaultHighlighter
. SystemHighlighter
highlights command and language syntax using nano SyntaxHighlighter
.
SyntaxHighlighter is a JLine implementation of nanorc syntax highlighter that works with standard nanorc syntaxfiles.
JLine supported keywords: the syntax, color, and icolor are used to define syntax highlighting rules for different text patterns. Other nanorc keywords are quietly ignored.
JLine has extended the commands color and icolor first parameter syntax to support 255 colors, true color and additional ansi styles:
# nanorc syntax
color [bold,][italic,]fgcolor,bgcolor ...
# jline syntax
color style1[,style2]...[,stylen] ...
where style<i>
define either foreground color, background color or additional text styles.
Valid text styles names are blink, bold, conceal, crossed-out, faint, hidden, inverse, inverse-neg, italic and underline.
Color styles can be defined using:
- standard color names white, black, blue, green, red, cyan, yellow, magenta
- standard color name with prefix: bright, light or !
- 255 color name: ~<name>
- 255 color number
- 24-bit color: #<hexcode>
- default color: normal, default
- empty string: does not redefine color
The first color style in a list will define the foreground color and subsequent color styles the background color. More than two colors in a list can be treated as configuration error even though it is silently accepted.
SyntaxHighlighter
does not implement Highlighter
interface but it can be useful for implementing one or it can be just used to highlight command output and/or descriptions.
ConfigurationPath configPath = new ConfigurationPath(Paths.get("/pub/myApp"), // application-wide settings
Paths.get(System.getProperty("user.home"), ".myApp")); // user-specific settings
SyntaxHighlighter javaSyntax = SyntaxHighlighter.build(configPath.getConfig("jnanorc"), "Java");
javaSyntax.highlight("public AttributedString highlight(String string)").println(terminal);