]> git.cworth.org Git - sup/commitdiff
yet another utf8 bugfix: fix string subsetting
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Sun, 31 May 2009 15:58:16 +0000 (08:58 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Sun, 31 May 2009 15:59:09 +0000 (08:59 -0700)
... with a HORRIBLE SLOW HACK!

lib/sup/buffer.rb

index 5672e3d6748663ad5f5db4833c799e23eb9fd83f..8eedf9697c26f1aa94c8a6769aa4f7c9e5752406 100644 (file)
@@ -108,11 +108,16 @@ class Buffer
 
     @w.attrset Colormap.color_for(opts[:color] || :none, opts[:highlight])
     s ||= ""
-    maxl = @width - x
-    @w.mvaddstr y, x, s[0 ... maxl]
-    l = s.display_length
-    unless l >= maxl || opts[:no_fill]
-      @w.mvaddstr(y, x + l, " " * (maxl - l))
+    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