Top Description Fields Constructors Methods
io.github.kusoroadeolu.clique.style

public final Class Ink

extends Object
Class Inheritance
Annotations
@Stable
since:4.0.1
Imports
io.github.kusoroadeolu.clique.configuration.StyleContext, io.github.kusoroadeolu.clique.internal.Gradient, .Hyperlink, .RGBColor, io.github.kusoroadeolu.clique.internal.documentation.Stable, io.github.kusoroadeolu.clique.internal.markup.PredefinedStyleContext, io.github.kusoroadeolu.clique.internal.utils.StringUtils, io.github.kusoroadeolu.clique.spi.AnsiCode, .RGBAnsiCode, java.util.ArrayList, .Collections, .List, .Objects

A lightweight, functional, chainable ANSI string builder.

Similar in spirit to Chalk. Each method returns a new Ink instance, leaving the original unchanged. Call on(String) to produce the final styled string.

Outputs raw ANSI escape sequences directly — no markup parser involved.

Usage:

Clique.ink().red().bold().on("Error")

Clique.ink().of("ctp_mauve").bold().on("Hello")
Since
4.0.0

Field Summary

Modifier and TypeField and Description
private final List<AnsiCode>
private final StyleContext
private final Gradient
private final Hyperlink

Constructor Summary

AccessConstructor and Description
public
Ink()

public
Ink(StyleContext context)

pack-priv
Ink(List<AnsiCode> codes, StyleContext context)

Method Summary

Modifier and TypeMethod and Description
public Ink
public Ink
public Ink
public Ink
public Ink

Returns:

a new Ink instance with the hex color accumulated
bgHex
(String
the hex color string; must not be null and must be in #RRGGBB format
hexCode
)

Applies a background hex color to this Ink instance.

public Ink
public Ink
public Ink
bgRgb(int red, int green, int blue)

public Ink
public Ink
public Ink
public Ink
blue()

public Ink
bold()

public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
public Ink
cyan()

public Ink
dim()

public Ink
public boolean
equals(Object o)

Overrides java.lang.Object.equals.

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

public Ink

Returns:

a new Ink instance with the gradient accumulated
gradient
(RGBAnsiCode
the starting RGBAnsiCode of the gradient; must not be null
from
,
RGBAnsiCode
the ending RGBAnsiCode of the gradient; must not be null
to
)

Applies a color gradient to this Ink instance, transitioning from one RGBAnsiCode to another across the rendered text.

public Ink

Returns:

a new Ink instance with the gradient accumulated
gradient
(String
the starting hexCode of the gradient; must not be null
fromHex
,
String
the ending hexCode of the gradient; must not be null
toHex
)

Applies a color gradient to this Ink instance, transitioning from one hex code to another across the rendered text.

public Ink
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Ink

Returns:

a new Ink instance with the hex color accumulated
hex
(String
the hex color string; must not be null and must be in #RRGGBB format
hexCode
)

Applies a foreground hex color to this Ink instance.

public Ink
public Ink
public Ink
public Ink

Returns:

a new Ink instance with the style accumulated
of
(String
the registered style name (e.g. "ctp_mauve")
style
)

Adds a named style, looked up from the instance's StyleContext and PredefinedStyleContext.

public Ink

Returns:

a new Ink instance with the style accumulated
of
(AnsiCode
the AnsiCode to be applied
code
)

Adds a named style, looked up from the instance's StyleContext and PredefinedStyleContext.

public String

Returns:

the styled string with ANSI sequences applied, or just the raw String if no styles were accumulated
on
(String
the String to style;
value
)

Applies the accumulated ANSI codes to the given value and returns the styled string.

public String

Returns:

the styled string with ANSI sequences applied, or just value.toString() if no styles were accumulated
on
(Object
the Object to style; toString() is called on it
value
)

Applies the accumulated ANSI codes to the given value and returns the styled string.

public Ink
red()

public Ink
public Ink
rgb(int red, int green, int blue)

public Ink
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public Ink
public Ink
private Ink
with(AnsiCode code)

private Ink
with(Gradient gradient)

public Ink
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

codesback to summary
private final List<AnsiCode> codes
contextback to summary
private final StyleContext context
gradientback to summary
private final Gradient gradient

Constructor Detail

Inkback to summary
public Ink()
Inkback to summary
public Ink(StyleContext context)
Inkback to summary
pack-priv Ink(List<AnsiCode> codes, StyleContext context)

Method Detail

bgBlackback to summary
public Ink bgBlack()
bgBlueback to summary
public Ink bgBlue()
bgCyanback to summary
public Ink bgCyan()
bgGreenback to summary
public Ink bgGreen()
bgHexback to summary
public Ink bgHex(String hexCode)

Applies a background hex color to this Ink instance.

The hex string must be in #RRGGBB format. The value is parsed into an RGBColor and applied to the rendered text.

Parameters
hexCode:String

the hex color string; must not be null and must be in #RRGGBB format

Returns:Ink

a new Ink instance with the hex color accumulated

