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 :alternate_starred_patina_color, Ncurses::COLOR_YELLOW,
87 Ncurses::COLOR_BLUE, Ncurses::A_BOLD
88 c.add :snippet_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
89 c.add :option_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
90 c.add :tagged_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
92 c.add :draft_notification_color, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK,
96 log "initializing buffer manager"
97 bm = BufferManager.new
99 log "initializing mail index buffer"
100 imode = InboxMode.new
101 ibuf = bm.spawn "inbox", imode
103 log "ready for interaction!"
109 Index.usual_sources.each { |s| s.check }
111 # do nothing! we'll report it at the next step
113 Redwood::report_broken_sources
115 Index.usual_sources.each do |s|
119 rescue SourceError => e
120 Redwood::log "fatal error loading from #{s}: #{e.message}"
122 end if s.respond_to? :connect
125 imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread { sleep 1; PollManager.poll } }
127 PollManager.start_thread
131 c = Ncurses.nonblocking_getch
134 if c == Ncurses::KEY_RESIZE
137 unless bm.handle_input(c)
138 x = global_keymap.action_for c
141 break if bm.kill_all_buffers_safely
143 curmode = bm.focus_buf.mode
144 bm.spawn_unless_exists("<help for #{curmode.name}>") { HelpMode.new curmode, global_keymap }
147 when :roll_buffers_backwards
148 bm.roll_buffers_backwards
150 bm.kill_buffer_safely bm.focus_buf
152 bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
154 b = bm.spawn_unless_exists("Contact List") { ContactListMode.new }
155 b.mode.load_in_background
157 text = bm.ask :search, "query: "
158 next unless text && text !~ /^\s*$/
161 qobj = Index.parse_user_query_string text
162 short_text = text.length < 20 ? text : text[0 ... 20] + "..."
163 log "built query from #{text.inspect}: #{qobj}"
164 mode = SearchResultsMode.new qobj
165 bm.spawn "search: \"#{short_text}\"", mode
166 mode.load_threads :num => mode.buffer.content_height
167 rescue Ferret::QueryParser::QueryParseException => e
168 bm.flash "Couldn't parse query."
171 b = bm.spawn_unless_exists("Label List") { LabelListMode.new }
172 b.mode.load_in_background
174 mode = ComposeMode.new
175 bm.spawn "New Message", mode
178 bm.raise_to_front PollManager.buffer
179 reporting_thread { PollManager.poll }
181 case Index.num_results_for :label => :draft
183 bm.flash "No draft messages."
186 Index.each_id_by_date(:label => :draft) { |mid, builder| m = builder.call }
187 r = ResumeMode.new(m)
188 BufferManager.spawn "Edit message", r
191 b = BufferManager.spawn_unless_exists(:draft) do
192 mode = LabelSearchResultsMode.new [:draft]
194 b.mode.load_threads :num => b.content_height
198 bm.completely_redraw_screen
200 bm.flash "Unknown key press '#{c.to_character}' for #{bm.focus_buf.mode.name}."
205 rescue Exception => e
211 Redwood::log "oh crap, an exception"
213 Redwood::log "good night, sweet prince!"
217 Index.save unless $exception # TODO: think about this
221 ----------------------------------------------------------------
222 I'm very sorry, but it seems that an error occurred in Sup.
223 Please accept my sincere apologies. If you don't mind, please
224 send the backtrace below and a brief report of the circumstances
225 to wmorgan-sup at masanjin dot nets so that I might address this
230 ----------------------------------------------------------------
232 The problem was: #{$exception.message} (error type #{$exception.class.name})