Class SyntaxHighlighter

java.lang.Object
org.jline.builtins.SyntaxHighlighter

public class SyntaxHighlighter extends Object
Java implementation of a syntax highlighter based on nanorc format.

This class provides syntax highlighting capabilities for JLine applications, using configuration files in a format similar to GNU nano's nanorc files. It supports:

  • Regular expression based highlighting rules
  • Theme-based styling
  • File type detection
  • Inclusion of other configuration files

The highlighter can be used to add syntax coloring to various text displays in terminal applications, such as file viewers, editors, and REPLs.

Author:
Matti Rinta-Nikkola
  • Field Details

  • Method Details

    • build

      protected static SyntaxHighlighter build(List<Path> syntaxFiles, String file, String syntaxName)
    • build

      protected static SyntaxHighlighter build(List<Path> syntaxFiles, String file, String syntaxName, boolean ignoreErrors)
    • build

      public static SyntaxHighlighter build(Path nanorc, String syntaxName)
      Build SyntaxHighlighter
      Parameters:
      nanorc - Path of nano config file jnanorc
      syntaxName - syntax name e.g 'Java'
      Returns:
      SyntaxHighlighter
    • nanorcInclude

      protected static void nanorcInclude(Path nanorc, String parameter, List<Path> syntaxFiles) throws IOException
      Throws:
      IOException
    • nanorcTheme

      protected static void nanorcTheme(Path nanorc, String parameter, List<Path> syntaxFiles) throws IOException
      Throws:
      IOException
    • addFiles

      protected static void addFiles(Path nanorc, String parameter, Consumer<Stream<Path>> consumer) throws IOException
      Throws:
      IOException
    • build

      public static SyntaxHighlighter build(String nanorcUrl)
      Build SyntaxHighlighter

      This method builds a SyntaxHighlighter from a URL or classpath resource. The URL can be a file URL, an HTTP URL, or a classpath resource URL.

      For classpath resources, use the "classpath:" prefix followed by the resource path. For example: "classpath:/nano/jnanorc"

      Parameters:
      nanorcUrl - URL or classpath resource path of nanorc file
      Returns:
      SyntaxHighlighter
    • setCurrentTheme

      public void setCurrentTheme(Path currentTheme)
    • getCurrentTheme

      public Path getCurrentTheme()
    • setParser

      public void setParser(org.jline.builtins.SyntaxHighlighter.Parser parser)
    • reset

      public SyntaxHighlighter reset()
    • refresh

      public void refresh()
    • highlight

      public org.jline.utils.AttributedString highlight(String string)
    • highlight

      public org.jline.utils.AttributedString highlight(org.jline.utils.AttributedStringBuilder asb)
    • highlight

      public org.jline.utils.AttributedString highlight(org.jline.utils.AttributedString attributedString)