Class StyleResolver

java.lang.Object
org.jline.utils.StyleResolver
Direct Known Subclasses:
StyleResolver

public class StyleResolver extends Object
Resolves named styles and style expressions into AttributedStyle objects.

The StyleResolver class provides functionality for resolving style specifications into AttributedStyle objects. It supports a rich expression language for defining styles, including named colors, RGB values, and various text attributes.

Style specifications can include:

  • Named colors (e.g., "red", "blue", "bright-green")
  • RGB color values (e.g., "#ff0000", "rgb:ff/00/00")
  • Text attributes (e.g., "bold", "underline", "italic")
  • Compound styles with foreground and background (e.g., "red,bold,bg:blue")
  • References to styles defined elsewhere (e.g., "${named.style}")

This class is used throughout JLine for resolving style specifications in configuration files, command-line options, and programmatic style definitions. It provides a consistent way to define and apply styles across different components.

The resolver can be configured with a source function that looks up named styles, allowing for hierarchical style definitions and style inheritance.

Since:
3.6
  • Field Details

  • Constructor Details

  • Method Details

    • colorRgb

      private static Integer colorRgb(String name)
      Returns the RGB color for the given name.

      Bright color can be specified with: !<color> or bright-<color>.

      Full xterm256 color can be specified with: ~<color>. RGB colors can be specified with: x<rgb> or #<rgb> where rgb is a 24 bits hexadecimal color.

      Parameters:
      name - the name of the color
      Returns:
      color code, or null if unable to determine.
    • color

      private static Integer color(String name)
      Returns the color identifier for the given name.

      Bright color can be specified with: !<color> or bright-<color>.

      Full xterm256 color can be specified with: ~<color>.

      Parameters:
      name - the name of the color
      Returns:
      color code, or null if unable to determine.
    • resolve

      public AttributedStyle resolve(String spec)
      Resolve the given style specification.

      If for some reason the specification is invalid, then AttributedStyle.DEFAULT will be used.

      Parameters:
      spec - the specification
      Returns:
      the style
    • resolve

      public AttributedStyle resolve(String spec, String defaultSpec)
      Resolve the given style specification.

      If this resolves to AttributedStyle.DEFAULT then given default specification is used if non-null.

      Parameters:
      spec - the specification
      defaultSpec - the default specifiaction
      Returns:
      the style
    • apply

      private AttributedStyle apply(AttributedStyle style, String spec)
      Apply style specification.
      Parameters:
      style - the style to apply to
      spec - the specification
      Returns:
      the new style
    • applyAnsi

      private AttributedStyle applyAnsi(AttributedStyle style, String spec)
    • applyReference

      private AttributedStyle applyReference(AttributedStyle style, String spec)
      Apply source-referenced named style.
      Parameters:
      style - the style to apply to
      spec - the specification
      Returns:
      the new style
    • applyNamed

      private AttributedStyle applyNamed(AttributedStyle style, String name)
      Apply default named styles.
      Parameters:
      style - the style to apply to
      name - the named style
      Returns:
      the new style
    • applyColor

      private AttributedStyle applyColor(AttributedStyle style, String spec)
      Apply color styles specification.
      Parameters:
      style - The style to apply to
      spec - Color specification: <color-mode>:<color-name>
      Returns:
      The new style