Class: Tuile::Buffer::Cell

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(grapheme, style) ⇒ Cell

Returns a new instance of Cell.

Parameters:



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

#dirtyBoolean

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).

Returns:



59
60
61
# File 'lib/tuile/buffer.rb', line 59

def dirty
  @dirty
end

#graphemeString (readonly)

Read-only: mutate content through #set so dirty tracking stays correct.

Returns:

  • (String)

    one grapheme cluster, ‘“ ”` for blank, or `“”` for a wide-glyph continuation.



52
53
54
# File 'lib/tuile/buffer.rb', line 52

def grapheme
  @grapheme
end

#styleStyledString::Style (readonly)

Returns:



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.

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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).

Returns:

  • (Boolean)

    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.

Parameters:

Returns:

  • (Boolean)

    #dirty after the write.



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