Class: RubyTUI::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/rubytui/cell.rb

Overview

The atomic unit of the rendering grid: a single character with a style.

Each cell in a Buffer holds one character (or empty string for wide-char spacers) and an associated Style.

Constant Summary collapse

EMPTY_CHAR =

Default empty character (space).

" "

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol = EMPTY_CHAR, style = Style::DEFAULT) ⇒ Cell

Returns a new instance of Cell.

Parameters:

  • symbol (String) (defaults to: EMPTY_CHAR) —

    the character (default: space)

  • style (Style) (defaults to: Style::DEFAULT) —

    the style (default: Style::DEFAULT)



19
20
21
22
# File 'lib/rubytui/cell.rb', line 19

def initialize(symbol = EMPTY_CHAR, style = Style::DEFAULT)
  @symbol = symbol
  @style = style
end

Instance Attribute Details

#style ⇒ Style

Returns the style applied to this cell.

Returns:

  • (Style) —

    the style applied to this cell



12
13
14
# File 'lib/rubytui/cell.rb', line 12

def style
  @style
end

#symbol ⇒ String

Returns the character displayed in this cell.

Returns:

  • (String) —

    the character displayed in this cell



10
11
12
# File 'lib/rubytui/cell.rb', line 10

def symbol
  @symbol
end

Instance Method Details

#==(other) ⇒ Boolean

Compare by symbol and style.

Parameters:

  • other (Object) —

    object to compare against

Returns:

  • (Boolean) —

    true if other is a Cell with an equal symbol and style



48
49
50
# File 'lib/rubytui/cell.rb', line 48

def ==(other)
  other.is_a?(Cell) && @symbol == other.symbol && @style == other.style
end

#empty? ⇒ Boolean

Returns true if this cell has default content (space + default style).

Returns:

  • (Boolean) —

    true if this cell has default content (space + default style)



53
# File 'lib/rubytui/cell.rb', line 53

def empty? = @symbol == EMPTY_CHAR && @style == Style::DEFAULT

#reset! ⇒ self

Reset this cell to empty (space character, default style).

Returns:

  • (self)


27
28
29
30
31
# File 'lib/rubytui/cell.rb', line 27

def reset!
  @symbol = EMPTY_CHAR
  @style = Style::DEFAULT
  self
end

#set(symbol, style = Style::DEFAULT) ⇒ self

Set this cell's character and style.

Parameters:

  • symbol (String) —

    the character

  • style (Style) (defaults to: Style::DEFAULT) —

    the style (default: Style::DEFAULT)

Returns:

  • (self)


38
39
40
41
42
# File 'lib/rubytui/cell.rb', line 38

def set(symbol, style = Style::DEFAULT)
  @symbol = symbol
  @style = style
  self
end