Archive of RubyForge sup-talk mailing list
 help / color / mirror / Atom feed
From: wmorgan-sup@masanjin.net (William Morgan)
Subject: [sup-talk] display_length issue with special-characters on non-UTF8 terminal
Date: Fri, 12 Jun 2009 12:18:11 -0700	[thread overview]
Message-ID: <1244834230-sup-1200@entry> (raw)
In-Reply-To: <1244536704-sup-7027@valgus>

Reformatted excerpts from Tarko Tikan's message of 2009-06-09:
> When String.display_length was introduced in recent update, it broke
> the length for non-UTF8 strings that contain the special characters.
> Wrong length results corrupted display (line ends chopped off).

That's a good point. I got a little utf8-centric with those changes.
(I'm assuming that your terminal encoding is not UTF-8.)

Does this patch fix the issue? If so, I will release an 0.8.1.

--- cut here ---
diff --git a/lib/sup.rb b/lib/sup.rb
index 4f59eaa..20835ae 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -244,7 +244,7 @@ end
     Redwood::log "using character set encoding #{$encoding.inspect}"
   else
     Redwood::log "warning: can't find character set by using locale, defaulting
-    $encoding = "utf-8"
+    $encoding = "UTF-8"
   end
 
 ## now everything else (which can feel free to call Redwood::log at load time)
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
index 8a3004f..d5310bc 100644
--- a/lib/sup/util.rb
+++ b/lib/sup/util.rb
@@ -172,7 +172,13 @@ class Object
 end
 
 class String
-  def display_length; scan(/./u).size end
+  def display_length
+    if $encoding == "UTF-8"
+      scan(/./u).size
+    else
+      size
+    end
+  end
 
   def camel_to_hyphy
     self.gsub(/([a-z])([A-Z0-9])/, '\1-\2').downcase

-- 
William <wmorgan-sup at masanjin.net>


  reply	other threads:[~2009-06-12 19:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-09 10:00 Tarko Tikan
2009-06-12 19:18 ` William Morgan [this message]
2009-06-13 11:13   ` Tarko Tikan
2009-06-15 14:10     ` William Morgan
2009-06-17 16:04     ` William Morgan
2009-06-17 18:34       ` Nicolas Pouillard

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=1244834230-sup-1200@entry \
    --to=wmorgan-sup@masanjin.net \
    /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