Class: UI::Colors
- Inherits:
-
Object
- Object
- UI::Colors
- Defined in:
- lib/ektoplayer/ui/colors.rb
Constant Summary collapse
- COLORS =
{ none: -1, white: ICurses::COLOR_WHITE, black: ICurses::COLOR_BLACK, red: ICurses::COLOR_RED, blue: ICurses::COLOR_BLUE, cyan: ICurses::COLOR_CYAN, green: ICurses::COLOR_GREEN, yellow: ICurses::COLOR_YELLOW, magenta: ICurses::COLOR_MAGENTA }
- ATTRIBUTES =
{ bold: ICurses::A_BOLD, standout: ICurses::A_STANDOUT, blink: ICurses::A_BLINK, underline: ICurses::A_UNDERLINE }
Class Method Summary collapse
- .[](name) ⇒ Object
- .add_attributes(*attrs) ⇒ Object
- .default_bg(color) ⇒ Object
- .default_colors(fg = -1,, bg = -1)) ⇒ Object
- .default_fg(color) ⇒ Object
- .get(name) ⇒ Object
- .get_volatile(name) ⇒ Object
- .init_pair_cached(fg, bg) ⇒ Object
- .reset ⇒ Object
- .set(name, fg, bg = nil, *attrs) ⇒ Object
- .set_volatile(name, fg, bg) ⇒ Object
- .start ⇒ Object
Class Method Details
.[](name) ⇒ Object
109 |
# File 'lib/ektoplayer/ui/colors.rb', line 109 def self.[](name) @@aliases[name] || 0 end |
.add_attributes(*attrs) ⇒ Object
103 104 105 106 107 |
# File 'lib/ektoplayer/ui/colors.rb', line 103 def self.add_attributes(*attrs) flags = 0 attrs.each { |attr| flags |= ATTRIBUTES[attr] } flags end |
.default_bg(color) ⇒ Object
72 73 74 |
# File 'lib/ektoplayer/ui/colors.rb', line 72 def self.default_bg(color) @@default_bg = COLORS[color] end |
.default_colors(fg = -1,, bg = -1)) ⇒ Object
76 77 78 79 |
# File 'lib/ektoplayer/ui/colors.rb', line 76 def self.default_colors(fg = -1, bg = -1) self.default_fg(fg) self.default_bg(bg) end |
.default_fg(color) ⇒ Object
68 69 70 |
# File 'lib/ektoplayer/ui/colors.rb', line 68 def self.default_fg(color) @@default_fg = COLORS[color] end |
.get(name) ⇒ Object
110 |
# File 'lib/ektoplayer/ui/colors.rb', line 110 def self.get(name) @@aliases[name] || 0 end |
.get_volatile(name) ⇒ Object
118 119 120 |
# File 'lib/ektoplayer/ui/colors.rb', line 118 def self.get_volatile(name) @@volatile[name] || 0 end |
.init_pair_cached(fg, bg) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ektoplayer/ui/colors.rb', line 81 def self.init_pair_cached(fg, bg) if !fg or fg == :default fg = @@default_fg else fg = COLORS[fg] end if !bg or bg == :default bg = @@default_bg else bg = COLORS[bg] end unless id = @@cached[fg][bg] id = @@cached[fg][bg] = @@id @@id += 1 end ICurses.init_pair(id, fg, bg) #or fail ICurses.color_pair(id) end |
.reset ⇒ Object
66 |
# File 'lib/ektoplayer/ui/colors.rb', line 66 def self.reset; self.start end |
.set(name, fg, bg = nil, *attrs) ⇒ Object
112 113 114 115 116 |
# File 'lib/ektoplayer/ui/colors.rb', line 112 def self.set(name, fg, bg = nil, *attrs) @@aliases[name] = self.init_pair_cached(fg, bg) attrs.each { |attr| @@aliases[name] |= ATTRIBUTES[attr] } @@aliases[name] end |
.set_volatile(name, fg, bg) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ektoplayer/ui/colors.rb', line 122 def self.set_volatile(name, fg, bg) fg, bg = COLORS[fg], COLORS[bg] unless id = @@volatile_ids[name] id = @@volatile_ids[name] = @@id @@id += 1 end @@volatile[name] = ICurses.init_pair(id, fg, bg) end |
.start ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/ektoplayer/ui/colors.rb', line 58 def self.start @@id ||= 1 @@aliases ||= {} @@volatile ||= {} @@volatile_ids ||= {} @@cached ||= Hash.new { |h,k| h[k] = {} } @@default_fg = @@default_bg = -1 end |