Top Description Inners Fields Constructors Methods
io.github.kusoroadeolu.clique.configuration

public final Class StyleContext

extends Object
Class Inheritance
Annotations
@Stable
since:4.0.2
Imports
io.github.kusoroadeolu.clique.internal.CompositeColor, io.github.kusoroadeolu.clique.internal.documentation.Stable, io.github.kusoroadeolu.clique.internal.exception.NoSuchThemeException, io.github.kusoroadeolu.clique.internal.loader.ThemeLoader, io.github.kusoroadeolu.clique.spi.AnsiCode, java.util.Collection, .HashMap, .Map, .Objects

A scoped registry of custom markup styles, mapping markup names to AnsiCode instances.

A StyleContext attached to a io.github.kusoroadeolu.clique.configuration.ParserConfiguration takes precedence over global custom styles and predefined styles during tag resolution. See ParserConfiguration for the full resolution order.

Instances are obtained via builder(), from(Map), or from(StyleContext). NONE is a sentinel representing an empty context with no registered styles.

This class is immutable and thread-safe. StyleContextBuilder is not thread-safe; external synchronization is required if a builder instance is shared across threads.

Example:

StyleContext ctx = StyleContext.builder()
    .add("highlight", ColorCode.YELLOW)
    .add("muted", StyleCode.DIM)
    .build();

ParserConfiguration config = ParserConfiguration.builder()
    .styleContext(ctx)
    .build();
Since
4.0.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final Map<String, AnsiCode>
public static final StyleContext
NONE

A sentinel StyleContext with no registered styles.

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public static StyleContext.StyleContextBuilder

Returns:

a new StyleContextBuilder
builder
()

Returns a new builder for constructing a StyleContext.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static StyleContext

Returns:

a new StyleContext containing the given styles
from
(Map<String, AnsiCode>
a map of markup names to ANSI codes; must not be null
codes
)

Creates a StyleContext from an existing map of style names to AnsiCode instances.

public static StyleContext

Returns:

a new StyleContext containing the same styles
from
(StyleContext
the context to copy; must not be null
context
)

Creates a shallow copy of an existing StyleContext.

public static StyleContext

Returns:

a new StyleContext containing the same styles
fromTheme
(String
the name of the theme to be registered; must not be null
theme
)

Creates a StyleContext from a CliqueTheme.

public AnsiCode

Returns:

the associated AnsiCode, or null if not present
get
(String
the markup name to look up
s
)

Returns the AnsiCode registered under the given markup name, or null if no style is registered for that name.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

localStylesback to summary
private final Map<String, AnsiCode> localStyles
NONEback to summary
public static final StyleContext NONE

A sentinel StyleContext with no registered styles.

Passing this to ParserConfiguration.ParserConfigurationBuilder#styleContext(StyleContext) is a no-op; no local styles will be added to the parser's resolution chain.

Constructor Detail

StyleContextback to summary
pack-priv StyleContext(StyleContext.StyleContextBuilder builder)
StyleContextback to summary
pack-priv StyleContext()

Method Detail

builderback to summary
public static StyleContext.StyleContextBuilder builder()

Returns a new builder for constructing a StyleContext.

Returns:StyleContext.StyleContextBuilder

a new StyleContextBuilder

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
fromback to summary
public static StyleContext from(Map<String, AnsiCode> codes)

Creates a StyleContext from an existing map of style names to AnsiCode instances.

The provided map is copied; subsequent modifications to it do not affect the returned context.

Parameters
codes:Map<String, AnsiCode>

a map of markup names to ANSI codes; must not be null

Returns:StyleContext

a new StyleContext containing the given styles

Exceptions
NullPointerException:
if codes is null
fromback to summary
public static StyleContext from(StyleContext context)

Creates a shallow copy of an existing StyleContext.

The registered styles are copied; the returned context is independent of the source.

Parameters
context:StyleContext

the context to copy; must not be null

Returns:StyleContext

a new StyleContext containing the same styles

Exceptions
NullPointerException:
if context is null
fromThemeback to summary
public static StyleContext fromTheme(String theme)

Creates a StyleContext from a CliqueTheme.

The registered styles are copied; the returned context is independent of the source.

Parameters
theme:String

the name of the theme to be registered; must not be null

Returns:StyleContext

a new StyleContext containing the same styles

Exceptions
NullPointerException:
if theme is null
NoSuchThemeException:
if no theme was found
getback to summary
public AnsiCode get(String s)

Returns the AnsiCode registered under the given markup name, or null if no style is registered for that name.

