bin/sup in sup-0.6 vs bin/sup in sup-0.7
- old
+ new
@@ -6,11 +6,11 @@
require 'fileutils'
require 'trollop'
require 'fastthread'
require "sup"
-BIN_VERSION = "0.6"
+BIN_VERSION = "0.7"
unless Redwood::VERSION == BIN_VERSION
$stderr.puts <<EOS
Error: version mismatch!
@@ -43,10 +43,18 @@
Executes at startup
No variables.
No return value.
EOS
+Redwood::HookManager.register "shutdown", <<EOS
+Executes when sup is shutting down. May be run when sup is crashing,
+so don\'t do anything too important. Run before the label, contacts,
+and people are saved.
+No variables.
+No return value.
+EOS
+
if $opts[:list_hooks]
Redwood::HookManager.print_hooks
exit
end
@@ -55,18 +63,19 @@
module Redwood
global_keymap = Keymap.new do |k|
k.add :quit_ask, "Quit Sup, but ask first", 'q'
k.add :quit_now, "Quit Sup immediately", 'Q'
- k.add :help, "Show help", 'H', '?'
+ k.add :help, "Show help", '?'
k.add :roll_buffers, "Switch to next buffer", 'b'
# k.add :roll_buffers_backwards, "Switch to previous buffer", 'B'
k.add :kill_buffer, "Kill the current buffer", 'x'
k.add :list_buffers, "List all buffers", 'B'
k.add :list_contacts, "List contacts", 'C'
k.add :redraw, "Redraw screen", :ctrl_l
k.add :search, "Search all messages", '\\', 'F'
+ k.add :search_unread, "Show all unread messages", 'U'
k.add :list_labels, "List labels", 'L'
k.add :poll, "Poll for new messages", 'P'
k.add :compose, "Compose new message", 'm', 'c'
k.add :nothing, "Do nothing", :ctrl_g
k.add :recall_draft, "Edit most recent draft message", 'R'
@@ -99,11 +108,11 @@
h = HighLine.new
h.wrap_at = :auto
h.say Index.fancy_lock_error_message_for(e)
case h.ask("Should I ask that process to kill itself? ")
- when /^\s*y\s*$/i
+ when /^\s*y(es)?\s*$/i
h.say "Ok, suggesting seppuku..."
FileUtils.touch Redwood::SUICIDE_FN
sleep SuicideManager::DELAY * 2
FileUtils.rm_f Redwood::SUICIDE_FN
h.say "Let's try that again."
@@ -178,11 +187,20 @@
if $opts[:search]
SearchResultsMode.spawn_from_query $opts[:search]
end
until Redwood::exceptions.nonempty? || SuicideManager.die?
- c = Ncurses.nonblocking_getch
+ c =
+ begin
+ Ncurses.nonblocking_getch
+ rescue Exception => e
+ if e.is_a?(Interrupt)
+ raise if BufferManager.ask_yes_or_no("Die ungracefully now?")
+ bm.draw_screen
+ nil
+ end
+ end
next unless c
bm.erase_flash
action =
begin
@@ -192,11 +210,10 @@
bm.resolve_input_with_keymap c, global_keymap
end
rescue InputSequenceAborted
:nothing
end
-
case action
when :quit_now
break if bm.kill_all_buffers_safely
when :quit_ask
if bm.ask_yes_or_no "Really quit?"
@@ -218,10 +235,12 @@
b.mode.load_in_background if new
when :search
query = BufferManager.ask :search, "search all messages: "
next unless query && query !~ /^\s*$/
SearchResultsMode.spawn_from_query query
+ when :search_unread
+ SearchResultsMode.spawn_from_query "is:unread"
when :list_labels
labels = LabelManager.listable_labels.map { |l| LabelManager.string_for l }
user_label = bm.ask_with_completions :label, "Show threads with label (enter for listing): ", labels
unless user_label.nil?
if user_label.empty?
@@ -265,9 +284,11 @@
unless $opts[:no_threads]
PollManager.stop if PollManager.instantiated?
SuicideManager.stop if PollManager.instantiated?
Index.stop_lock_update_thread
end
+
+ HookManager.run "shutdown"
Redwood::finish
stop_cursing
Redwood::log "stopped cursing"