class

Ansi::Style

Inherits Reference < Object

Style represents an ANSI SGR (Select Graphic Rendition) style.

Constants

CurlyUnderlineStyle = Underline::Curly
DashedUnderlineStyle = Underline::Dashed
DottedUnderlineStyle = Underline::Dotted
DoubleUnderlineStyle = Underline::Double
NoUnderlineStyle = Underline::None

Underline styles constants (deprecated aliases for compatibility)

SingleUnderlineStyle = Underline::Single
UnderlineCurly = Underline::Curly
UnderlineDashed = Underline::Dashed
UnderlineDotted = Underline::Dotted
UnderlineDouble = Underline::Double
UnderlineNone = Underline::None

Underline styles constants.

UnderlineSingle = Underline::Single
UnderlineStyleCurly = Underline::Curly
UnderlineStyleDashed = Underline::Dashed
UnderlineStyleDotted = Underline::Dotted
UnderlineStyleDouble = Underline::Double
UnderlineStyleNone = Underline::None

More deprecated constants

UnderlineStyleSingle = Underline::Single

Constructors

new(attrs : Array(String))
Source
new(attrs : Array(Attr)) : Style

NewStyle returns a new style with the given attributes. Attributes are SGR (Select Graphic Rendition) codes that control text formatting like bold, italic, colors, etc.

Source

Instance methods

attrs
Source
background_color(c : AnyColor = nil) : Style

BackgroundColor appends the background color style attribute to the style. If c is nil, the default background color is used.

Source
bold

Bold appends the bold or normal intensity style attribute to the style.

Source
conceal(v : Bool) : Style

Conceal appends the conceal or no conceal style attribute to the style. When v is true, text is hidden/concealed. When false, concealment is disabled.

Source
default_background_color

DefaultBackgroundColor appends the default background color style attribute to the style.

Source
default_foreground_color

DefaultForegroundColor appends the default foreground color style attribute to the style.

Deprecated: use #foreground_color(nil) instead.

Source
default_underline_color

DefaultUnderlineColor appends the default underline color style attribute to the style.

Deprecated: use #underline_color(nil) instead.

Source
faint

Faint appends the faint or normal intensity style attribute to the style.

Source
foreground_color(c : AnyColor = nil) : Style

ForegroundColor appends the foreground color style attribute to the style. If c is nil, the default foreground color is used.

Source
italic(v : Bool) : Style

Italic appends the italic or no italic style attribute to the style. When v is true, text is rendered in italic. When false, italic is disabled.

Source
no_conceal

NoConceal appends the no conceal style attribute to the style.

Deprecated: use #conceal(false) instead.

Source
no_italic

NoItalic appends the no italic style attribute to the style.

Deprecated: use #italic(false) instead.

Source
no_reverse

NoReverse appends the no reverse style attribute to the style.

Deprecated: use #reverse(false) instead.

Source
no_strikethrough

NoStrikethrough appends the no strikethrough style attribute to the style.

Deprecated: use #strikethrough(false) instead.

Source
no_underline

NoUnderline appends the no underline style attribute to the style.

Deprecated: use #underline(false) instead.

Source
normal

Normal appends the normal intensity style attribute to the style. This resets Bold and Faint attributes.

Source
reset

Reset appends the reset style attribute to the style. This resets all formatting attributes to their defaults.

Source
reverse(v : Bool) : Style

Reverse appends the reverse or no reverse style attribute to the style. When v is true, foreground and background colors are swapped. When false, reverse video is disabled.

Source
strikethrough(v : Bool) : Style

Strikethrough appends the strikethrough or no strikethrough style attribute to the style. When v is true, text is rendered with a horizontal line through it. When false, strikethrough is disabled.

Source
styled(str : String) : String

Styled returns a styled string with the given style applied. The style is applied at the beginning and reset at the end of the string.

Source
to_s

String returns the ANSI SGR (Select Graphic Rendition) style sequence for the given style.

Source
underline(v : Bool) : Style

Underline appends the underline or no underline style attribute to the style. When v is true, text is underlined. When false, underline is disabled.

Source
underline_color(c : AnyColor = nil) : Style

UnderlineColor appends the underline color style attribute to the style. If c is nil, the default underline color is used.

Source
underline_style(u : Underline) : Style

UnderlineStyle appends the underline style attribute to the style. Supports various underline styles including single, double, curly, dotted, and dashed.

Source

Nested types