struct

Gradientty::ColorInstance

Inherits Struct < Value < Object

Represents a gradient color instance for rendering strings with color transitions.

Create an instance using Gradientty.gradient(["#hex1", "#hex2", ...]). Use #call for single-line strings or #multiline for multi-line strings.

Constructors

new(colors : Array(Array(Int32)))

Initializes a ColorInstance with an array of RGB color stops.

colors - An array of RGB color stops.

Source

Instance methods

call(str : String)

Applies the gradient to a single-line string.

Spaces and newlines are preserved. The string is returned with ANSI color codes applied.

str - The string to apply the gradient to.

Example:

custom = Gradientty.gradient(["#ff0000", "#00ff00"])
puts custom.call("Hello")
Source
colors

The array of RGB color stops used for the gradient. Each color is an Array of three Int32 values: [R, G, B].

Source
colors=(colors : Array(Array(Int32)))

The array of RGB color stops used for the gradient. Each color is an Array of three Int32 values: [R, G, B].

Source
multiline(str : String, continuous = false)

Applies the gradient to a multi-line string.

Each line receives the full gradient individually by default. If continuous is true, the gradient flows continuously across all lines.

str - The multi-line string to color. continuous - Whether to apply gradient continuously across all lines (default: false).

Example:

custom = Gradientty.gradient(["#ff0000", "#00ff00", "#0000ff"])
puts custom.multiline("Hello\nWorld", true)
Source