Class CompositeHighlighter

java.lang.Object
org.daiitech.naftah.utils.repl.BaseHighlighter
org.daiitech.naftah.utils.repl.CompositeHighlighter
All Implemented Interfaces:
org.jline.reader.Highlighter

public class CompositeHighlighter extends BaseHighlighter
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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder class for creating a CompositeHighlighter instance using a fluent interface.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    builder(org.jline.reader.Highlighter originalHighlighter)
    Creates a new builder for a CompositeHighlighter.
    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.

    Methods inherited from class org.daiitech.naftah.utils.repl.BaseHighlighter

    merge, setErrorIndex, setErrorPattern

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.jline.reader.Highlighter

    refresh
  • Field Details

    • highlighters

      private final List<org.jline.reader.Highlighter> 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 specified
      highlighters - 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:
      highlight in interface org.jline.reader.Highlighter
      Overrides:
      highlight in class BaseHighlighter
      Parameters:
      reader - the LineReader instance
      buffer - the input line to highlight
      Returns:
      an AttributedString representing the highlighted line