X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fbuffer.rb;h=d85090a6db57eab56a8e230a6aeb8e3a925e6339;hb=c7aa3fcad08082fa8d897349eb8d9b98735e0445;hp=77a0e1e4685a2e87bb7695247ea50c3a8dd7c17a;hpb=a8e3572ee5ed91d205c2de0dd98cf8e610d04493;p=sup diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb index 77a0e1e..d85090a 100644 --- a/lib/sup/buffer.rb +++ b/lib/sup/buffer.rb @@ -25,13 +25,13 @@ module Ncurses 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 @@ -70,7 +70,7 @@ class Buffer 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 @@ -196,10 +196,13 @@ EOS @flash = nil @shelled = @asking = false @in_x = ENV["TERM"] =~ /(xterm|rxvt|screen)/ - - self.class.i_am_the_instance self + @sigwinch_happened = false + @sigwinch_mutex = Mutex.new end + def sigwinch_happened!; @sigwinch_mutex.synchronize { @sigwinch_happened = true } end + def sigwinch_happened?; @sigwinch_mutex.synchronize { @sigwinch_happened } end + def buffers; @name_map.to_a; end def focus_on buf @@ -267,6 +270,14 @@ EOS def completely_redraw_screen return if @shelled + ## this magic makes Ncurses get the new size of the screen + Ncurses.endwin + Ncurses.stdscr.keypad 1 + Ncurses.curs_set 0 + Ncurses.refresh + @sigwinch_mutex.synchronize { @sigwinch_happened = false } + debug "new screen size is #{Ncurses.rows} x #{Ncurses.cols}" + status, title = get_status_and_title(@focus_buf) # must be called outside of the ncurses lock Ncurses.sync do @@ -474,7 +485,7 @@ EOS end if answer - answer = + answer = if answer.empty? spawn_modal "file browser", FileBrowserMode.new elsif File.directory?(answer) @@ -490,7 +501,7 @@ EOS ## returns an array of labels def ask_for_labels domain, question, default_labels, forbidden_labels=[] default_labels = default_labels - forbidden_labels - LabelManager::RESERVED_LABELS - default = default_labels.join(" ") + default = default_labels.to_a.join(" ") default += " " unless default.empty? # here I would prefer to give more control and allow all_labels instead of @@ -501,7 +512,7 @@ EOS return unless answer - user_labels = answer.symbolistize + user_labels = answer.to_set_of_symbols user_labels.each do |l| if forbidden_labels.include?(l) || LabelManager::RESERVED_LABELS.include?(l) BufferManager.flash "'#{l}' is a reserved label!" @@ -514,7 +525,7 @@ EOS def ask_for_contacts domain, question, default_contacts=[] default = default_contacts.map { |s| s.to_s }.join(" ") default += " " unless default.empty? - + recent = Index.load_contacts(AccountManager.user_emails, :num => 10).map { |c| [c.full_address, c.email] } contacts = ContactManager.contacts.map { |c| [ContactManager.alias_for(c), c.full_address, c.email] }