lib/sup/buffer.rb in sup-0.11 vs lib/sup/buffer.rb in sup-0.12

- old
+ new

@@ -98,11 +98,11 @@ mode.resize rows, cols end def redraw status if @dirty - draw status + draw status else draw_status status end commit @@ -128,19 +128,17 @@ @w.attrset Colormap.color_for(opts[:color] || :none, opts[:highlight]) s ||= "" maxl = @width - x # maximum display width width stringl = maxl # string "length" + + # fill up the line with blanks to overwrite old screen contents + @w.mvaddstr y, x, " " * maxl unless opts[:no_fill] + ## the next horribleness is thanks to ruby's lack of widechar support stringl += 1 while stringl < s.length && s[0 ... stringl].display_length < maxl @w.mvaddstr y, x, s[0 ... stringl] - unless opts[:no_fill] - l = s.display_length - unless l >= maxl - @w.mvaddstr(y, x + l, " " * (maxl - l)) - end - end end def clear @w.clear end @@ -226,11 +224,11 @@ def buffers; @name_map.to_a; end def shelled?; @shelled; end def focus_on buf return unless @buffers.member? buf - return if buf == @focus_buf + return if buf == @focus_buf @focus_buf.blur if @focus_buf @focus_buf = buf @focus_buf.focus end @@ -352,11 +350,11 @@ ## if the named buffer already exists, pops it to the front without ## calling the block. otherwise, gets the mode from the block and ## creates a new buffer. returns two things: the buffer, and a boolean ## indicating whether it's a new buffer or not. def spawn_unless_exists title, opts={} - new = + new = if @name_map.member? title raise_to_front @name_map[title] unless opts[:hidden] false else mode = yield @@ -453,35 +451,42 @@ end end def ask_with_completions domain, question, completions, default=nil ask domain, question, default do |s| - completions.select { |x| x =~ /^#{Regexp::escape s}/i }.map { |x| [x, x] } + s.force_encoding 'UTF-8' if s.methods.include?(:encoding) + completions.select { |x| x =~ /^#{Regexp::escape s}/iu }.map { |x| [x, x] } end end def ask_many_with_completions domain, question, completions, default=nil ask domain, question, default do |partial| - prefix, target = + prefix, target = case partial when /^\s*$/ ["", ""] when /^(.*\s+)?(.*?)$/ [$1 || "", $2] else raise "william screwed up completion: #{partial.inspect}" end + prefix.force_encoding 'UTF-8' if prefix.methods.include?(:encoding) + target.force_encoding 'UTF-8' if target.methods.include?(:encoding) completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] } end end def ask_many_emails_with_completions domain, question, completions, default=nil ask domain, question, default do |partial| prefix, target = partial.split_on_commas_with_remainder target ||= prefix.pop || "" + target.force_encoding 'UTF-8' if target.methods.include?(:encoding) + prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ") + prefix.force_encoding 'UTF-8' if prefix.methods.include?(:encoding) + completions.select { |x| x =~ /^#{Regexp::escape target}/i }.sort_by { |c| [ContactManager.contact_for(c) ? 0 : 1, c] }.map { |x| [prefix + x, x] } end end def ask_for_filename domain, question, default=nil, allow_directory=false @@ -557,10 +562,17 @@ if answer answer.split_on_commas.map { |x| ContactManager.contact_for(x) || Person.from_address(x) } end end + def ask_for_account domain, question + completions = AccountManager.user_emails + answer = BufferManager.ask_many_emails_with_completions domain, question, completions, "" + answer = AccountManager.default_account.email if answer == "" + AccountManager.account_for Person.from_address(answer).email if answer + end + ## for simplicitly, we always place the question at the very bottom of the ## screen def ask domain, question, default=nil, &block raise "impossible!" if @asking @asking = true @@ -584,11 +596,11 @@ next unless c # getch timeout break unless tf.handle_input c # process keystroke if tf.new_completions? kill_buffer completion_buf if completion_buf - + shorts = tf.completions.map { |full, short| short } prefix_len = shorts.shared_prefix.length mode = CompletionMode.new shorts, :header => "Possible completions for \"#{tf.value}\": ", :prefix_len => prefix_len completion_buf = spawn "<completions>", mode, :height => 10 @@ -601,11 +613,11 @@ tf.position_cursor end Ncurses.sync { Ncurses.refresh } end - + kill_buffer completion_buf if completion_buf @dirty = true @asking = false Ncurses.sync do @@ -682,16 +694,16 @@ action end def minibuf_lines @minibuf_mutex.synchronize do - [(@flash ? 1 : 0) + + [(@flash ? 1 : 0) + (@asking ? 1 : 0) + @minibuf_stack.compact.size, 1].max end end - + def draw_minibuf opts={} m = nil @minibuf_mutex.synchronize do m = @minibuf_stack.compact m << @flash if @flash @@ -789,10 +801,10 @@ :status => buf.mode.status } statusbar_text = HookManager.run("status-bar-text", opts) || default_status_bar(buf) term_title_text = HookManager.run("terminal-title-text", opts) || default_terminal_title(buf) - + [statusbar_text, term_title_text] end def users unless @users