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", 'A'
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 :mime_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
75 c.add :quote_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
76 c.add :sig_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
77 c.add :quote_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
78 c.add :sig_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
79 c.add :to_me_color, Ncurses::COLOR_GREEN, Ncurses::COLOR_BLACK
80 c.add :starred_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
82 c.add :starred_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_GREEN,
84 c.add :snippet_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
85 c.add :option_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
86 c.add :tagged_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
88 c.add :draft_notification_color, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK,
92 log "initializing buffer manager"
93 bm = BufferManager.new
95 log "initializing mail index buffer"
97 ibuf = bm.spawn "inbox", imode
99 log "ready for (inter)action!"
103 imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread { sleep 1; PollManager.poll } }
105 PollManager.start_thread
109 c = Ncurses.nonblocking_getch
112 if c == Ncurses::KEY_RESIZE
115 unless bm.handle_input(c)
116 x = global_keymap.action_for c
121 curmode = bm.focus_buf.mode
122 bm.spawn_unless_exists("<help for #{curmode.name}>") { HelpMode.new curmode, global_keymap }
125 when :roll_buffers_backwards
126 bm.roll_buffers_backwards
128 bm.kill_buffer bm.focus_buf if bm.focus_buf.mode.killable?
130 bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
132 b = bm.spawn_unless_exists("Contact List") { ContactListMode.new }
133 b.mode.load_more b.content_height
135 text = bm.ask :search, "query: "
136 next unless text && text !~ /^\s*$/
139 qobj = Index.parse_user_query_string text
140 short_text = text.length < 20 ? text : text[0 ... 20] + "..."
141 log "built query from #{text.inspect}: #{qobj}"
142 mode = SearchResultsMode.new qobj
143 bm.spawn "search: \"#{short_text}\"", mode
144 mode.load_threads :num => mode.buffer.content_height
145 rescue Ferret::QueryParser::QueryParseException => e
146 bm.flash "Couldn't parse query."
150 b = bm.spawn_unless_exists("Label List") { LabelListMode.new }
151 b.mode.load_in_background
153 mode = ComposeMode.new
154 bm.spawn "New Message", mode
157 bm.raise_to_front PollManager.buffer
158 reporting_thread { PollManager.poll }
160 case Index.num_results_for :label => :draft
162 bm.flash "No draft messages."
165 Index.each_id_by_date(:label => :draft) { |mid, builder| m = builder.call }
166 r = ResumeMode.new(m)
167 BufferManager.spawn "Edit message", r
170 b = BufferManager.spawn_unless_exists(:draft) do
171 mode = LabelSearchResultsMode.new [:draft]
173 b.mode.load_threads :num => b.content_height
177 bm.completely_redraw_screen
179 bm.flash "Unknown key press '#{c.to_character}' for #{bm.focus_buf.mode.name}."
185 rescue Exception => e
191 # don't ask me why, but sometimes it's necessary to print something
192 # to stderr at this point or the exception doesn't get printed.
193 # doesn't get printed. WHY?
198 Index.save unless $exception # TODO: think about this
202 ----------------------------------------------------------------
203 I'm very sorry, but it seems that an error occurred in Sup.
204 Please accept my sincere apologies. If you don't mind, please
205 send the backtrace below and a brief report of the circumstances
206 to wmorgan-sup at masanjin dot nets so that I might address this
211 ----------------------------------------------------------------
213 The problem was: #{$exception.message} (error type #{$exception.class.name})