7 Thread.abort_on_exception = true # make debugging possible
22 module_function :reporting_thread
24 global_keymap = Keymap.new do |k|
25 k.add :quit, "Quit Redwood", 'q'
26 k.add :help, "Show help", 'H', '?'
27 k.add :roll_buffers, "Switch to next buffer", 'b'
28 k.add :roll_buffers_backwards, "Switch to previous buffer", 'B'
29 k.add :kill_buffer, "Kill the current buffer", 'x'
30 k.add :list_buffers, "List all buffers", 'A'
31 k.add :list_contacts, "List contacts", 'C'
32 k.add :redraw, "Redraw screen", :ctrl_l
33 k.add :search, "Search messages", '/'
34 k.add :list_labels, "List labels", 'L'
35 k.add :poll, "Poll for new messages", 'P'
36 k.add :compose, "Compose new message", 'm'
43 Ncurses.stdscr.keypad 1
53 module_function :start_cursing, :stop_cursing
58 log "loaded #{Index.size} messages from index"
60 if(s = Index.source_for DraftManager.source_name)
61 DraftManager.source = s
63 Index.add_source DraftManager.new_source
66 if(s = Index.source_for SentManager.source_name)
67 SentManager.source = s
69 Index.add_source SentManager.new_source
76 log "initializing colormap"
78 c.add :status_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLUE, Ncurses::A_BOLD
79 c.add :index_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
80 c.add :index_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK,
82 c.add :labellist_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
83 c.add :labellist_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK,
85 c.add :twiddle_color, Ncurses::COLOR_BLUE, Ncurses::COLOR_BLACK
86 c.add :label_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
87 c.add :message_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_GREEN
88 c.add :mime_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
89 c.add :quote_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
90 c.add :sig_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
91 c.add :quote_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
92 c.add :sig_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
93 c.add :to_me_color, Ncurses::COLOR_GREEN, Ncurses::COLOR_BLACK
94 c.add :starred_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
96 c.add :starred_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_GREEN,
98 c.add :snippet_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
99 c.add :option_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
100 c.add :tagged_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
102 c.add :draft_notification_color, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK,
106 log "initializing buffer manager"
107 bm = BufferManager.new
109 log "initializing mail index buffer"
110 imode = InboxMode.new
111 ibuf = bm.spawn "inbox", imode
113 log "ready for (inter)action!"
117 imode.load_more_threads ibuf.content_height
119 reporting_thread { sleep 3; PollManager.poll }
120 PollManager.start_thread
124 c = Ncurses.nonblocking_getch
127 if c == Ncurses::KEY_RESIZE
130 unless bm.handle_input(c)
131 x = global_keymap.action_for c
136 curmode = bm.focus_buf.mode
137 bm.spawn_unless_exists("<help for #{curmode.name}>") { HelpMode.new curmode, global_keymap }
140 when :roll_buffers_backwards
141 bm.roll_buffers_backwards
143 bm.kill_buffer bm.focus_buf if bm.focus_buf.mode.killable?
145 bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
147 bm.spawn_unless_exists("Contact List") { ContactListMode.new }
149 text = bm.ask :search, "query: "
150 next unless text && text !~ /^\s*$/
153 qobj = Index.parse_user_query_string text
154 short_text = text.length < 20 ? text : text[0 ... 20] + "..."
155 log "built query from #{text.inspect}: #{qobj}"
156 mode = SearchResultsMode.new qobj
157 bm.spawn "search: \"#{short_text}\"", mode
158 mode.load_more_threads mode.buffer.content_height
159 rescue Ferret::QueryParser::QueryParseException => e
160 bm.flash "Couldn't parse query."
164 b = bm.spawn_unless_exists("Label List") { LabelListMode.new }
165 b.mode.load_in_background
167 mode = ComposeMode.new
168 bm.spawn "New Message", mode
171 bm.raise_to_front PollManager.buffer
172 reporting_thread { PollManager.poll }
175 bm.completely_redraw_screen
177 bm.flash "Unknown key press '#{c.to_character}' for #{bm.focus_buf.mode.name}."
183 rescue Exception => e
190 Index.save unless $exception # TODO: think about this
196 An error occurred while parsing a message from source:
197 #{$exception.source}.
198 Typically, this means that the source has been modified in some
199 way which has rendered the messages invalid. For example, if it's
200 an mbox file, you may have read or deleted messages using another
203 You must rebuild the index for this source. Please run:
204 sup-import --rebuild #{$exception.source}
205 to correct this error.
210 ----------------------------------------------------------------
211 I'm very sorry, but it seems that an error occurred in Sup.
212 Please accept my sincere apologies. If you don't mind, please
213 send the backtrace below and a brief report of the circumstances
214 to user wmorgan-sup at site masanjin dot net so that I might
215 address this problem. Thank you!
219 ----------------------------------------------------------------
221 The problem was: #{$exception.message} (error type #{$exception.class.name})