From mboxrd@z Thu Jan 1 00:00:00 1970 From: dag.odenhall@gmail.com (Dag Odenhall) Date: Fri, 25 Apr 2008 01:53:51 +0200 Subject: [sup-talk] [PATCH] Configurable coloring Message-ID: <1209080103-sup-8620@psilocybic> Hello good folks This lil patch allows you to override these color symbols: :status :index_old :index_new :index_starred :index_draft :labellist_old :labellist_new :twiddle :label :message_patina :alternate_patina :missing_message :attachment :cryptosig_valid :cryptosig_unknown :cryptosig_invalid :generic_notice_patina :quote_patina :sig_patina :quote :sig :to_me :starred :starred_patina :alternate_starred_patina :snippet :option :tagged :draft_notification :completion_character :horizontal_selector_selected :horizontal_selector_unselected :search_highlight in your config.yaml. You can set :fg or :bg to any of: default (transparent) black blue cyan green magenta red white yellow You can also set :attrs to a list of any of: horizontal reverse left blink low dim right bold top protect attributes vertical invis normal color altcharset standout chartext underline This all goes under :colors, so an example would be: :colors: :status: :fg: black :bg: red :attrs: - reverse - underline This is all a quick hack that can probably be improved upon, but it works fine. Thanks Marc Hartstein for help with getting the transparency working. Dag. diff --git a/bin/sup b/bin/sup index 078a134..0c5e70d 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