module Redwood
-$exception = nil
-def reporting_thread
- ::Thread.new do
- begin
- yield
- rescue Exception => e
- $exception ||= e
- raise
- end
- end
-end
-module_function :reporting_thread
-
global_keymap = Keymap.new do |k|
k.add :quit, "Quit Redwood", 'q'
k.add :help, "Show help", 'H', '?'
k.add :list_labels, "List labels", 'L'
k.add :poll, "Poll for new messages", 'P'
k.add :compose, "Compose new message", 'm'
+ k.add :recall_draft, "Edit most recent draft message", 'R'
end
def start_cursing
module_function :start_cursing, :stop_cursing
Redwood::start
-
Index.new.load
-log "loaded #{Index.size} messages from index"
if(s = Index.source_for DraftManager.source_name)
DraftManager.source = s
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 :mime_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
Logger.make_buf
bm.draw_screen
- imode.load_more_threads ibuf.content_height
+ Index.usual_sources.each do |s|
+ reporting_thread do
+ begin
+ s.connect
+ rescue SourceError => e
+ Redwood::log "Fatal error loading from #{s}: #{e.message}"
+ end
+ end if s.respond_to? :connect
+ end
+
+ imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread { sleep 1; PollManager.poll } }
- reporting_thread { sleep 3; PollManager.poll }
PollManager.start_thread
until $exception
x = global_keymap.action_for c
case x
when :quit
- break
+ break if bm.kill_all_buffers_safely
when :help
curmode = bm.focus_buf.mode
bm.spawn_unless_exists("<help for #{curmode.name}>") { HelpMode.new curmode, global_keymap }
when :roll_buffers_backwards
bm.roll_buffers_backwards
when :kill_buffer
- bm.kill_buffer bm.focus_buf if bm.focus_buf.mode.killable?
+ bm.kill_buffer_safely bm.focus_buf
when :list_buffers
bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
when :list_contacts
- bm.spawn_unless_exists("Contact List") { ContactListMode.new }
+ b = bm.spawn_unless_exists("Contact List") { ContactListMode.new }
+ b.mode.load_in_background
when :search
text = bm.ask :search, "query: "
next unless text && text !~ /^\s*$/
log "built query from #{text.inspect}: #{qobj}"
mode = SearchResultsMode.new qobj
bm.spawn "search: \"#{short_text}\"", mode
- mode.load_more_threads mode.buffer.content_height
+ mode.load_threads :num => mode.buffer.content_height
rescue Ferret::QueryParser::QueryParseException => e
bm.flash "Couldn't parse query."
end
-
when :list_labels
b = bm.spawn_unless_exists("Label List") { LabelListMode.new }
b.mode.load_in_background
when :poll
bm.raise_to_front PollManager.buffer
reporting_thread { PollManager.poll }
+ when :recall_draft
+ case Index.num_results_for :label => :draft
+ when 0
+ bm.flash "No draft messages."
+ when 1
+ m = nil
+ Index.each_id_by_date(:label => :draft) { |mid, builder| m = builder.call }
+ r = ResumeMode.new(m)
+ BufferManager.spawn "Edit message", r
+ r.edit
+ else
+ b = BufferManager.spawn_unless_exists(:draft) do
+ mode = LabelSearchResultsMode.new [:draft]
+ end
+ b.mode.load_threads :num => b.content_height
+ end
when :nothing
when :redraw
bm.completely_redraw_screen
end
end
end
- bm.kill_all_buffers
rescue Exception => e
$exception ||= e
ensure
Redwood::finish
stop_cursing
+
+ # don't ask me why, but sometimes it's necessary to print something
+ # to stderr at this point or the exception doesn't get printed.
+ # doesn't get printed. WHY?
+
+ $stderr.puts " "
end
Index.save unless $exception # TODO: think about this
if $exception
- case $exception
- when IndexError
- $stderr.puts <<EOS
-An error occurred while parsing a message from source:
- #{$exception.source}.
-Typically, this means that the source has been modified in some
-way which has rendered the messages invalid. For example, if it's
-an mbox file, you may have read or deleted messages using another
-mail client.
-
-You must rebuild the index for this source. Please run:
- sup-import --rebuild #{$exception.source}
-to correct this error.
-EOS
-#' stupid ruby-mode
- else
- $stderr.puts <<EOS
+ $stderr.puts <<EOS
----------------------------------------------------------------
I'm very sorry, but it seems that an error occurred in Sup.
Please accept my sincere apologies. If you don't mind, please
send the backtrace below and a brief report of the circumstances
-to user wmorgan-sup at site masanjin dot net so that I might
-address this problem. Thank you!
+to wmorgan-sup at masanjin dot nets so that I might address this
+problem. Thank you!
Sincerely,
William
The problem was: #{$exception.message} (error type #{$exception.class.name})
A backtrace follows:
EOS
- end
raise $exception
end