[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sup-devel] [PATCH] dont restrict colors to those in Colormap::DEFAULT_COLORS
This is necessary for user-created highlight colors. A side effect is that
invalid color names now default to ugly red/green instead of what was in
DEFAULT_COLORS, which seems more useful for debugging colormap problems. Also
remove the redundant warnings.
---
lib/sup/colormap.rb | 58 ++++++++++++++++++--------------------------------
1 files changed, 21 insertions(+), 37 deletions(-)
diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
index aeb3818..7de48db 100644
--- a/lib/sup/colormap.rb
+++ b/lib/sup/colormap.rb
@@ -183,51 +183,35 @@ class Colormap
Redwood::load_yaml_obj Redwood::COLOR_FN
end
- 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] ? 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.to_s.upcase}"
- rescue NameError
- error ||= "Warning: there is no color named \"#{ufg}\", using fallback."
- warn "there is no color named \"#{ufg}\""
- end
- end
+ Colormap::DEFAULT_COLORS.merge(user_colors||{}).each_pair do |k, v|
+ fg = begin
+ Curses.const_get "COLOR_#{v[:fg].to_s.upcase}"
+ rescue NameError
+ warn "there is no color named \"#{v[:fg]}\""
+ Curses::COLOR_GREEN
+ end
- if(ubg = ucolor[:bg])
- begin
- 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}\""
- end
- end
+ bg = begin
+ Curses.const_get "COLOR_#{v[:bg].to_s.upcase}"
+ rescue NameError
+ warn "there is no color named \"#{v[:bg]}\""
+ Curses::COLOR_RED
+ end
- 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."
- warn "there is no attribute named \"#{a}\", using fallback."
- end
- end
+ attrs = (v[:attrs]||[]).map do |a|
+ begin
+ Curses.const_get "A_#{a.upcase}"
+ rescue NameError
+ warn "there is no attribute named \"#{a}\", using fallback."
+ nil
end
- end
+ end.compact
- highlight = ucolor[:highlight] || v[:highlight]
- highlight_symbol = highlight ? :"#{highlight}_color" : nil
+ highlight_symbol = v[:highlight] ? :"#{v[:highlight]}_color" : nil
symbol = (k.to_s + "_color").to_sym
add symbol, fg, bg, attrs, highlight_symbol
end
-
- 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