Ncurses.stdscr.keypad 1
Ncurses.curs_set 0
Ncurses.start_color
+ Ncurses.use_default_colors
$cursing = true
end
log "starting curses"
start_cursing
- Colormap.new do |c|
- c.add :status_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLUE, Ncurses::A_BOLD
- c.add :index_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
- c.add :index_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK,
- Ncurses::A_BOLD
- c.add :index_starred_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
- Ncurses::A_BOLD
- c.add :index_draft_color, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK,
- Ncurses::A_BOLD
- c.add :labellist_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
- c.add :labellist_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK,
- Ncurses::A_BOLD
- c.add :twiddle_color, Ncurses::COLOR_BLUE, Ncurses::COLOR_BLACK
- c.add :label_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
- c.add :message_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_GREEN
- c.add :alternate_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_BLUE
- c.add :missing_message_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_RED
- c.add :attachment_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
- c.add :cryptosig_valid_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK, Ncurses::A_BOLD
- c.add :cryptosig_unknown_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
- c.add :cryptosig_invalid_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_RED, Ncurses::A_BOLD
- c.add :generic_notice_patina_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
- c.add :quote_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
- c.add :sig_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
- c.add :quote_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
- c.add :sig_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
- c.add :to_me_color, Ncurses::COLOR_GREEN, Ncurses::COLOR_BLACK
- c.add :starred_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
- Ncurses::A_BOLD
- c.add :starred_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_GREEN,
- Ncurses::A_BOLD
- c.add :alternate_starred_patina_color, Ncurses::COLOR_YELLOW,
- Ncurses::COLOR_BLUE, Ncurses::A_BOLD
- c.add :snippet_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
- c.add :option_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
- c.add :tagged_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
- Ncurses::A_BOLD
- c.add :draft_notification_color, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK,
- Ncurses::A_BOLD
- c.add :completion_character_color, Ncurses::COLOR_WHITE,
- Ncurses::COLOR_BLACK, Ncurses::A_BOLD
- c.add :horizontal_selector_selected_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK, Ncurses::A_BOLD
- c.add :horizontal_selector_unselected_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
- c.add :search_highlight_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_YELLOW, Ncurses::A_BOLD, :highlight => :search_highlight_color
- end
-
bm = BufferManager.new
+ Colormap.new
log "initializing mail index buffer"
imode = InboxMode.new
+module Curses
+ COLOR_DEFAULT = -1
+end
+
module Redwood
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
+
+ DEFAULT_COLORS = {
+ :status => { :fg => "white", :bg => "blue", :attrs => ["bold"] },
+ :index_old => { :fg => "white", :bg => "black" },
+ :index_new => { :fg => "white", :bg => "black", :attrs => ["bold"] },
+ :index_starred => { :fg => "yellow", :bg => "black", :attrs => ["bold"] },
+ :index_draft => { :fg => "red", :bg => "black", :attrs => ["bold"] },
+ :labellist_old => { :fg => "white", :bg => "black" },
+ :labellist_new => { :fg => "white", :bg => "black", :attrs => ["bold"] },
+ :twiddle => { :fg => "blue", :bg => "black" },
+ :label => { :fg => "yellow", :bg => "black" },
+ :message_patina => { :fg => "black", :bg => "green" },
+ :alternate_patina => { :fg => "black", :bg => "blue" },
+ :missing_message => { :fg => "black", :bg => "red" },
+ :attachment => { :fg => "cyan", :bg => "black" },
+ :cryptosig_valid => { :fg => "yellow", :bg => "black", :attrs => ["bold"] },
+ :cryptosig_unknown => { :fg => "cyan", :bg => "black" },
+ :cryptosig_invalid => { :fg => "yellow", :bg => "red", :attrs => ["bold"] },
+ :generic_notice_patina => { :fg => "cyan", :bg => "black" },
+ :quote_patina => { :fg => "yellow", :bg => "black" },
+ :sig_patina => { :fg => "yellow", :bg => "black" },
+ :quote => { :fg => "yellow", :bg => "black" },
+ :sig => { :fg => "yellow", :bg => "black" },
+ :to_me => { :fg => "green", :bg => "black" },
+ :starred => { :fg => "yellow", :bg => "black", :attrs => ["bold"] },
+ :starred_patina => { :fg => "yellow", :bg => "green", :attrs => ["bold"] },
+ :alternate_starred_patina => { :fg => "yellow", :bg => "blue", :attrs => ["bold"] },
+ :snippet => { :fg => "cyan", :bg => "black" },
+ :option => { :fg => "white", :bg => "black" },
+ :tagged => { :fg => "red", :bg => "black", :attrs => ["bold"] },
+ :draft_notification => { :fg => "red", :bg => "black", :attrs => ["bold"] },
+ :completion_character => { :fg => "white", :bg => "black", :attrs => ["bold"] },
+ :horizontal_selector_selected => { :fg => "yellow", :bg => "black", :attrs => ["bold"] },
+ :horizontal_selector_unselected => { :fg => "cyan", :bg => "black" },
+ :search_highlight => { :fg => "black", :bg => "yellow", :attrs => ["bold"] }
+ }
def initialize
raise "only one instance can be created" if @@instance
@entries[highlight_sym(:none)] = highlight_for(Curses::COLOR_WHITE,
Curses::COLOR_BLACK,
[]) + [nil]
+ populate_colormap
end
def add sym, fg, bg, attr=nil, opts={}
color
end
+ ## 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
+ end
+
+ errors = []
+
+ 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]}\""
+ 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]}\""
+ 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 }
+ end
+
def self.instance; @@instance; end
def self.method_missing meth, *a
Colorcolors.new unless @@instance