Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Matti Eiden <snaipperi@gmail.com>
To: sup-devel <sup-devel@rubyforge.org>
Subject: Re: [sup-devel] Arch utf8 vs UTF-8 fix and wide character support
Date: Tue, 11 May 2010 21:50:17 +0300	[thread overview]
Message-ID: <k2l6242182a1005111150n1b018aanf8a939e1d260b59a@mail.gmail.com> (raw)
In-Reply-To: <1273250528-sup-9662@zyrg.net>

>
> It's actually the multiple screen cells that causes problems, not
> multiple bytes [1]. Sup currently thinks all characters are 1 cell wide.
> The right thing is probably a C extension that uses wcswidth.
>
> [1] http://mid.gmane.org/1264629880-sup-9232%40zyrg.net
>

So okay, I sent my previous answer accidentally only to Rich. In this
mail I mentioned a Ruby library called terminfo (
http://www.a-k-r.org/ruby-terminfo/ ), which contains a function
wcswidth.

I downloaded terminfo and installed it, and edited lib/sup/util.rb slightly.
1) Added of course "require 'terminfo'" on the top.
2) Modified the display_length function of "nasty multibyte hack" to
use TermInfo.wcswidth instead of native "size"


Results: Everything seems to work now.

I don't know what is the opinion of other sup users, whether adding a
new dependency (to terminfo) is desirable, as the current list of
dependencies is already rather high.. Discuss. If somebody with some C
skills knows how to move that wcswidth function to the ruby-ncursesw
(Rich? :D) would that be a more favourable option?

Here's the actual patch of what I did to keep it clear (I notice there
has been an earlier utf8 patch here, for pre Ruby 1.9.1 versions. I
don't know how many of you use some earlier Ruby version still, of
course this would also solve the "nasty" utf scan patch.):

--- util-old.rb	2010-05-11 21:38:55.736596584 +0300
+++ util.rb	2010-05-11 21:36:12.653281044 +0300
@@ -3,6 +3,7 @@
 require 'mime/types'
 require 'pathname'
 require 'set'
+require 'terminfo'
 ## time for some monkeypatching!
 class Lockfile
   def gen_lock_id
@@ -183,7 +184,7 @@
     if RUBY_VERSION < '1.9.1' && ($encoding == "UTF-8" || $encoding == "utf8")
       scan(/./u).size
     else
-      size
+      TermInfo.wcswidth(self)
     end
   end
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


  reply	other threads:[~2010-05-11 18:56 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 [this message]
2010-05-11 19:19       ` William Morgan
2010-05-11 21:51         ` Matti Eiden
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=k2l6242182a1005111150n1b018aanf8a939e1d260b59a@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