commit e08f3799bc2b0e1c3b1f2d6d2b6250e000877259
parent cdd52ebb78534460115e08e8bbd9d8eb2796e8eb
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Tue, 3 Jun 2008 19:11:34 -0700
various color tweaks
- fix NME when there's no colors.yaml
- remove top-level "colors:" attribute of colors.yaml
- allow single attributes to be non-arrays
- flash at most one error
- other minor rejiggering
Diffstat:
2 files changed, 36 insertions(+), 23 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -79,7 +79,6 @@ def start_cursing
Ncurses.stdscr.keypad 1
Ncurses.curs_set 0
Ncurses.start_color
- Ncurses.use_default_colors
$cursing = true
end
@@ -142,7 +141,7 @@ begin
start_cursing
bm = BufferManager.new
- Colormap.new
+ Colormap.new.populate_colormap
log "initializing mail index buffer"
imode = InboxMode.new
diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
@@ -60,7 +60,6 @@ class Colormap
@entries[highlight_sym(:none)] = highlight_for(Curses::COLOR_WHITE,
Curses::COLOR_BLACK,
[]) + [nil]
- populate_colormap
end
def add sym, fg, bg, attr=nil, opts={}
@@ -152,43 +151,58 @@ class Colormap
## Try to use the user defined colors, in case of an error fall back
## to the default ones.
def populate_colormap
- if File.exists? Redwood::COLOR_FN
- user_colors = Redwood::load_yaml_obj Redwood::COLOR_FN
+ user_colors = if File.exists? Redwood::COLOR_FN
+ Redwood::log "loading user colors from #{Redwood::COLOR_FN}"
+ Redwood::load_yaml_obj Redwood::COLOR_FN
end
- errors = []
-
+ error = nil
Colormap::DEFAULT_COLORS.each_pair do |k, v|
fg = Curses.const_get "COLOR_#{v[:fg].upcase}"
bg = Curses.const_get "COLOR_#{v[:bg].upcase}"
- attrs = v[:attrs].map { |a| Curses.const_get "A_#{a.upcase}" } rescue attrs
-
- if(ucolor = user_colors[:colors][k])
- begin
- fg = Curses.const_get "COLOR_#{ucolor[:fg].upcase}"
- rescue NameError
- errors << "Warning: There is no color named \"#{ucolor[:fg]}\", using fallback."
- Redwood::log "Warning: There is no color named \"#{ucolor[:fg]}\""
+ attrs = v[:attrs] ? v[:attrs].map { |a| Curses.const_get "A_#{a.upcase}" } : []
+
+ if user_colors && (ucolor = user_colors[k])
+ if(ufg = ucolor[:fg])
+ begin
+ fg = Curses.const_get "COLOR_#{ufg.upcase}"
+ rescue NameError
+ error ||= "Warning: there is no color named \"#{ufg}\", using fallback."
+ Redwood::log "Warning: there is no color named \"#{ufg}\""
+ end
+ end
+
+ if(ubg = ucolor[:bg])
+ begin
+ bg = Curses.const_get "COLOR_#{ubg.upcase}"
+ rescue NameError
+ error ||= "Warning: there is no color named \"#{ubg}\", using fallback."
+ Redwood::log "Warning: there is no color named \"#{ubg}\""
+ end
end
- begin
- bg = Curses.const_get "COLOR_#{ucolor[:bg].upcase}"
- rescue NameError
- errors << "Warning: There is no color named \"#{ucolor[:bg]}\", using fallback."
- Redwood::log "Warning: There is no color named \"#{ucolor[:bg]}\""
+
+ if(uattrs = ucolor[:attrs])
+ attrs = [*uattrs].flatten.map do |a|
+ begin
+ Curses.const_get "A_#{a.upcase}"
+ rescue NameError
+ error ||= "Warning: there is no attribute named \"#{a}\", using fallback."
+ Redwood::log "Warning: there is no attribute named \"#{a}\", using fallback."
+ end
+ end
end
- attrs = ucolor[:attrs].map {|a| Curses.const_get "A_#{a.upcase}" } rescue attrs
end
symbol = (k.to_s + "_color").to_sym
add symbol, fg, bg, attrs
end
- errors.each { |e| BufferManager.flash e }
+ BufferManager.flash error if error
end
def self.instance; @@instance; end
def self.method_missing meth, *a
- Colorcolors.new unless @@instance
+ Colormap.new unless @@instance
@@instance.send meth, *a
end
end