Exceptions
NullPointerException:
if hexCode is null
IllegalArgumentException:
if hexCode is not in #RRGGBB format
bgMagentaback to summary
public Ink bgMagenta()
bgRedback to summary
public Ink bgRed()
bgRgbback to summary
public Ink bgRgb(int red, int green, int blue)
bgWhiteback to summary
public Ink bgWhite()
bgYellowback to summary
public Ink bgYellow()
blackback to summary
public Ink black()
blueback to summary
public Ink blue()
boldback to summary
public Ink bold()
brightBgBlackback to summary
public Ink brightBgBlack()
brightBgBlueback to summary
public Ink brightBgBlue()
brightBgCyanback to summary
public Ink brightBgCyan()
brightBgGreenback to summary
public Ink brightBgGreen()
brightBgMagentaback to summary
public Ink brightBgMagenta()
brightBgRedback to summary
public Ink brightBgRed()
brightBgWhiteback to summary
public Ink brightBgWhite()
brightBgYellowback to summary
public Ink brightBgYellow()
brightBlackback to summary
public Ink brightBlack()
brightBlueback to summary
public Ink brightBlue()
brightCyanback to summary
public Ink brightCyan()
brightGreenback to summary
public Ink brightGreen()
brightMagentaback to summary
public Ink brightMagenta()
brightRedback to summary
public Ink brightRed()
brightWhiteback to summary
public Ink brightWhite()
brightYellowback to summary
public Ink brightYellow()
cyanback to summary
public Ink cyan()
dimback to summary
public Ink dim()
doubleUnderlineback to summary
public Ink doubleUnderline()
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
gradientback to summary
public Ink gradient(RGBAnsiCode from, RGBAnsiCode to)

Applies a color gradient to this Ink instance, transitioning from one RGBAnsiCode to another across the rendered text.

The gradient is computed by linearly interpolating the R, G, and B channels between from and to across each visible character. Existing ANSI escape sequences embedded in the text are preserved and excluded from the interpolation; only printable characters are colorized. A RESET sequence is appended at the end of the output.

Parameters
from:RGBAnsiCode

the starting RGBAnsiCode of the gradient; must not be null

to:RGBAnsiCode

the ending RGBAnsiCode of the gradient; must not be null

Returns:Ink

a new Ink instance with the gradient accumulated

Exceptions
NullPointerException:
if from or to is null
gradientback to summary
public Ink gradient(String fromHex, String toHex)

Applies a color gradient to this Ink instance, transitioning from one hex code to another across the rendered text.

The gradient is computed by linearly interpolating the R, G, and B channels between fromHex and toHex across each visible character. Existing ANSI escape sequences embedded in the text are preserved and excluded from the interpolation; only printable characters are colorized. A RESET sequence is appended at the end of the output.

Parameters
fromHex:String

the starting hexCode of the gradient; must not be null

toHex:String

the ending hexCode of the gradient; must not be null

Returns:Ink

a new Ink instance with the gradient accumulated

Exceptions
NullPointerException:
if from or to is null
greenback to summary
public Ink green()
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
hexback to summary
public Ink hex(String hexCode)

Applies a foreground hex color to this Ink instance.

The hex string must be in #RRGGBB format. The value is parsed into an RGBColor and applied to the rendered text.

Parameters
hexCode:String

the hex color string; must not be null and must be in #RRGGBB format

Returns:Ink

a new Ink instance with the hex color accumulated

Exceptions
NullPointerException:
if hexCode is null
IllegalArgumentException:
if hexCode is not in #RRGGBB format
invisibleback to summary
public Ink invisible()
italicback to summary
public Ink italic()
magentaback to summary
public Ink magenta()
ofback to summary
public Ink of(String style)

Adds a named style, looked up from the instance's StyleContext and PredefinedStyleContext. Throws UndefinedStyleException if not found.

Parameters
style:String

the registered style name (e.g. "ctp_mauve")

Returns:Ink

a new Ink instance with the style accumulated

Exceptions
NullPointerException:
if style is null
ofback to summary
public Ink of(AnsiCode code)

Adds a named style, looked up from the instance's StyleContext and PredefinedStyleContext. Throws UndefinedStyleException if not found.

Parameters
code:AnsiCode

the AnsiCode to be applied

Returns:Ink

a new Ink instance with the style accumulated

Exceptions
NullPointerException:
if style is null
onback to summary
public String on(String value)

Applies the accumulated ANSI codes to the given value and returns the styled string. Appends a reset sequence at the end.

Parameters
value:String

the String to style;

Returns:String

the styled string with ANSI sequences applied, or just the raw String if no styles were accumulated

Exceptions
NullPointerException:
if value is null
onback to summary
public String on(Object value)

Applies the accumulated ANSI codes to the given value and returns the styled string. Appends a reset sequence at the end.

Parameters
value:Object

the Object to style; toString() is called on it

Returns:String

the styled string with ANSI sequences applied, or just value.toString() if no styles were accumulated

Exceptions
NullPointerException:
if value is null
redback to summary
public Ink red()
reverseVideoback to summary
public Ink reverseVideo()
rgbback to summary
public Ink rgb(int red, int green, int blue)
strikethroughback to summary
public Ink strikethrough()
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
underlineback to summary
public Ink underline()
whiteback to summary
public Ink white()
withback to summary
private Ink with(AnsiCode code)
withback to summary
private Ink with(Gradient gradient)
yellowback to summary
public Ink yellow()