Class CommandHighlighter

  • All Implemented Interfaces:
    org.jline.reader.Highlighter

    public class CommandHighlighter
    extends java.lang.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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.jline.utils.AttributedString highlight​(org.jline.reader.LineReader reader, java.lang.String buffer)  
      void setErrorIndex​(int errorIndex)  
      void setErrorPattern​(java.util.regex.Pattern errorPattern)  
      • 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
    • Constructor Detail

      • 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 Detail

      • highlight

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

        public void setErrorPattern​(java.util.regex.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