Parameters
s:String

the markup name to look up

Returns:AnsiCode

the associated AnsiCode, or null if not present

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
io.github.kusoroadeolu.clique.configuration back to summary

public Class StyleContext.StyleContextBuilder

extends Object
Class Inheritance
  • java.lang.Object
  • io.github.kusoroadeolu.clique.configuration.StyleContext.StyleContextBuilder

Builder for StyleContext.

Multiple add calls accumulate; later registrations for the same markup name overwrite earlier ones. All overloads ultimately store a single AnsiCode per name — multi-code overloads wrap their arguments in a CompositeColor.

This builder is not thread-safe.

Field Summary

Modifier and TypeField and Description
private final Map<String, AnsiCode>
private static final String

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public StyleContext.StyleContextBuilder

Returns:

this builder
add
(String
the markup name; must not be null
style
,
AnsiCode
the ANSI code to associate; must not be null
code
)

Registers a single AnsiCode under the given markup name.

public StyleContext.StyleContextBuilder

Returns:

this builder
add
(String
the markup name; must not be null
style
,
AnsiCode...
one or more ANSI codes to combine; must not be null
code
)

Registers multiple AnsiCode instances under the given markup name, combining them into a CompositeColor.

public StyleContext.StyleContextBuilder

Returns:

this builder
add
(String
the markup name; must not be null
style
,
Collection<AnsiCode>
a collection of ANSI codes to combine; must not be null
code
)

Registers a collection of AnsiCode instances under the given markup name, combining them into a CompositeColor.

public StyleContext.StyleContextBuilder

Returns:

this builder
add
(Map<String, AnsiCode>
a map of markup names to ANSI codes; must not be null
codes
)

Bulk-registers all entries from the given map.

public StyleContext.StyleContextBuilder

Returns:

this builder
add
(StyleContext
the context whose styles to merge; must not be null
context
)

Merges all styles from an existing StyleContext into this builder.

public StyleContext

Returns:

a new, immutable StyleContext
build
()

Constructs a new StyleContext from the current builder state.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

localStylesback to summary
private final Map<String, AnsiCode> localStyles
NULL_STYLE_NAMEback to summary
private static final String NULL_STYLE_NAME

Constructor Detail

StyleContextBuilderback to summary
private StyleContextBuilder()

Method Detail

addback to summary
public StyleContext.StyleContextBuilder add(String style, AnsiCode code)

Registers a single AnsiCode under the given markup name.

Parameters
style:String

the markup name; must not be null

code:AnsiCode

the ANSI code to associate; must not be null

Returns:StyleContext.StyleContextBuilder

this builder

Exceptions
NullPointerException:
if style or code is null
addback to summary
public StyleContext.StyleContextBuilder add(String style, AnsiCode... code)

Registers multiple AnsiCode instances under the given markup name, combining them into a CompositeColor.

Parameters
style:String

the markup name; must not be null

code:AnsiCode[]

one or more ANSI codes to combine; must not be null

Returns:StyleContext.StyleContextBuilder

this builder

Exceptions
NullPointerException:
if style or code is null
addback to summary
public StyleContext.StyleContextBuilder add(String style, Collection<AnsiCode> code)

Registers a collection of AnsiCode instances under the given markup name, combining them into a CompositeColor.

Parameters
style:String

the markup name; must not be null

code:Collection<AnsiCode>

a collection of ANSI codes to combine; must not be null

Returns:StyleContext.StyleContextBuilder

this builder

Exceptions
NullPointerException:
if style or code is null
addback to summary
public StyleContext.StyleContextBuilder add(Map<String, AnsiCode> codes)

Bulk-registers all entries from the given map.

Entries are added in iteration order; if the map contains a name already registered in this builder, the map's value overwrites the existing one.

Parameters
codes:Map<String, AnsiCode>

a map of markup names to ANSI codes; must not be null

Returns:StyleContext.StyleContextBuilder

this builder

Exceptions
NullPointerException:
if codes is null
addback to summary
public StyleContext.StyleContextBuilder add(StyleContext context)

Merges all styles from an existing StyleContext into this builder.

If a name from context is already registered in this builder, the incoming value overwrites the existing one.

Parameters
context:StyleContext

the context whose styles to merge; must not be null

Returns:StyleContext.StyleContextBuilder

this builder

Exceptions
NullPointerException:
if context is null
buildback to summary
public StyleContext build()

Constructs a new StyleContext from the current builder state.

Returns:StyleContext

a new, immutable StyleContext