Class: Tuile::Buffer::Cell

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

Instance Method Summary collapse

Constructor Details

#initialize(grapheme, style) ⇒ Cell

@param grapheme

@param style

Parameters:



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

#dirtyBoolean

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

Returns:

  • (Boolean)


72
73
74
# File 'lib/tuile/buffer.rb', line 72

def dirty
  @dirty
end

#graphemeString (readonly)

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

@return — one grapheme cluster, " " for blank, or "" for a wide-glyph continuation.

Returns:

  • (String)


65
66
67
# File 'lib/tuile/buffer.rb', line 65

def grapheme
  @grapheme
end

#styleStyledString::Style (readonly)

Returns:



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

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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.

Parameters:

Returns:

  • (Boolean)


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