Class BaseHighlighter

java.lang.Object
org.daiitech.naftah.utils.repl.BaseHighlighter
All Implemented Interfaces:
org.jline.reader.Highlighter
Direct Known Subclasses:
CompositeHighlighter, NaftahHighlighter, SyntaxHighlighter

public abstract class BaseHighlighter extends Object implements org.jline.reader.Highlighter
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

    Fields
    Modifier and Type
    Field
    Description
    protected final org.jline.reader.Highlighter
    The original highlighter to delegate to.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BaseHighlighter(org.jline.reader.Highlighter originalHighlighter)
    Constructs a new BaseHighlighter with the given original highlighter.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.jline.utils.AttributedString
    highlight(org.jline.reader.LineReader reader, String buffer)
    Highlights the given input buffer using the original highlighter.
    static org.jline.utils.AttributedString
    merge(org.jline.utils.AttributedString base, org.jline.utils.AttributedString overlay)
    Merges two AttributedString objects, combining their character styles.
    void
    setErrorIndex(int errorIndex)
    Sets the index in the buffer that caused a parsing error.
    void
    setErrorPattern(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, wait

    Methods inherited from interface org.jline.reader.Highlighter

    refresh
  • Field Details

    • originalHighlighter

      protected final org.jline.reader.Highlighter originalHighlighter
      The 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 two AttributedString objects, 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 be null)
      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:
      highlight in interface org.jline.reader.Highlighter
      Parameters:
      reader - the line reader
      buffer - the input string to highlight
      Returns:
      an AttributedString with applied highlighting
    • setErrorPattern

      public void setErrorPattern(Pattern errorPattern)
      Sets the pattern that identifies errors in the input.
      Specified by:
      setErrorPattern in interface org.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:
      setErrorIndex in interface org.jline.reader.Highlighter
      Parameters:
      errorIndex - the index of the error