From mboxrd@z Thu Jan 1 00:00:00 1970 From: dag.odenhall@gmail.com (Dag Odenhall) Date: Fri, 25 Apr 2008 21:12:16 +0200 Subject: [sup-talk] [PATCH] use any custom colors configured in config.yaml Message-ID: <1209150616-sup-8211@psilocybic> * bin/sup: (start_cursing) Initialize use of default colors (transparency). * lib/sup/colormap.rb: Add a COLOR_DEFAULT constant to the Curses module. (CURSES_COLOR) Add the new COLOR_DEFAULT constant. (color_for) Use colors from config if available. Signed-off-by: Dag Odenhall --- bin/sup | 1 + lib/sup/colormap.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletions(-) diff --git a/bin/sup b/bin/sup index 6360cde..e791fe5 100644 --- a/bin/sup +++ b/bin/sup @@ -78,6 +78,7 @@ def start_cursing Ncurses.stdscr.keypad 1 Ncurses.curs_set 0 Ncurses.start_color + Ncurses.use_default_colors $cursing = true end diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb index 9c6869a..4c48604 100644 --- a/lib/sup/colormap.rb +++ b/lib/sup/colormap.rb @@ -1,3 +1,7 @@ +module Curses + COLOR_DEFAULT = -1 +end + module Redwood class Colormap @@ -6,7 +10,7 @@ class Colormap CURSES_COLORS = [Curses::COLOR_BLACK, Curses::COLOR_RED, Curses::COLOR_GREEN, Curses::COLOR_YELLOW, Curses::COLOR_BLUE, Curses::COLOR_MAGENTA, Curses::COLOR_CYAN, - Curses::COLOR_WHITE] + Curses::COLOR_WHITE, Curses::COLOR_DEFAULT] NUM_COLORS = 15 def initialize @@ -80,6 +84,11 @@ class Colormap fg, bg, attrs, color = @entries[sym] return color if color + confcolor = $config[:colors][sym.to_s[0..-7].to_sym] rescue nil + fg = Curses.const_get "COLOR_#{confcolor[:fg].upcase}" rescue fg + bg = Curses.const_get "COLOR_#{confcolor[:bg].upcase}" rescue bg + attrs = confcolor[:attrs].map {|a| Curses.const_get "A_#{a.upcase}" } rescue attrs + if(cp = @color_pairs[[fg, bg]]) ## nothing else ## need to get a new colorpair -- 1.5.5.1