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'
30 Ncurses.stdscr.keypad 1
40 module_function :start_cursing, :stop_cursing
42 Redwood::SentManager.new Redwood::SENT_FN
43 Redwood::ContactManager.new Redwood::CONTACT_FN
44 Redwood::LabelManager.new Redwood::LABEL_FN
45 Redwood::AccountManager.new $config[:accounts]
46 Redwood::DraftManager.new Redwood::DRAFT_DIR
47 Redwood::UpdateManager.new
48 Redwood::PollManager.new
51 log "loaded #{Index.size} messages from index"
53 if(s = Index.source_for DraftManager.source_name)
54 DraftManager.source = s
56 Index.add_source DraftManager.new_source
59 if(s = Index.source_for SentManager.source_name)
60 SentManager.source = s
62 Index.add_source SentManager.new_source
69 log "initializing colormap"
71 c.add :status_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLUE, Ncurses::A_BOLD
72 c.add :index_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
73 c.add :index_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK,
75 c.add :labellist_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
76 c.add :labellist_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK,
78 c.add :twiddle_color, Ncurses::COLOR_BLUE, Ncurses::COLOR_BLACK
79 c.add :label_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
80 c.add :message_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_GREEN
81 c.add :mime_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
82 c.add :quote_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
83 c.add :sig_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
84 c.add :quote_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
85 c.add :sig_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
86 c.add :to_me_color, Ncurses::COLOR_GREEN, Ncurses::COLOR_BLACK
87 c.add :starred_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
89 c.add :starred_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_GREEN,
91 c.add :snippet_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
92 c.add :option_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
93 c.add :tagged_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
95 c.add :draft_notification_color, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK,
99 log "initializing buffer manager"
100 bm = BufferManager.new
102 log "initializing mail index buffer"
103 imode = InboxMode.new
104 ibuf = bm.spawn "inbox", imode
106 log "ready for (inter)action!"
110 imode.load_more_threads ibuf.content_height
112 ::Thread.new { sleep 3; PollManager.poll }
116 c = Ncurses.nonblocking_getch
119 if c == Ncurses::KEY_RESIZE
122 unless bm.handle_input(c)
123 x = global_keymap.action_for c
128 curmode = bm.focus_buf.mode
129 bm.spawn_unless_exists("<help for #{curmode.name}>") { HelpMode.new curmode, global_keymap }
132 when :roll_buffers_backwards
133 bm.roll_buffers_backwards
135 bm.kill_buffer bm.focus_buf unless bm.focus_buf.mode.is_a? InboxMode
137 bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
139 mode = ContactListMode.new
140 bm.spawn "compose to contacts", mode
142 text = bm.ask :search, "query: "
143 next unless text && text !~ /^\s*$/
144 mode = SearchResultsMode.new text
149 text[0 ... 20] + "..."
151 bm.spawn "search: \"#{short_text}\"", mode
153 mode.load_more_threads mode.buffer.content_height
155 b = BufferManager.spawn_unless_exists("all labels") do
158 b.mode.load_in_background
160 mode = ComposeMode.new
161 bm.spawn "new message", mode
164 BufferManager.raise_to_front PollManager.buffer
168 bm.completely_redraw_screen
170 BufferManager.flash "Unknown key press '#{c.to_character}' for #{bm.focus_buf.mode.name}."
176 Redwood::LabelManager.save
177 Redwood::ContactManager.save
178 rescue Exception => e
184 Index.save unless $exception # TODO: think about this
190 An error occurred while parsing a message from source "#{$exception.source}".
191 Typically, this means that the source has been modified in some
192 way which has rendered the messages invalid. For example, if it's an mbox
193 file, you may have read or deleted messages using another client.
195 You must rebuild the index for this source. Please run:
196 sup-import --rebuild #{$exception.source}
197 to correct this error.
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 user wmorgan-sup at site masanjin dot net so that I might
207 address this problem. Thank you!
211 ----------------------------------------------------------------
213 The problem was: #{$exception.message} (error type #{$exception.class.name})