Class: Twterm::Image::Color
- Inherits:
-
Attr
- Object
- Twterm::Image
- Attr
- Twterm::Image::Color
- Defined in:
- lib/twterm/image/color.rb
Instance Method Summary collapse
-
#initialize(image, fg, bg = :transparent) ⇒ Color
constructor
A new instance of Color.
- #to_s ⇒ Object
Methods inherited from Attr
Methods inherited from Twterm::Image
#!, #-, #_, #at, blank_line, #bold, #brackets, checkbox, #color, #column, cursor, #dim, empty, #line, number, #parens, plural, remaining_resource, string, toggle_switch, #underlined, whitespace, #|
Constructor Details
#initialize(image, fg, bg = :transparent) ⇒ Color
Returns a new instance of Color.
6 7 8 9 10 |
# File 'lib/twterm/image/color.rb', line 6 def initialize(image, fg, bg = :transparent) super(image) @fg, @bg = fg, bg end |
Instance Method Details
#to_s ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/twterm/image/color.rb', line 12 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 |