Package org.daiitech.naftah.utils.repl
Class BaseHighlighter
java.lang.Object
org.daiitech.naftah.utils.repl.BaseHighlighter
- All Implemented Interfaces:
org.jline.reader.Highlighter
- Direct Known Subclasses:
CompositeHighlighter,NaftahHighlighter,SyntaxHighlighter
An abstract base class for implementing custom
Highlighter logic
while preserving behavior from an original highlighter.
It delegates highlighting operations to the original highlighter by default,
and provides a utility method merge(AttributedString, AttributedString)
for combining two attributed strings with merged styles.
- Author:
- Chakib Daii
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.jline.reader.HighlighterThe original highlighter to delegate to. -
Constructor Summary
ConstructorsConstructorDescriptionBaseHighlighter(org.jline.reader.Highlighter originalHighlighter) Constructs a new BaseHighlighter with the given original highlighter. -
Method Summary
Modifier and TypeMethodDescriptionorg.jline.utils.AttributedStringHighlights the given input buffer using the original highlighter.static org.jline.utils.AttributedStringmerge(org.jline.utils.AttributedString base, org.jline.utils.AttributedString overlay) Merges twoAttributedStringobjects, combining their character styles.voidsetErrorIndex(int errorIndex) Sets the index in the buffer that caused a parsing error.voidsetErrorPattern(Pattern errorPattern) Sets the pattern that identifies errors in the input.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jline.reader.Highlighter
refresh
-
Field Details
-
originalHighlighter
protected final org.jline.reader.Highlighter originalHighlighterThe original highlighter to delegate to.
-
-
Constructor Details
-
BaseHighlighter
public BaseHighlighter(org.jline.reader.Highlighter originalHighlighter) Constructs a new BaseHighlighter with the given original highlighter.- Parameters:
originalHighlighter- the highlighter to delegate to
-
-
Method Details
-
merge
public static org.jline.utils.AttributedString merge(org.jline.utils.AttributedString base, org.jline.utils.AttributedString overlay) Merges twoAttributedStringobjects, combining their character styles. If one string is longer than the other, the remaining portion is appended as-is.- Parameters:
base- the base attributed string (can benull)overlay- the string to overlay on top of the base- Returns:
- a new merged
AttributedString
-
highlight
public org.jline.utils.AttributedString highlight(org.jline.reader.LineReader reader, String buffer) Highlights the given input buffer using the original highlighter.- Specified by:
highlightin interfaceorg.jline.reader.Highlighter- Parameters:
reader- the line readerbuffer- the input string to highlight- Returns:
- an
AttributedStringwith applied highlighting
-
setErrorPattern
Sets the pattern that identifies errors in the input.- Specified by:
setErrorPatternin interfaceorg.jline.reader.Highlighter- Parameters:
errorPattern- the regular expression pattern
-
setErrorIndex
public void setErrorIndex(int errorIndex) Sets the index in the buffer that caused a parsing error.- Specified by:
setErrorIndexin interfaceorg.jline.reader.Highlighter- Parameters:
errorIndex- the index of the error
-