lib/sup/buffer.rb in sup-0.13.2.1 vs lib/sup/buffer.rb in sup-0.14.0
- old
+ new
@@ -1,5 +1,7 @@
+# encoding: utf-8
+
require 'etc'
require 'thread'
require 'ncursesw'
@@ -124,18 +126,15 @@
return if x >= @width || y >= @height
@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]
+ @w.mvaddstr y, x, s.slice_by_display_length(maxl)
end
def clear
@w.clear
end
@@ -448,11 +447,11 @@
end
end
def ask_with_completions domain, question, completions, default=nil
ask domain, question, default do |s|
- s.force_encoding 'UTF-8' if s.methods.include?(:encoding)
+ s.fix_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
@@ -465,26 +464,26 @@
[$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] }
+ prefix.fix_encoding
+ target.fix_encoding
+ completions.select { |x| x =~ /^#{Regexp::escape target}/iu }.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)
+ target.fix_encoding
prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ")
- prefix.force_encoding 'UTF-8' if prefix.methods.include?(:encoding)
+ prefix.fix_encoding
- completions.select { |x| x =~ /^#{Regexp::escape target}/i }.sort_by { |c| [ContactManager.contact_for(c) ? 0 : 1, c] }.map { |x| [prefix + x, x] }
+ completions.select { |x| x =~ /^#{Regexp::escape target}/iu }.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
answer = ask domain, question, default do |s|
@@ -493,11 +492,11 @@
name = $2.empty? ? Etc.getlogin : $2
dir = Etc.getpwnam(name).dir rescue nil
if dir
[[s.sub(full, dir), "~#{name}"]]
else
- users.select { |u| u =~ /^#{Regexp::escape name}/ }.map do |u|
+ users.select { |u| u =~ /^#{Regexp::escape name}/u }.map do |u|
[s.sub("~#{name}", "~#{u}"), "~#{u}"]
end
end
else # regular filename completion
Dir["#{s}*"].sort.map do |fn|
@@ -552,10 +551,11 @@
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
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) || Person.from_address(x) }
end
@@ -620,10 +620,10 @@
@asking = false
Ncurses.sync do
tf.deactivate
draw_screen :sync => false, :status => status, :title => title
end
- tf.value.tap { |x| x.force_encoding Encoding::UTF_8 if x && x.respond_to?(:encoding) }
+ tf.value.tap { |x| x }
end
def ask_getch question, accept=nil
raise "impossible!" if @asking