- java.lang.Object
-
- org.jline.shell.impl.CommandHighlighter
-
- All Implemented Interfaces:
org.jline.reader.Highlighter
public class CommandHighlighter extends java.lang.Object implements org.jline.reader.HighlighterCommand-aware syntax highlighter for the shell.Highlights the first word of the command line based on whether it is a known command in the dispatcher:
- Known commands are highlighted in bold
- Unknown commands are highlighted in red
- Pipeline operators (
|,&&,||,;, etc.) are highlighted in cyan
An optional delegate
Highlightercan be provided for composability. If provided, the delegate is called first, then command highlighting is applied on top.- Since:
- 4.0
-
-
Constructor Summary
Constructors Constructor Description CommandHighlighter(CommandDispatcher dispatcher)Creates a command highlighter with no delegate.CommandHighlighter(CommandDispatcher dispatcher, org.jline.reader.Highlighter delegate)Creates a command highlighter with an optional delegate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.jline.utils.AttributedStringhighlight(org.jline.reader.LineReader reader, java.lang.String buffer)voidsetErrorIndex(int errorIndex)voidsetErrorPattern(java.util.regex.Pattern errorPattern)
-
-
-
Constructor Detail
-
CommandHighlighter
public CommandHighlighter(CommandDispatcher dispatcher)
Creates a command highlighter with no delegate.- Parameters:
dispatcher- the command dispatcher for command lookup
-
CommandHighlighter
public CommandHighlighter(CommandDispatcher dispatcher, org.jline.reader.Highlighter delegate)
Creates a command highlighter with an optional delegate.When a delegate is provided, it is used to highlight the buffer first, and then command-specific highlighting is applied on top.
- Parameters:
dispatcher- the command dispatcher for command lookupdelegate- the delegate highlighter, or null
-
-
Method Detail
-
highlight
public org.jline.utils.AttributedString highlight(org.jline.reader.LineReader reader, java.lang.String buffer)- Specified by:
highlightin interfaceorg.jline.reader.Highlighter
-
setErrorPattern
public void setErrorPattern(java.util.regex.Pattern errorPattern)
- Specified by:
setErrorPatternin interfaceorg.jline.reader.Highlighter
-
setErrorIndex
public void setErrorIndex(int errorIndex)
- Specified by:
setErrorIndexin interfaceorg.jline.reader.Highlighter
-
-