Class StyleResolver

  • Direct Known Subclasses:
    StyleResolver

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

      Constructors 
      Constructor Description
      StyleResolver​(java.util.function.Function<java.lang.String,​java.lang.String> source)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AttributedStyle resolve​(java.lang.String spec)
      Resolve the given style specification.
      AttributedStyle resolve​(java.lang.String spec, java.lang.String defaultSpec)
      Resolve the given style specification.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StyleResolver

        public StyleResolver​(java.util.function.Function<java.lang.String,​java.lang.String> source)
    • Method Detail

      • resolve

        public AttributedStyle resolve​(java.lang.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​(java.lang.String spec,
                                       java.lang.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