7 Thread.abort_on_exception = true # make debugging possible
11 global_keymap = Keymap.new do |k|
12 k.add :quit, "Quit Redwood", 'q'
13 k.add :help, "Show help", 'H', '?'
14 k.add :roll_buffers, "Switch to next buffer", 'b'
15 # k.add :roll_buffers_backwards, "Switch to previous buffer", 'B'
16 k.add :kill_buffer, "Kill the current buffer", 'x'
17 k.add :list_buffers, "List all buffers", 'B'
18 k.add :list_contacts, "List contacts", 'C'
19 k.add :redraw, "Redraw screen", :ctrl_l
20 k.add :search, "Search messages", '/'
21 k.add :list_labels, "List labels", 'L'
22 k.add :poll, "Poll for new messages", 'P'
23 k.add :compose, "Compose new message", 'm'
24 k.add :recall_draft, "Edit most recent draft message", 'R'
31 Ncurses.stdscr.keypad 1
41 module_function :start_cursing, :stop_cursing
46 if(s = Index.source_for DraftManager.source_name)
47 DraftManager.source = s
49 Index.add_source DraftManager.new_source
52 if(s = Index.source_for SentManager.source_name)
53 SentManager.source = s
55 Index.add_source SentManager.new_source
62 log "initializing colormap"
64 c.add :status_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLUE, Ncurses::A_BOLD
65 c.add :index_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
66 c.add :index_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK,
68 c.add :labellist_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
69 c.add :labellist_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK,
71 c.add :twiddle_color, Ncurses::COLOR_BLUE, Ncurses::COLOR_BLACK
72 c.add :label_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
73 c.add :message_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_GREEN
74 c.add :alternate_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_BLUE
75 c.add :missing_message_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_RED
76 c.add :mime_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
77 c.add :quote_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
78 c.add :sig_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
79 c.add :quote_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
80 c.add :sig_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
81 c.add :to_me_color, Ncurses::COLOR_GREEN, Ncurses::COLOR_BLACK
82 c.add :starred_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
84 c.add :starred_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_GREEN,
86 c.add :snippet_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
87 c.add :option_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
88 c.add :tagged_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
90 c.add :draft_notification_color, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK,
94 log "initializing buffer manager"
95 bm = BufferManager.new
97 log "initializing mail index buffer"
99 ibuf = bm.spawn "inbox", imode
101 log "ready for (inter)action!"
105 Index.usual_sources.each do |s|
109 rescue SourceError => e
110 Redwood::log "Fatal error loading from #{s}: #{e.message}"
112 end if s.respond_to? :connect
115 imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread { sleep 1; PollManager.poll } }
117 PollManager.start_thread
121 c = Ncurses.nonblocking_getch
124 if c == Ncurses::KEY_RESIZE
127 unless bm.handle_input(c)
128 x = global_keymap.action_for c
131 break if bm.kill_all_buffers_safely
133 curmode = bm.focus_buf.mode
134 bm.spawn_unless_exists("<help for #{curmode.name}>") { HelpMode.new curmode, global_keymap }
137 when :roll_buffers_backwards
138 bm.roll_buffers_backwards
140 bm.kill_buffer_safely bm.focus_buf
142 bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
144 b = bm.spawn_unless_exists("Contact List") { ContactListMode.new }
145 b.mode.load_in_background
147 text = bm.ask :search, "query: "
148 next unless text && text !~ /^\s*$/
151 qobj = Index.parse_user_query_string text
152 short_text = text.length < 20 ? text : text[0 ... 20] + "..."
153 log "built query from #{text.inspect}: #{qobj}"
154 mode = SearchResultsMode.new qobj
155 bm.spawn "search: \"#{short_text}\"", mode
156 mode.load_threads :num => mode.buffer.content_height
157 rescue Ferret::QueryParser::QueryParseException => e
158 bm.flash "Couldn't parse query."
161 b = bm.spawn_unless_exists("Label List") { LabelListMode.new }
162 b.mode.load_in_background
164 mode = ComposeMode.new
165 bm.spawn "New Message", mode
168 bm.raise_to_front PollManager.buffer
169 reporting_thread { PollManager.poll }
171 case Index.num_results_for :label => :draft
173 bm.flash "No draft messages."
176 Index.each_id_by_date(:label => :draft) { |mid, builder| m = builder.call }
177 r = ResumeMode.new(m)
178 BufferManager.spawn "Edit message", r
181 b = BufferManager.spawn_unless_exists(:draft) do
182 mode = LabelSearchResultsMode.new [:draft]
184 b.mode.load_threads :num => b.content_height
188 bm.completely_redraw_screen
190 bm.flash "Unknown key press '#{c.to_character}' for #{bm.focus_buf.mode.name}."
195 rescue Exception => e
201 # don't ask me why, but sometimes it's necessary to print something
202 # to stderr at this point or the exception doesn't get printed.
203 # doesn't get printed. WHY?
208 Index.save unless $exception # TODO: think about this
212 ----------------------------------------------------------------
213 I'm very sorry, but it seems that an error occurred in Sup.
214 Please accept my sincere apologies. If you don't mind, please
215 send the backtrace below and a brief report of the circumstances
216 to wmorgan-sup at masanjin dot nets so that I might address this
221 ----------------------------------------------------------------
223 The problem was: #{$exception.message} (error type #{$exception.class.name})