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={}
@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
@mode.draw
draw_status status
commit
+ @atime = Time.now
end
## s nil means a blank line!
@w.attrset Colormap.color_for(opts[:color] || :none, opts[:highlight])
s ||= ""
- maxl = @width - x
- @w.mvaddstr y, x, s[0 ... maxl]
- unless s.length >= maxl || opts[:no_fill]
- @w.mvaddstr(y, x + s.length, " " * (maxl - s.length))
+ maxl = @width - x # maximum display width width
+ stringl = maxl # string "length"
+ ## 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
## 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
end
if answer
- answer =
+ answer =
if answer.empty?
spawn_modal "file browser", FileBrowserMode.new
elsif File.directory?(answer)
## 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
return unless answer
- user_labels = answer.split(/\s+/).map { |l| l.intern }
+ 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!"
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] }
answer = BufferManager.ask_many_emails_with_completions domain, question, completions, default
if answer
- answer.split_on_commas.map { |x| ContactManager.contact_for(x) || PersonManager.person_for(x) }
+ answer.split_on_commas.map { |x| ContactManager.contact_for(x) || Person.from_address(x) }
end
end
Ncurses.sync do
Ncurses.endwin
system command
+ Ncurses.stdscr.keypad 1
Ncurses.refresh
Ncurses.curs_set 0
end