Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH] Configurable coloring
@ 2008-04-24 23:53 Dag Odenhall
  0 siblings, 0 replies; only message in thread
From: Dag Odenhall @ 2008-04-24 23:53 UTC (permalink / raw)


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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-24 23:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-24 23:53 [sup-talk] [PATCH] Configurable coloring Dag Odenhall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox