Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCHv2 1/3] support high colors in colors.yaml
@ 2010-01-03 15:24 Rich Lane
  2010-01-03 15:24 ` [sup-devel] [PATCH 2/3] send color errors to the log instead of flashing Rich Lane
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Lane @ 2010-01-03 15:24 UTC (permalink / raw)
  To: sup-devel

Add constants for colors >15 so that they can be used in the colors config
file. You can use integers for all available colors. If you're running
xterm-256color or compatible you can use "cXYZ" for the 6x6x6 color cube and
"gX" for 24 shades of gray.
---
 lib/sup/colormap.rb |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
index c4a4024..71c715f 100644
--- a/lib/sup/colormap.rb
+++ b/lib/sup/colormap.rb
@@ -1,5 +1,23 @@
 module Curses
   COLOR_DEFAULT = -1
+
+  NUM_COLORS = `tput colors`.to_i
+  MAX_PAIRS = `tput pairs`.to_i
+
+  def self.color! name, value
+    const_set "COLOR_#{name.to_s.upcase}", value
+  end
+
+  ## numeric colors
+  Curses::NUM_COLORS.times { |x| color! x, x }
+
+  if Curses::NUM_COLORS == 256
+    ## xterm 6x6x6 color cube
+    6.times { |x| 6.times { |y| 6.times { |z| color! "c#{x}#{y}#{z}", 16 + z + 6*y + 36*x } } }
+
+    ## xterm 24-shade grayscale
+    24.times { |x| color! "g#{x}", (16+6*6*6) + x }
+  end
 end
 
 module Redwood
@@ -7,12 +25,6 @@ module Redwood
 class Colormap
   @@instance = nil
 
-  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_DEFAULT]
-  NUM_COLORS = (CURSES_COLORS.size - 1) * (CURSES_COLORS.size - 1)
-
   DEFAULT_COLORS = {
     :status => { :fg => "white", :bg => "blue", :attrs => ["bold"] },
     :index_old => { :fg => "white", :bg => "default" },
@@ -68,8 +80,8 @@ class Colormap
 
   def add sym, fg, bg, attr=nil, opts={}
     raise ArgumentError, "color for #{sym} already defined" if @entries.member? sym
-    raise ArgumentError, "color '#{fg}' unknown" unless CURSES_COLORS.include? fg
-    raise ArgumentError, "color '#{bg}' unknown" unless CURSES_COLORS.include? bg
+    raise ArgumentError, "color '#{fg}' unknown" unless (-1...Curses::NUM_COLORS).include? fg
+    raise ArgumentError, "color '#{bg}' unknown" unless (-1...Curses::NUM_COLORS).include? bg
     attrs = [attr].flatten.compact
 
     @entries[sym] = [fg, bg, attrs, nil]
@@ -127,7 +139,7 @@ class Colormap
     if(cp = @color_pairs[[fg, bg]])
       ## nothing
     else ## need to get a new colorpair
-      @next_id = (@next_id + 1) % NUM_COLORS
+      @next_id = (@next_id + 1) % Curses::MAX_PAIRS
       @next_id += 1 if @next_id == 0 # 0 is always white on black
       id = @next_id
       debug "colormap: for color #{sym}, using id #{id} -> #{fg}, #{bg}"
@@ -169,7 +181,7 @@ class Colormap
       if user_colors && (ucolor = user_colors[k])
         if(ufg = ucolor[:fg])
           begin
-            fg = Curses.const_get "COLOR_#{ufg.upcase}"
+            fg = Curses.const_get "COLOR_#{ufg.to_s.upcase}"
           rescue NameError
             error ||= "Warning: there is no color named \"#{ufg}\", using fallback."
             warn "there is no color named \"#{ufg}\""
@@ -178,7 +190,7 @@ class Colormap
 
         if(ubg = ucolor[:bg])
           begin
-            bg = Curses.const_get "COLOR_#{ubg.upcase}"
+            bg = Curses.const_get "COLOR_#{ubg.to_s.upcase}"
           rescue NameError
             error ||= "Warning: there is no color named \"#{ubg}\", using fallback."
             warn "there is no color named \"#{ubg}\""
-- 
1.6.3.3

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


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

* [sup-devel] [PATCH 2/3] send color errors to the log instead of flashing
  2010-01-03 15:24 [sup-devel] [PATCHv2 1/3] support high colors in colors.yaml Rich Lane
@ 2010-01-03 15:24 ` Rich Lane
  2010-01-03 15:24   ` [sup-devel] [PATCH 3/3] add keybinding 'Oc' to reload colors Rich Lane
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Lane @ 2010-01-03 15:24 UTC (permalink / raw)
  To: sup-devel

During startup, when these errors are most likely to occur, not enough buffer
initialization has been done for BufferManager.flash to work.
---
 lib/sup/colormap.rb |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
index 71c715f..d28c550 100644
--- a/lib/sup/colormap.rb
+++ b/lib/sup/colormap.rb
@@ -213,7 +213,7 @@ class Colormap
       add symbol, fg, bg, attrs
     end
 
-    BufferManager.flash error if error
+    warn error if error
   end
 
   def self.instance; @@instance; end
-- 
1.6.3.3

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


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

* [sup-devel] [PATCH 3/3] add keybinding 'Oc' to reload colors
  2010-01-03 15:24 ` [sup-devel] [PATCH 2/3] send color errors to the log instead of flashing Rich Lane
