From: William Morgan Date: Wed, 20 May 2009 00:39:23 +0000 (-0400) Subject: fix display of utf8 characters so that widths are correct X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=e79b083fd8edcb88c169575ed5ff97c17f129023;p=sup fix display of utf8 characters so that widths are correct Based on a patch from Einar Lielmanis --- diff --git a/lib/sup/mode.rb b/lib/sup/mode.rb index bea46d9..6433492 100644 --- a/lib/sup/mode.rb +++ b/lib/sup/mode.rb @@ -58,7 +58,7 @@ class Mode title = "Keybindings from #{Mode.make_name klass.name}" s = < color, :highlight => opts[:highlight] - xpos += text.length + xpos += text.display_length elsif xpos < @leftcol ## partial buffer.write ln - @topline, 0, text[(@leftcol - xpos) .. -1], :color => color, :highlight => opts[:highlight] - xpos += text.length + xpos += text.display_length else buffer.write ln - @topline, xpos - @leftcol, text, :color => color, :highlight => opts[:highlight] - xpos += text.length + xpos += text.display_length end end end diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 56dcdff..66c9123 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -216,7 +216,7 @@ EOS ## let's see you do THIS in python @threads = @ts.threads.select { |t| !@hidden_threads[t] }.sort_by { |t| [t.date, t.first.id] }.reverse @size_widgets = @threads.map { |t| size_widget_for_thread t } - @size_widget_width = @size_widgets.max_of { |w| w.length } + @size_widget_width = @size_widgets.max_of { |w| w.display_length } end regen_text @@ -700,9 +700,9 @@ protected last = i == ann.length - 1 abbrev = - if cur_width + name.length > from_width + if cur_width + name.display_length > from_width name[0 ... (from_width - cur_width - 1)] + "." - elsif cur_width + name.length == from_width + elsif cur_width + name.display_length == from_width name[0 ... (from_width - cur_width)] else if last @@ -712,7 +712,7 @@ protected end end - cur_width += abbrev.length + cur_width += abbrev.display_length if last && from_width > cur_width abbrev += " " * (from_width - cur_width) diff --git a/lib/sup/util.rb b/lib/sup/util.rb index c54a2c0..02575c0 100644 --- a/lib/sup/util.rb +++ b/lib/sup/util.rb @@ -172,6 +172,8 @@ class Object end class String + def display_length; scan(/./u).size end + def camel_to_hyphy self.gsub(/([a-z])([A-Z0-9])/, '\1-\2').downcase end