Oh right, splitting. Yes right, makes sense. I tried your console/string, seems good, except the display_split ignores the padding request? Or did I understand this feature wrongly? I mean, it slices the string exactly where the end offset is, not by the nearest " ", space?
Well anyway, I showed it inside sup, seems to be working nicely. Here's what I did to get it to work, if anybody's interested. I'm in a rush to work, so there may be mistakes. I tried to check that everything works. Summary: - buffer.rb is patched to slice all strings according to @width, this fixes issues in inbox-mode when email subjects have wide characters. Old "hacks" were removed. - utils.rb is patched to wrap using display_slice and then looking for nearest space. if no space is found, it uses simply the original output of display_slice. display_length function defaults to the display_width With quick testing for resizing the window with different kind of test emails, I see no lost characters or text corruption. Nice, thanks.
--- buffer-old.rb 2010-05-12 00:42:50.501278238 +0300 +++ buffer.rb 2010-05-12 00:42:37.711280439 +0300 @@ -1,5 +1,6 @@ require 'etc' require 'thread' +require 'console/string' begin require 'ncursesw' @@ -129,10 +130,8 @@ @w.attrset Colormap.color_for(opts[:color] || :none, opts[:highlight]) s ||= "" 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] + s = s.display_slice(0,maxl,"") + @w.mvaddstr y, x, s unless opts[:no_fill] l = s.display_length unless l >= maxl
--- util-old.rb 2010-05-11 21:38:55.736596584 +0300 +++ util.rb 2010-05-12 00:33:16.128001053 +0300 @@ -3,6 +3,7 @@ require 'mime/types' require 'pathname' require 'set' +require 'console/string' ## time for some monkeypatching! class Lockfile def gen_lock_id @@ -177,16 +178,12 @@ end class String - ## nasty multibyte hack for ruby 1.8. if it's utf-8, split into chars using - ## the utf8 regex and count those. otherwise, use the byte length. + def display_length - if RUBY_VERSION < '1.9.1' && ($encoding == "UTF-8" || $encoding == "utf8") - scan(/./u).size - else - size - end + display_width end + def camel_to_hyphy self.gsub(/([a-z])([A-Z0-9])/, '\1-\2').downcase end @@ -270,14 +267,17 @@ def wrap len ret = [] s = self - while s.length > len - cut = s[0 ... len].rindex(/\s/) - if cut - ret << s[0 ... cut] - s = s[(cut + 1) .. -1] + while s.display_width > len + cut = s.display_slice(0,len," ") + # find the last space, since display slices it precisely + space = cut.rindex(/\s/) + space = cut.size unless space #No spaces? + cut = s[0 ... space] + ret << cut + if space != cut.size #+1 to kill the space in the beginning of next line + s = s[(cut.size + 1) .. -1] else - ret << s[0 ... len] - s = s[len .. -1] + s = s[cut.size .. -1] end end ret << s
_______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel