Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Matti Eiden <snaipperi@gmail.com>
To: Sup developer discussion <sup-devel@rubyforge.org>
Subject: Re: [sup-devel] Arch utf8 vs UTF-8 fix and wide character support
Date: Wed, 12 May 2010 00:51:20 +0300	[thread overview]
Message-ID: <t2s6242182a1005111451uc2781ca0rcd97dbf6d3146684@mail.gmail.com> (raw)
In-Reply-To: <1273605454-sup-2267@masanjin.net>

[-- Attachment #1: Type: text/plain, Size: 1024 bytes --]

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.

[-- Attachment #2: console-sup-buffer.patch --]
[-- Type: text/x-patch, Size: 755 bytes --]

--- 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

[-- Attachment #3: console-sup-util.patch --]
[-- Type: text/x-patch, Size: 1450 bytes --]

--- 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

[-- Attachment #4: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

  reply	other threads:[~2010-05-11 21:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <y2j6242182a1005061059w5e32fb54vd10ccfd7e4a1911e@mail.gmail.com>
2010-05-06 18:02 ` Matti Eiden
2010-05-07 16:46   ` Rich Lane
2010-05-11 18:50     ` Matti Eiden
2010-05-11 19:19       ` William Morgan
2010-05-11 21:51         ` Matti Eiden [this message]
2010-05-13 12:33           ` William Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=t2s6242182a1005111451uc2781ca0rcd97dbf6d3146684@mail.gmail.com \
    --to=snaipperi@gmail.com \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox