Interface Highlighter
- All Known Implementing Classes:
DefaultHighlighter
Highlighters are responsible for applying visual styling to the command line text as the user types. This can include syntax highlighting for programming languages, highlighting matching brackets, marking errors, or any other visual cues that help users understand the structure and validity of their input.
Implementations convert plain text into AttributedString
instances that contain
both the text and its visual styling information. The LineReader will then render
these styled strings to the terminal with the appropriate colors and text attributes.
The default implementation is DefaultHighlighter
.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionorg.jline.utils.AttributedString
highlight
(LineReader reader, String buffer) Highlights the provided text buffer with appropriate styling.default void
refresh
(LineReader reader) Refreshes the highlighter's configuration.default void
setErrorIndex
(int errorIndex) Sets a specific character position in the buffer to be highlighted as an error.default void
setErrorPattern
(Pattern errorPattern) Sets a regular expression pattern that identifies errors to be highlighted.
-
Method Details
-
highlight
Highlights the provided text buffer with appropriate styling.This method is called by the LineReader to apply syntax highlighting to the current input line. It should analyze the buffer content and return an AttributedString with appropriate styling applied based on the content's syntax, structure, or other relevant characteristics.
- Parameters:
reader
- The LineReader instance requesting highlightingbuffer
- The text buffer to be highlighted- Returns:
- An AttributedString containing the highlighted buffer with styling applied
-
refresh
Refreshes the highlighter's configuration.This method is called when the highlighter should reload or refresh its configuration, such as when color schemes change or when syntax rules are updated. The default implementation does nothing.
- Parameters:
reader
- The LineReader instance associated with this highlighter
-
setErrorPattern
Sets a regular expression pattern that identifies errors to be highlighted.Text matching this pattern will typically be highlighted with error styling (often red or with a distinctive background color) to indicate problematic input.
- Parameters:
errorPattern
- A regular expression pattern that matches text to be highlighted as errors
-
setErrorIndex
default void setErrorIndex(int errorIndex) Sets a specific character position in the buffer to be highlighted as an error.This is typically used to indicate the exact position of a syntax error or other issue in the input line. The highlighter will apply error styling at this position.
- Parameters:
errorIndex
- The character index in the buffer to be highlighted as an error
-