From: William Morgan Date: Thu, 6 Aug 2009 18:30:12 +0000 (-0400) Subject: Merge branch 'ncurses-fixes' into next X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=67986d7c0e66054a654edeb7e383e66a45e861bf;p=sup Merge branch 'ncurses-fixes' into next Conflicts: bin/sup lib/sup/buffer.rb --- 67986d7c0e66054a654edeb7e383e66a45e861bf diff --cc bin/sup index 1febefd,2d5de67..0e2260c --- a/bin/sup +++ b/bin/sup @@@ -218,29 -221,39 +221,40 @@@ begi end until Redwood::exceptions.nonempty? || SuicideManager.die? - 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 + c = begin + Ncurses.nonblocking_getch + rescue Interrupt => e + raise if BufferManager.ask_yes_or_no "Die ungracefully now?" + BufferManager.draw_screen + nil + end + + if c.nil? + if BufferManager.sigwinch_happened? + Redwood::log "redrawing screen on sigwinch" + BufferManager.completely_redraw_screen + end + next + end + + if c == 410 + ## this is ncurses's way of telling us it's detected a refresh. + ## since we have our own sigwinch handler, we don't do anything. + next + end + 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 diff --cc lib/sup/buffer.rb index 5f52d1d,5881feb..b3a256f --- a/lib/sup/buffer.rb +++ b/lib/sup/buffer.rb @@@ -25,13 -25,13 +25,15 @@@ module Ncurse 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 - if IO.select([$stdin], nil, nil, 1) - Ncurses.getch - else - nil + ## INSANTIY + ## it is NECESSARY to wrap Ncurses.getch in a select() otherwise all + ## background threads will be BLOCKED. (except in very modern versions + ## of libncurses-ruby. the current one on ubuntu seems to work well.) + if IO.select([$stdin], nil, nil, 0.5) + c = Ncurses.getch end end