Class: Tuile::Buffer::Cell
- Inherits:
-
Object
- Object
- Tuile::Buffer::Cell
- Defined in:
- lib/tuile/buffer.rb
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
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
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
A new instance of Cell.
-
#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
Returns a new instance of Cell.
63 64 65 66 67 |
# File 'lib/tuile/buffer.rb', line 63 def initialize(grapheme, style) @grapheme = grapheme @style = style @dirty = false end |
Instance Attribute Details
#dirty ⇒ Boolean
Returns 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).
59 60 61 |
# File 'lib/tuile/buffer.rb', line 59 def dirty @dirty end |
#grapheme ⇒ String (readonly)
Read-only: mutate content through #set so dirty tracking stays correct.
52 53 54 |
# File 'lib/tuile/buffer.rb', line 52 def grapheme @grapheme end |
#style ⇒ StyledString::Style (readonly)
55 56 57 |
# File 'lib/tuile/buffer.rb', line 55 def style @style end |
Instance Method Details
#==(other) ⇒ Boolean
Content equality (grapheme + style); the dirty flag is bookkeeping and is deliberately excluded.
94 95 96 |
# File 'lib/tuile/buffer.rb', line 94 def ==(other) other.is_a?(Cell) && @grapheme == other.grapheme && @style == other.style end |
#continuation? ⇒ Boolean
Returns 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).
72 |
# File 'lib/tuile/buffer.rb', line 72 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.
82 83 84 85 86 87 88 |
# File 'lib/tuile/buffer.rb', line 82 def set(grapheme, style) return @dirty if @grapheme == grapheme && @style == style @grapheme = grapheme @style = style @dirty = true end |