@ 2010-01-03 15:24   ` Rich Lane
  2010-01-05 21:02     ` William Morgan
  0 siblings, 1 reply; 4+ messages in thread
From: Rich Lane @ 2010-01-03 15:24 UTC (permalink / raw)
  To: sup-devel

---
 bin/sup             |   10 ++++++++++
 lib/sup/colormap.rb |    6 +++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/bin/sup b/bin/sup
index 5571598..0716e55 100755
--- a/bin/sup
+++ b/bin/sup
@@ -96,6 +96,11 @@ global_keymap = Keymap.new do |k|
   k.add :recall_draft, "Edit most recent draft message", 'R'
   k.add :show_inbox, "Show the Inbox buffer", 'I'
   k.add :show_console, "Show the Console buffer", '~'
+
+  ## Submap for less often used keybindings
+  k.add_multi "reload (c)olors", 'O' do |kk|
+    kk.add :reload_colors, "Reload colors", 'c'
+  end
 end
 
 ## the following magic enables wide characters when used with a ruby
@@ -326,6 +331,11 @@ begin
     when :show_console
       b, new = bm.spawn_unless_exists("Console", :system => true) { ConsoleMode.new }
       b.mode.run
+    when :reload_colors
+      Colormap.reset
+      Colormap.populate_colormap
+      bm.completely_redraw_screen
+      bm.flash "reloaded colors"
     when :nothing, InputSequenceAborted
     when :redraw
       bm.completely_redraw_screen
diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
index d28c550..6f21f9a 100644
--- a/lib/sup/colormap.rb
+++ b/lib/sup/colormap.rb
@@ -68,11 +68,15 @@ class Colormap
   def initialize
     raise "only one instance can be created" if @@instance
     @@instance = self
-    @entries = {}
     @color_pairs = {[Curses::COLOR_WHITE, Curses::COLOR_BLACK] => 0}
     @users = []
     @next_id = 0
+    reset
     yield self if block_given?
+  end
+
+  def reset
+    @entries = {}
     @entries[highlight_sym(:none)] = highlight_for(Curses::COLOR_WHITE,
                                                    Curses::COLOR_BLACK,
                                                    []) + [nil]
-- 
1.6.3.3

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


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

* Re: [sup-devel] [PATCH 3/3] add keybinding 'Oc' to reload colors
  2010-01-03 15:24   ` [sup-devel] [PATCH 3/3] add keybinding 'Oc' to reload colors Rich Lane
@ 2010-01-05 21:02     ` William Morgan
  0 siblings, 0 replies; 4+ messages in thread
From: William Morgan @ 2010-01-05 21:02 UTC (permalink / raw)
  To: sup-devel

Branch colors, merged into next. Thanks!
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


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

end of thread, other threads:[~2010-01-05 21:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-03 15:24 [sup-devel] [PATCHv2 1/3] support high colors in colors.yaml Rich Lane
2010-01-03 15:24 ` [sup-devel] [PATCH 2/3] send color errors to the log instead of flashing Rich Lane
2010-01-03 15:24   ` [sup-devel] [PATCH 3/3] add keybinding 'Oc' to reload colors Rich Lane
2010-01-05 21:02     ` William Morgan

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