Class: Twterm::Image::Color

Inherits:
Twterm::Image show all
Defined in:
lib/twterm/image/color.rb

Instance Method Summary collapse

Methods inherited from Twterm::Image

#!, #-, #at, blank_line, #bold, #brackets, checkbox, #color, #column, cursor, empty, #line, number, #parens, plural, remaining_resource, string, whitespace, #|

Constructor Details

#initialize(image, fg, bg = :transparent) ⇒ Color

Returns a new instance of Color.



4
5
6
# File 'lib/twterm/image/color.rb', line 4

def initialize(image, fg, bg = :transparent)
  @image, @fg, @bg = image, fg, bg
end

Instance Method Details

#heightObject



8
9
10
# File 'lib/twterm/image/color.rb', line 8

def height
  image.height
end

#render(window) ⇒ Object



12
13
14
15
16
# File 'lib/twterm/image/color.rb', line 12

def render(window)
  window.attron(Curses.color_pair(color_pair_index))
  image.at(line, column).render(window)
  window.attroff(Curses.color_pair(color_pair_index))
end

#to_sObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/twterm/image/color.rb', line 18

def to_s
  fg_colors = {
    black: 30, red: 31, green: 32, yellow: 33,
    blue: 34, magenta: 35, cyan: 36, white: 37
  }
  bg_colors = {
    black: 40, red: 41, green: 42, yellow: 43,
    blur: 44, magenta: 45, cyan: 46, white: 47
  }

  str = "\e[#{fg_colors[@fg]}m#{image}\e[0m"
  @bg == :transparent ? str : "\e[#{bg_colors[@bg]}m#{str}"
end

#widthObject



32
33
34
# File 'lib/twterm/image/color.rb', line 32

def width
  image.width
end