Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
* [sup-talk] [PATCH] use any custom colors configured in config.yaml
@ 2008-04-25 19:12 Dag Odenhall
  2008-04-28 22:28 ` William Morgan
  0 siblings, 1 reply; 3+ messages in thread
From: Dag Odenhall @ 2008-04-25 19:12 UTC (permalink / raw)


* 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 <dag.odenhall at gmail.com>
---
 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [sup-talk] [PATCH] use any custom colors configured in config.yaml
  2008-04-25 19:12 [sup-talk] [PATCH] use any custom colors configured in config.yaml Dag Odenhall
@ 2008-04-28 22:28 ` William Morgan
  2008-04-28 23:01   ` Dag Odenhall
  0 siblings, 1 reply; 3+ messages in thread
From: William Morgan @ 2008-04-28 22:28 UTC (permalink / raw)


Hi Dag,

Thanks for the patch! People have been clamoring for this functionality
forever and I have been cruelly not doing it for them.

A few minor comments:

Reformatted excerpts from Dag Odenhall's message of 2008-04-25:
> +    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

1. Can you wrap all this in an if statement, rather than having sequence of
   post-fix rescue stuff? You could do something like "if(confcolor
   = $config[...)" and set fg and bg within that.

2. Errors in the color names will be silently ignored. The
   NameError exception should be caught and turned into a
   BufferManager.flash and a Redwood::log to inform the user.

3. Since I feel like people will write a lot of these descriptions, I
   would load in colors from a colors.yaml file instead of from the
   config file. (I can do this one instead if you're unsure.)

-- 
William <wmorgan-sup at masanjin.net>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [sup-talk] [PATCH] use any custom colors configured in config.yaml
  2008-04-28 22:28 ` William Morgan
@ 2008-04-28 23:01   ` Dag Odenhall
  0 siblings, 0 replies; 3+ messages in thread
From: Dag Odenhall @ 2008-04-28 23:01 UTC (permalink / raw)


Excerpts from William Morgan's message of Tue Apr 29 00:28:29 +0200 2008:
> Hi Dag,
> 
> Thanks for the patch! People have been clamoring for this functionality
> forever and I have been cruelly not doing it for them.

Well thanks for the thanks! :)

> 
> A few minor comments:
> 
> Reformatted excerpts from Dag Odenhall's message of 2008-04-25:
> > +    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
> 
> 1. Can you wrap all this in an if statement, rather than having sequence of
>    post-fix rescue stuff? You could do something like "if(confcolor
>    = $config[...)" and set fg and bg within that.
> 
> 2. Errors in the color names will be silently ignored. The
>    NameError exception should be caught and turned into a
>    BufferManager.flash and a Redwood::log to inform the user.

I'll give it a try.

> 3. Since I feel like people will write a lot of these descriptions, I
>    would load in colors from a colors.yaml file instead of from the
>    config file. (I can do this one instead if you're unsure.)

I could give this a try too, then again you are probably better at
getting it the way you envision it... I guess we'll see. :)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-04-28 23:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-25 19:12 [sup-talk] [PATCH] use any custom colors configured in config.yaml Dag Odenhall
2008-04-28 22:28 ` William Morgan
2008-04-28 23:01   ` Dag Odenhall

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