X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup%2Fbuffer.rb;h=6f0acf9852ea51d4b45125d035476051ed42d2f4;hb=d8776329d314e63fafc99096fe2418cb81ec6bb0;hp=4374fa82be83de4db6c9b573bdc54e6bc57eb4d1;hpb=f7b27c55c1be05de3d7952f6a7cf630142e0bbcd;p=sup diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb index 4374fa8..6f0acf9 100644 --- a/lib/sup/buffer.rb +++ b/lib/sup/buffer.rb @@ -51,8 +51,8 @@ module Redwood class InputSequenceAborted < StandardError; end class Buffer - attr_reader :mode, :x, :y, :width, :height, :title - bool_reader :dirty + attr_reader :mode, :x, :y, :width, :height, :title, :atime + bool_reader :dirty, :system bool_accessor :force_to_top def initialize window, mode, width, height, opts={} @@ -63,6 +63,8 @@ class Buffer @title = opts[:title] || "" @force_to_top = opts[:force_to_top] || false @x, @y, @width, @height = 0, 0, width, height + @atime = Time.at 0 + @system = opts[:system] || false end def content_height; @height - 1; end @@ -97,6 +99,7 @@ class Buffer @mode.draw draw_status status commit + @atime = Time.now end ## s nil means a blank line! @@ -165,6 +168,15 @@ called at least once per keystroke, so excessive computation is discouraged. Variables: the same as status-bar-text hook. Return value: a string to be used as the terminal title. +EOS + + HookManager.register "extra-contact-addresses", <" entries. + +Variables: none +Return value: an array of email address strings. EOS def initialize @@ -263,7 +275,8 @@ EOS get_status_and_title @focus_buf # must be called outside of the ncurses lock end - print "\033]2;#{title}\07" if title && @in_x + ## http://rtfm.etla.org/xterm/ctlseq.html (see Operating System Controls) + print "\033]0;#{title}\07" if title && @in_x Ncurses.mutex.lock unless opts[:sync] == false @@ -328,7 +341,7 @@ EOS ## w = Ncurses::WINDOW.new(height, width, (opts[:top] || 0), ## (opts[:left] || 0)) w = Ncurses.stdscr - b = Buffer.new w, mode, width, height, :title => realtitle, :force_to_top => (opts[:force_to_top] || false) + b = Buffer.new w, mode, width, height, :title => realtitle, :force_to_top => opts[:force_to_top], :system => opts[:system] mode.buffer = b @name_map[realtitle] = b @@ -423,7 +436,7 @@ EOS prefix, target = partial.split_on_commas_with_remainder target ||= prefix.pop || "" prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ") - completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] } + 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 @@ -455,7 +468,7 @@ EOS elsif File.directory?(answer) spawn_modal "file browser", FileBrowserMode.new(answer) else - answer + File.expand_path answer end end @@ -468,13 +481,15 @@ EOS default = default_labels.join(" ") default += " " unless default.empty? - applyable_labels = (LabelManager.applyable_labels - forbidden_labels).map { |l| LabelManager.string_for l }.sort_by { |s| s.downcase } + # here I would prefer to give more control and allow all_labels instead of + # user_defined_labels only + applyable_labels = (LabelManager.user_defined_labels - forbidden_labels).map { |l| LabelManager.string_for l }.sort_by { |s| s.downcase } answer = ask_many_with_completions domain, question, applyable_labels, default return unless answer - user_labels = answer.split(/\s+/).map { |l| l.intern } + user_labels = answer.symbolistize user_labels.each do |l| if forbidden_labels.include?(l) || LabelManager::RESERVED_LABELS.include?(l) BufferManager.flash "'#{l}' is a reserved label!" @@ -491,11 +506,12 @@ EOS 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] } - completions = (recent + contacts).flatten.uniq.sort + completions = (recent + contacts).flatten.uniq + completions += HookManager.run("extra-contact-addresses") || [] answer = BufferManager.ask_many_emails_with_completions domain, question, completions, default if answer - answer.split_on_commas.map { |x| ContactManager.contact_for(x.downcase) || PersonManager.person_for(x) } + answer.split_on_commas.map { |x| ContactManager.contact_for(x) || Person.from_address(x) } end end @@ -557,7 +573,6 @@ EOS def ask_getch question, accept=nil raise "impossible!" if @asking - @asking = true accept = accept.split(//).map { |x| x[0] } if accept @@ -570,6 +585,7 @@ EOS Ncurses.refresh end + @asking = true ret = nil done = false until done