Package org.daiitech.naftah.utils.repl
Class CompositeHighlighter
java.lang.Object
org.daiitech.naftah.utils.repl.BaseHighlighter
org.daiitech.naftah.utils.repl.CompositeHighlighter
- All Implemented Interfaces:
org.jline.reader.Highlighter
A composite implementation of
Highlighter that applies multiple highlighters in sequence
and merges their results. If no additional highlighters are provided, it delegates to the original highlighter.
This class uses the builder pattern to allow fluent composition of multiple highlighters.
Example usage:
Highlighter original = ...; Highlighter custom1 = ...; Highlighter custom2 = ...; CompositeHighlighter highlighter = CompositeHighlighter.builder(original) .add(custom1) .add(custom2) .build();
- Author:
- Chakib Daii
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class for creating a CompositeHighlighter instance using a fluent interface. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<org.jline.reader.Highlighter>List of highlighters to apply in sequence.Fields inherited from class org.daiitech.naftah.utils.repl.BaseHighlighter
originalHighlighter -
Constructor Summary
ConstructorsConstructorDescriptionCompositeHighlighter(org.jline.reader.Highlighter originalHighlighter, List<org.jline.reader.Highlighter> highlighters) Constructs a CompositeHighlighter with the original highlighter and a list of additional highlighters. -
Method Summary
Modifier and TypeMethodDescriptionstatic CompositeHighlighter.Builderbuilder(org.jline.reader.Highlighter originalHighlighter) Creates a new builder for a CompositeHighlighter.org.jline.utils.AttributedStringApplies each highlighter in the list to the given input line and merges the results.Methods inherited from class org.daiitech.naftah.utils.repl.BaseHighlighter
merge, setErrorIndex, setErrorPatternMethods 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
-
highlighters
List of highlighters to apply in sequence.
-
-
Constructor Details
-
CompositeHighlighter
public CompositeHighlighter(org.jline.reader.Highlighter originalHighlighter, List<org.jline.reader.Highlighter> highlighters) Constructs a CompositeHighlighter with the original highlighter and a list of additional highlighters.- Parameters:
originalHighlighter- the original highlighter to delegate to if no others are specifiedhighlighters- a list of highlighters to apply in sequence
-
-
Method Details
-
builder
public static CompositeHighlighter.Builder builder(org.jline.reader.Highlighter originalHighlighter) Creates a new builder for a CompositeHighlighter.- Parameters:
originalHighlighter- the original highlighter- Returns:
- a new Builder instance
-
highlight
public org.jline.utils.AttributedString highlight(org.jline.reader.LineReader reader, String buffer) Applies each highlighter in the list to the given input line and merges the results.- Specified by:
highlightin interfaceorg.jline.reader.Highlighter- Overrides:
highlightin classBaseHighlighter- Parameters:
reader- the LineReader instancebuffer- the input line to highlight- Returns:
- an AttributedString representing the highlighted line
-