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:



56
57
58
59
60
# File 'lib/tuile/buffer.rb', line 56

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)


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

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)


45
46
47
# File 'lib/tuile/buffer.rb', line 45

def grapheme
  @grapheme
end

#styleStyledString::Style (readonly)

Returns:



48
49
50
# File 'lib/tuile/buffer.rb', line 48

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)


87
88
89
# File 'lib/tuile/buffer.rb', line 87

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)


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

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)


75
76
77
78
79
80
81
# File 'lib/tuile/buffer.rb', line 75

def set(grapheme, style)
  return @dirty if @grapheme == grapheme && @style == style

  @grapheme = grapheme
  @style = style
  @dirty = true
end