class TermBuf::StyleTable

Overview

Interns styles so a Cell can carry a four byte id rather than the whole struct.

Two cells with equal styles always get the same id, which turns the paint diff's style comparison into an integer compare and lets the encoder cache one SGR byte string per id.

The table only grows. An application cycling through distinct styles — an animated colour gradient, say — accumulates entries at roughly 32 bytes each; a hundred thousand of them costs a few megabytes. Real applications use tens.

Defined in:

termbuf/core/style_table.cr

Constant Summary

DEFAULT = 0_u32

The id of Style::DEFAULT, which every table assigns first.

Constructors

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def [](id : StyleId) : Style #

The style id refers to.


[View source]
def []?(id : StyleId) : Style | Nil #

The style id refers to, or nil if it was never assigned.


[View source]
def each(& : StyleId, Style -> ) : Nil #

Yields every interned style with its id, in the order they were added.


[View source]
def id(style : Style) : StyleId #

The id for style, assigning one if this is the first time it is seen.


[View source]
def size : Int32 #

Number of distinct styles interned so far.


[View source]