Class CommandHighlighter

java.lang.Object
org.jline.shell.impl.CommandHighlighter
All Implemented Interfaces:
org.jline.reader.Highlighter

public class CommandHighlighter extends Object implements org.jline.reader.Highlighter
Command-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 Highlighter can be provided for composability. If provided, the delegate is called first, then command highlighting is applied on top.

Since:
4.0
  • Constructor Details

    • 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 lookup
      delegate - the delegate highlighter, or null
  • Method Details

    • highlight

      public org.jline.utils.AttributedString highlight(org.jline.reader.LineReader reader, String buffer)
      Specified by:
      highlight in interface org.jline.reader.Highlighter
    • setErrorPattern

      public void setErrorPattern(Pattern errorPattern)
      Specified by:
      setErrorPattern in interface org.jline.reader.Highlighter
    • setErrorIndex

      public void setErrorIndex(int errorIndex)
      Specified by:
      setErrorIndex in interface org.jline.reader.Highlighter