Class: Tuile::Buffer::Cell
- Inherits:
-
Object
- Object
- Tuile::Buffer::Cell
- Defined in:
- lib/tuile/buffer.rb,
sig/tuile.rbs
Overview
One screen cell: a single grapheme cluster, the StyledString::Style it's drawn in, and a dirty flag. Mutable by design (see Tuile::Buffer "Dirty tracking") — the grid rewrites cells in place. A continuation cell (right half of a wide glyph) carries an empty grapheme — see #continuation?.
Instance Attribute Summary collapse
-
#dirty ⇒ Boolean
@return — true if this cell changed since the last #flush.
-
#grapheme ⇒ String
readonly
Read-only: mutate content through #set so dirty tracking stays correct.
- #style ⇒ StyledString::Style readonly
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Content equality (grapheme + style); the dirty flag is bookkeeping and is deliberately excluded.
-
#continuation? ⇒ Boolean
@return — true if this is the right half of a wide glyph, which #flush skips (the glyph to the left already moved the cursor past it).
-
#initialize(grapheme, style) ⇒ Cell
constructor
@param
grapheme. -
#set(grapheme, style) ⇒ Boolean
Sets the cell's content, flipping #dirty on when grapheme or style actually changes (an already-dirty cell stays dirty).
Constructor Details
#initialize(grapheme, style) ⇒ Cell
@param grapheme
@param style
76 77 78 79 80 |
# File 'lib/tuile/buffer.rb', line 76 def initialize(grapheme, style) @grapheme = grapheme @style = style @dirty = false end |
Instance Attribute Details
#dirty ⇒ Boolean
@return — true if this cell changed since the last Tuile::Buffer#flush. Tuile::Buffer flips it (off as it flushes, on via Tuile::Buffer#mark_all_dirty).
72 73 74 |
# File 'lib/tuile/buffer.rb', line 72 def dirty @dirty end |
#grapheme ⇒ String (readonly)
Read-only: mutate content through #set so dirty tracking stays correct.
@return — one grapheme cluster, " " for blank, or "" for a
wide-glyph continuation.
65 66 67 |
# File 'lib/tuile/buffer.rb', line 65 def grapheme @grapheme end |
#style ⇒ StyledString::Style (readonly)
68 69 70 |
# File 'lib/tuile/buffer.rb', line 68 def style @style end |
Instance Method Details
#==(other) ⇒ Boolean
Content equality (grapheme + style); the dirty flag is bookkeeping and is deliberately excluded.
@param other
107 108 109 |
# File 'lib/tuile/buffer.rb', line 107 def ==(other) other.is_a?(Cell) && @grapheme == other.grapheme && @style == other.style end |
#continuation? ⇒ Boolean
@return — true if this is the right half of a wide glyph, which Tuile::Buffer#flush skips (the glyph to the left already moved the cursor past it).
85 |
# File 'lib/tuile/buffer.rb', line 85 def continuation? = @grapheme.empty? |
#set(grapheme, style) ⇒ Boolean
Sets the cell's content, flipping #dirty on when grapheme or style actually changes (an already-dirty cell stays dirty). Returns the resulting dirty flag, so callers can aggregate row/buffer dirty state in one step. The single mutation path behind Tuile::Buffer#set_char / Tuile::Buffer#fill / Tuile::Buffer#clear.
@param grapheme
@param style
@return — #dirty after the write.
95 96 97 98 99 100 101 |
# File 'lib/tuile/buffer.rb', line 95 def set(grapheme, style) return @dirty if @grapheme == grapheme && @style == style @grapheme = grapheme @style = style @dirty = true end |