Class: GLW::Screen::UpdateBlock

Inherits:
Data
  • Object
show all
Defined in:
lib/glw/screen.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cellsObject (readonly)

Returns the value of attribute cells

Returns:

  • (Object)

    the current value of cells



4
5
6
# File 'lib/glw/screen.rb', line 4

def cells
  @cells
end

#start_indexObject (readonly)

Returns the value of attribute start_index

Returns:

  • (Object)

    the current value of start_index



4
5
6
# File 'lib/glw/screen.rb', line 4

def start_index
  @start_index
end

Class Method Details

.make(start_index) ⇒ Object



5
# File 'lib/glw/screen.rb', line 5

def self.make(start_index) = new(start_index, [])

Instance Method Details

#to_s(current_fg: nil, current_bg: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/glw/screen.rb', line 7

def to_s(current_fg: nil, current_bg: nil)
  output = ""
  fg = current_fg
  bg = current_bg

  cells.each do |cell|
    if cell.fg_color != fg
      output << Terminal.set_fg(cell.fg_color)
      fg = cell.fg_color
    end

    if cell.bg_color != bg
      output << Terminal.set_bg(cell.bg_color)
      bg = cell.bg_color
    end

    output << cell.char
  end

  [output, fg, bg]
end