Class: Twterm::Image::Color
Instance Method Summary
collapse
#!, #-, #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
#height ⇒ Object
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_s ⇒ Object
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
|
#width ⇒ Object
32
33
34
|
# File 'lib/twterm/image/color.rb', line 32
def width
image.width
end
|