until Redwood::exceptions.nonempty? || $die
c = begin
Ncurses.nonblocking_getch
- rescue Interrupt => e
+ rescue Interrupt
raise if BufferManager.ask_yes_or_no "Die ungracefully now?"
BufferManager.draw_screen
nil
## decide what to do based on message labels and the operation we're performing
dothis, new_labels = case
- when (op == :restore) && restored_state[m.id] && old_m && (old_m.labels != restored_state[m.id])
- num_restored += 1
- [:update_message_state, restored_state[m.id]]
- when (op == :restore) && restored_state[m.id] && !old_m
- num_restored += 1
- m.labels = restored_state[m.id]
- :add_message
+ when (op == :restore) && restored_state[m.id]
+ if old_m && (old_m.labels != restored_state[m.id])
+ num_restored += 1
+ [:update_message_state, restored_state[m.id]]
+ elsif old_m.nil?
+ num_restored += 1
+ m.labels = restored_state[m.id]
+ :add_message
+ else
+ # labels are the same; don't do anything
+ end
when op == :discard
if old_m && (old_m.labels != m.labels)
[:update_message_state, m.labels]
else
- # don't do anything
+ # labels are the same; don't do anything
end
else
## duplicate behavior of poll mode: if index_state is non-nil, this is a newer
end
end
- module_function :rows, :cols, :curx, :nonblocking_getch, :mutex, :sync
+ ## pretends ctrl-c's are ctrl-g's
+ def safe_nonblocking_getch
+ nonblocking_getch
+ rescue Interrupt
+ KEY_CANCEL
+ end
+
+ module_function :rows, :cols, :curx, :nonblocking_getch, :safe_nonblocking_getch, :mutex, :sync
remove_const :KEY_ENTER
remove_const :KEY_CANCEL
draw_screen
until mode.done?
- c = Ncurses.nonblocking_getch
+ c = Ncurses.safe_nonblocking_getch
next unless c # getch timeout
break if c == Ncurses::KEY_CANCEL
begin
end
while true
- c = Ncurses.nonblocking_getch
+ c = Ncurses.safe_nonblocking_getch
next unless c # getch timeout
break unless tf.handle_input c # process keystroke
ret = nil
done = false
until done
- key = Ncurses.nonblocking_getch or next
+ key = Ncurses.safe_nonblocking_getch or next
if key == Ncurses::KEY_CANCEL
done = true
elsif accept.nil? || accept.empty? || accept.member?(key)
Executes before a string search is applied to the index,
returning a new search string.
Variables:
- subs: The string being searched. Be careful about shadowing:
- this variable is actually a method, so use a temporary variable
- or explicitly call self.subs; the substitutions in index.rb
- don't actually work.
+ subs: The string being searched.
EOS
def initialize dir=BASE_DIR
debug "read '#{name}' from #{fn_for(name)}"
end
rescue SystemCallError => e
- #log "disabled hook for '#{name}': #{e.message}"
+ #debug "disabled hook for '#{name}': #{e.message}"
nil
end
end
def xapian; Index.instance.instance_variable_get :@xapian; end
def ferret; Index.instance.instance_variable_get :@index; end
+ def special_methods; methods - Object.methods end
## files that won't cause problems when reloaded
## TODO expand this list / convert to blacklist
super "console"
@console = Console.new self
@binding = @console.instance_eval { binding }
- self << <<EOS
-Sup #{VERSION} console.
-Available commands: #{(@console.methods - Object.methods) * ", "}
-Ctrl-g stops evaluation; 'e' restarts it.
-
-EOS
end
def execute cmd
end
def prompt
- BufferManager.ask :console, "eval: "
+ BufferManager.ask :console, ">> "
end
def run
+ self << <<EOS
+Sup v#{VERSION} console session started.
+Available extra commands: #{(@console.special_methods) * ", "}
+Ctrl-G stops evaluation; 'e' restarts it.
+
+EOS
while true
- cmd = prompt or return
- execute cmd
+ if(cmd = prompt)
+ execute cmd
+ else
+ self << "Console session ended."
+ break
+ end
end
end
end
k.add :toggle_follow, "Toggle follow mode", 'f'
end
- def initialize buffer_name
+ ## if buffer_name is supplied, this mode will spawn a buffer
+ ## upon receiving the << message. otherwise, it will act like
+ ## a regular buffer.
+ def initialize autospawn_buffer_name=nil
@follow = true
- @buffer_name = buffer_name
+ @autospawn_buffer_name = autospawn_buffer_name
@on_kill = []
super()
end
end
def << s
- unless buffer
- BufferManager.spawn @buffer_name, self, :hidden => true, :system => true
+ if buffer.nil? && @autospawn_buffer_name
+ BufferManager.spawn @autospawn_buffer_name, self, :hidden => true, :system => true
end
s.split("\n").each { |l| super(l + "\n") } # insane. different << semantics.
MIN_DATE = Time.at 0
MAX_DATE = Time.at(2**31-1)
+ HookManager.register "custom-search", <<EOS
+Executes before a string search is applied to the index,
+returning a new search string.
+Variables:
+ subs: The string being searched.
+EOS
+
def initialize dir=BASE_DIR
super
def parse_query s
query = {}
- subs = s.gsub(/\b(to|from):(\S+)\b/) do
+ subs = HookManager.run("custom-search", :subs => s) || s
+ subs = subs.gsub(/\b(to|from):(\S+)\b/) do
field, name = $1, $2
if(p = ContactManager.contact_for(name))
[field, p.email]