Class StyleResolver

java.lang.Object
org.jline.utils.StyleResolver
org.jline.style.StyleResolver

public class StyleResolver extends StyleResolver
Resolves named (or source-referenced) AttributedStyle for a specific style group.

This class extends StyleResolver to add support for style groups and style sources. It allows resolving style specifications into AttributedStyle objects, with the ability to look up named styles from a StyleSource.

Style specifications can be in the following formats:

  • Direct style specifications: "bold,fg:red,bg:blue,underline"
  • Named style references: ".error" (looks up "error" in the current style group)
  • Named style references with defaults: ".error:-bold,fg:red" (uses default if named style is not found)

Example usage:

 StyleSource source = new MemoryStyleSource();
 source.set("mygroup", "error", "bold,fg:red");

 StyleResolver resolver = new StyleResolver(source, "mygroup");
 AttributedStyle style1 = resolver.resolve("bold,fg:blue");       // Direct style
 AttributedStyle style2 = resolver.resolve(".error");              // Named style
 AttributedStyle style3 = resolver.resolve(".missing:-underline"); // Default style
 
Since:
3.4
See Also:
  • Constructor Details

    • StyleResolver

      public StyleResolver(StyleSource source, String group)
      Constructs a new StyleResolver for the specified source and group.

      This constructor creates a StyleResolver that will look up named styles in the specified source and group. The resolver will use the source to resolve style names when a style specification starts with a dot (e.g., ".error").

      Parameters:
      source - the style source to use for named style lookups (must not be null)
      group - the style group to use for named style lookups (must not be null)
      Throws:
      NullPointerException - if source or group is null
  • Method Details

    • getSource

      public StyleSource getSource()
      Returns the style source used by this resolver.

      The style source is used to look up named styles when resolving style specifications that start with a dot (e.g., ".error").

      Returns:
      the style source (never null)
    • getGroup

      public String getGroup()
      Returns the style group used by this resolver.

      The style group is used to look up named styles in the style source when resolving style specifications that start with a dot (e.g., ".error").

      Returns:
      the style group name (never null)