end
Thread.abort_on_exception = true # make debugging possible
+Thread.current.priority = 1 # keep ui responsive
module Redwood
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
bm.erase_flash
- action = begin
- if bm.handle_input c
+ action =
+ begin
+ if bm.handle_input c
+ :nothing
+ else
+ bm.resolve_input_with_keymap c, global_keymap
+ end
+ rescue InputSequenceAborted
:nothing
- else
- 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
def mutex; @mutex ||= Mutex.new; end
def sync &b; mutex.synchronize(&b); end
+ ## magically, this stuff seems to work now. i could swear it didn't
+ ## before. hm.
def nonblocking_getch
## INSANTIY
## it is NECESSARY to wrap Ncurses.getch in a select() otherwise all
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
def content_height; @height - 1; end
def content_width; @width; end
- def resize rows, cols
+ def resize rows, cols
return if cols == @width && rows == @height
@width = cols
@height = rows
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
query = {}
subs = HookManager.run("custom-search", :subs => s) || s
- subs = s.gsub(/\b(to|from):(\S+)\b/) do
+
+ subs = subs.gsub(/\b(to|from):(\S+)\b/) do
field, name = $1, $2
if(p = ContactManager.contact_for(name))
[field, p.email]
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
end
def initialize
- super
+ 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
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 = s.gsub(/\b(to|from):(\S+)\b/) do
++ subs = subs.gsub(/\b(to|from):(\S+)\b/) do
field, name = $1, $2
if(p = ContactManager.contact_for(name))
[field, p.email]