Class SystemHighlighter
- java.lang.Object
-
- org.jline.reader.impl.DefaultHighlighter
-
- org.jline.console.impl.SystemHighlighter
-
- All Implemented Interfaces:
Highlighter
public class SystemHighlighter extends DefaultHighlighter
Highlighter implementation that provides syntax highlighting for commands and languages.SystemHighlighter extends DefaultHighlighter to provide syntax highlighting for:
- Command syntax (command names, options, arguments)
- Programming language syntax (for various languages)
- File content based on file extensions
The highlighter uses nanorc syntax definitions for highlighting, making it compatible with existing nanorc configuration files. It can be customized with different styles and supports dynamic refreshing of highlighting rules.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SystemHighlighter.FileHighlightCommand
-
Field Summary
Fields Modifier and Type Field Description protected SyntaxHighlighter
argsHighlighter
protected SyntaxHighlighter
commandHighlighter
protected int
commandIndex
protected java.util.Map<java.lang.String,SystemHighlighter.FileHighlightCommand>
fileHighlight
protected SyntaxHighlighter
langHighlighter
protected java.util.Map<java.lang.String,SyntaxHighlighter>
specificHighlighter
protected SystemRegistry
systemRegistry
-
Fields inherited from class org.jline.reader.impl.DefaultHighlighter
errorIndex, errorPattern
-
-
Constructor Summary
Constructors Constructor Description SystemHighlighter(SyntaxHighlighter commandHighlighter, SyntaxHighlighter argsHighlighter, SyntaxHighlighter langHighlighter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExternalHighlighterRefresh(java.util.function.Supplier<java.lang.Boolean> refresh)
void
addFileHighlight(java.lang.String... commands)
void
addFileHighlight(java.lang.String command, java.lang.String subcommand, java.util.Collection<java.lang.String> fileOptions)
protected AttributedString
doCommandHighlight(java.lang.String buffer)
protected AttributedString
doFileArgsHighlight(LineReader reader, java.lang.String buffer, java.util.List<java.lang.String> words, SystemHighlighter.FileHighlightCommand fhc)
protected AttributedString
doFileOptsHighlight(LineReader reader, java.lang.String buffer, java.util.List<java.lang.String> words, SystemHighlighter.FileHighlightCommand fhc)
AttributedString
highlight(LineReader reader, java.lang.String buffer)
Highlights the provided text buffer with appropriate styling.void
refresh(LineReader lineReader)
Refreshes the highlighter's configuration.void
setSpecificHighlighter(java.lang.String command, SyntaxHighlighter highlighter)
protected AttributedString
systemHighlight(LineReader reader, java.lang.String buffer)
-
Methods inherited from class org.jline.reader.impl.DefaultHighlighter
commandStyle, setErrorIndex, setErrorPattern
-
-
-
-
Field Detail
-
commandHighlighter
protected final SyntaxHighlighter commandHighlighter
-
argsHighlighter
protected final SyntaxHighlighter argsHighlighter
-
langHighlighter
protected final SyntaxHighlighter langHighlighter
-
systemRegistry
protected final SystemRegistry systemRegistry
-
fileHighlight
protected final java.util.Map<java.lang.String,SystemHighlighter.FileHighlightCommand> fileHighlight
-
specificHighlighter
protected final java.util.Map<java.lang.String,SyntaxHighlighter> specificHighlighter
-
commandIndex
protected int commandIndex
-
-
Constructor Detail
-
SystemHighlighter
public SystemHighlighter(SyntaxHighlighter commandHighlighter, SyntaxHighlighter argsHighlighter, SyntaxHighlighter langHighlighter)
-
-
Method Detail
-
setSpecificHighlighter
public void setSpecificHighlighter(java.lang.String command, SyntaxHighlighter highlighter)
-
refresh
public void refresh(LineReader lineReader)
Description copied from interface:Highlighter
Refreshes the highlighter's configuration.This method is called when the highlighter should reload or refresh its configuration, such as when color schemes change or when syntax rules are updated. The default implementation does nothing.
- Parameters:
lineReader
- The LineReader instance associated with this highlighter
-
addExternalHighlighterRefresh
public void addExternalHighlighterRefresh(java.util.function.Supplier<java.lang.Boolean> refresh)
-
highlight
public AttributedString highlight(LineReader reader, java.lang.String buffer)
Description copied from interface:Highlighter
Highlights the provided text buffer with appropriate styling.This method is called by the LineReader to apply syntax highlighting to the current input line. It should analyze the buffer content and return an AttributedString with appropriate styling applied based on the content's syntax, structure, or other relevant characteristics.
- Specified by:
highlight
in interfaceHighlighter
- Overrides:
highlight
in classDefaultHighlighter
- Parameters:
reader
- The LineReader instance requesting highlightingbuffer
- The text buffer to be highlighted- Returns:
- An AttributedString containing the highlighted buffer with styling applied
-
addFileHighlight
public void addFileHighlight(java.lang.String... commands)
-
addFileHighlight
public void addFileHighlight(java.lang.String command, java.lang.String subcommand, java.util.Collection<java.lang.String> fileOptions)
-
systemHighlight
protected AttributedString systemHighlight(LineReader reader, java.lang.String buffer)
-
doFileOptsHighlight
protected AttributedString doFileOptsHighlight(LineReader reader, java.lang.String buffer, java.util.List<java.lang.String> words, SystemHighlighter.FileHighlightCommand fhc)
-
doFileArgsHighlight
protected AttributedString doFileArgsHighlight(LineReader reader, java.lang.String buffer, java.util.List<java.lang.String> words, SystemHighlighter.FileHighlightCommand fhc)
-
doCommandHighlight
protected AttributedString doCommandHighlight(java.lang.String buffer)
-
-