Package org.jline.builtins
Class SyntaxHighlighter
java.lang.Object
org.jline.builtins.SyntaxHighlighter
Java implementation of a syntax highlighter based on nanorc format.
This class provides syntax highlighting capabilities for JLine applications, using configuration files in a format similar to GNU nano's nanorc files. It supports:
- Regular expression based highlighting rules
- Theme-based styling
- File type detection
- Inclusion of other configuration files
The highlighter can be used to add syntax coloring to various text displays in terminal applications, such as file viewers, editors, and REPLs.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class(package private) static class(package private) static classprivate static class(package private) static classprivate static classRepresents the static and glob parts of a path pattern.protected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprivate Pathprotected static final Stringstatic final Stringprivate final Pathprivate final Stringprivate SyntaxHighlighter.Parserstatic final Stringprivate final Map<String, List<SyntaxHighlighter.HighlightRule>> private intprivate booleanprivate final Stringprivate static final Stringstatic final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateprivateSyntaxHighlighter(String nanorcUrl) privateSyntaxHighlighter(Path nanorc, String syntaxName) privateSyntaxHighlighter(Path nanorc, String syntaxName, String nanorcUrl) -
Method Summary
Modifier and TypeMethodDescriptionprivate AttributedStringBuilder_highlight(AttributedString line, List<SyntaxHighlighter.HighlightRule> rules) private AttributedStringBuilder_highlight(AttributedString line, List<SyntaxHighlighter.HighlightRule> rules, CharSequence startWith, CharSequence continueAs) protected static voidprivate voidaddRules(Map<String, List<SyntaxHighlighter.HighlightRule>> rules) static SyntaxHighlighterBuild SyntaxHighlighterstatic SyntaxHighlighterBuild SyntaxHighlighterprotected static SyntaxHighlighterprotected static SyntaxHighlighterprivate static SyntaxHighlighter.PathPartsextractPathParts(String pattern) Extracts the static (non-wildcard) path prefix and the glob pattern from a path.highlight(AttributedString attributedString) protected static voidnanorcInclude(Path nanorc, String parameter, List<Path> syntaxFiles) protected static voidnanorcTheme(Path nanorc, String parameter, List<Path> syntaxFiles) voidrefresh()reset()voidsetCurrentTheme(Path currentTheme) voidsetParser(SyntaxHighlighter.Parser parser) private AttributedStringsplitAndHighlight(AttributedString attributedString)
-
Field Details
-
REGEX_TOKEN_NAME
- See Also:
-
TYPE_NANORCTHEME
- See Also:
-
DEFAULT_NANORC_FILE
- See Also:
-
DEFAULT_LESSRC_FILE
- See Also:
-
COMMAND_INCLUDE
- See Also:
-
COMMAND_THEME
- See Also:
-
TOKEN_NANORC
- See Also:
-
nanorc
-
syntaxName
-
nanorcUrl
-
rules
-
currentTheme
-
startEndHighlight
private boolean startEndHighlight -
ruleStartId
private int ruleStartId -
parser
-
-
Constructor Details
-
SyntaxHighlighter
private SyntaxHighlighter() -
SyntaxHighlighter
-
SyntaxHighlighter
-
SyntaxHighlighter
-
-
Method Details
-
build
-
build
protected static SyntaxHighlighter build(List<Path> syntaxFiles, String file, String syntaxName, boolean ignoreErrors) -
build
Build SyntaxHighlighter- Parameters:
nanorc- Path of nano config file jnanorcsyntaxName- syntax name e.g 'Java'- Returns:
- SyntaxHighlighter
-
nanorcInclude
protected static void nanorcInclude(Path nanorc, String parameter, List<Path> syntaxFiles) throws IOException - Throws:
IOException
-
nanorcTheme
protected static void nanorcTheme(Path nanorc, String parameter, List<Path> syntaxFiles) throws IOException - Throws:
IOException
-
addFiles
protected static void addFiles(Path nanorc, String parameter, Consumer<Stream<Path>> consumer) throws IOException - Throws:
IOException
-
extractPathParts
Extracts the static (non-wildcard) path prefix and the glob pattern from a path. For example:foo/bar/*.nanorcreturnsPathParts("foo/bar", "*.nanorc")foo/bar/**/*.nanorcreturnsPathParts("foo/bar", "**/*.nanorc")*.nanorcreturnsPathParts("", "*.nanorc")/usr/share/nano/*.nanorcreturnsPathParts("/usr/share/nano", "*.nanorc")
-
build
Build SyntaxHighlighterThis method builds a SyntaxHighlighter from a URL or classpath resource. The URL can be a file URL, an HTTP URL, or a classpath resource URL.
For classpath resources, use the "classpath:" prefix followed by the resource path. For example: "classpath:/nano/jnanorc"
- Parameters:
nanorcUrl- URL or classpath resource path of nanorc file- Returns:
- SyntaxHighlighter
-
addRules
-
setCurrentTheme
-
getCurrentTheme
-
setParser
-
reset
-
refresh
public void refresh() -
highlight
-
highlight
-
highlight
-
splitAndHighlight
-
_highlight
private AttributedStringBuilder _highlight(AttributedString line, List<SyntaxHighlighter.HighlightRule> rules) -
_highlight
private AttributedStringBuilder _highlight(AttributedString line, List<SyntaxHighlighter.HighlightRule> rules, CharSequence startWith, CharSequence continueAs)
-