struct

TermBuf::Style

Inherits Struct < Value < Object

Stability: stable — changes only in a major release.

Everything about a cell other than the character in it.

Styles are values, so they compare and hash by content. StyleTable interns them, which is what lets a Cell carry a four byte id instead of this whole struct.

Constants

DEFAULT = new

The style a freshly cleared terminal is in.

KEEP_BACKGROUND = Blend.new do |under, over, _column, _row| over.bg(under.background) end

A blend that keeps the colour already behind each cell and takes everything else from the style being written — a label across a progress bar, without the caller working out where the bar's colours change. A background named in the written style is ignored.

The position is ignored: this blend answers the same way wherever the cell is, which is why the two arguments it does use are named and the rest are not.

OVER = Blend.new do |under, over, _column, _row| under.merge(over) end

A blend laying the written style over what is already there, field by field, the way a view lays its own style under a write. See #merge.

The position is ignored, as it is for KEEP_BACKGROUND.

Constructors

Class methods

blend

Wraps a two argument block as a Blend, for the blends that answer from the two styles alone.

dim = TermBuf::Style.blend { |under, over| under.merge(over).faint }

The position the Blend signature carries is dropped rather than named, since a block written this way has nowhere to receive it.

Source

Instance methods

attributes

Everything a cell can be at once.

Source
background

Cell colour behind the text.

Source
bg(color : Color) : Style

A copy with a different background.

Source
bold

A copy with the bold attribute set.

Source
conceal

A copy the terminal renders as blanks.

Source
default?

Whether this is the untouched style, which needs no escape sequence.

Source
faint

A copy with the faint attribute set.

Source
fg(color : Color) : Style

A copy with a different text colour.

Source
foreground

Text colour.

Source
has?(flags : Attributes) : Bool

Whether every attribute in flags is set.

Source
ink?

Whether the cell paints anything other than its background. A cell that does not is interchangeable with a blank of the same background, which is what lets the painter reach for an erase instead of writing spaces.

Source
italic

A copy with the italic attribute set.

Source
linked(id : UInt32) : Style

A copy carrying OSC 8 link id. Zero means no link.

Source
merge(other : Style) : Style

A copy of this style with everything other sets taking over. A field other leaves at its default is kept from here.

What a surface carrying a base style needs: a panel says its background once, and a write inside it names only the colour and the attributes it cares about. Colours, the underline style, and the link merge that way.

Attributes are the exception. They are flags rather than a choice of one, so they combine: a bold write inside a faint panel is both, and there is no value of Attributes that means "leave the panel's alone" separately from "add none of my own".

Source
reverse

A copy with foreground and background swapped by the terminal.

Source
strike

A copy with the strike-through attribute set.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
underline

Which of the underline styles, if any.

Source
underline_color

Colour of the underline, when the terminal supports colouring it separately from the text.

Source
underlined(style : Underline = Underline::Single, color : Color = @underline_color) : Style

A copy carrying an underline. Terminals without ExtendedUnderline render every style as a plain one, and without UnderlineColor ignore color.

Source
with(flags : Attributes) : Style

Returns a copy with flags added.

Source
without(flags : Attributes) : Style

Returns a copy with flags removed.

Source