sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 080c2884c9c6212a2f087b94edf0ddaa41d7a171
parent 031f39bc6cae9efb94cf2ec008e525b6890d637b
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Mon, 15 Jun 2009 08:00:07 -0700

make multibyte display "work" for non-utf8 locales

A nasty hack, but fixes a previous utf8-centric change.

Diffstat:
M lib/sup.rb | 2 +-
M lib/sup/util.rb | 10 +++++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -243,7 +243,7 @@ end
     Redwood::log "using character set encoding #{$encoding.inspect}"
   else
     Redwood::log "warning: can't find character set by using locale, defaulting to utf-8"
-    $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
@@ -172,7 +172,15 @@ class Object
 end
 
 class String
-  def display_length; scan(/./u).size end
+  ## 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 $encoding == "UTF-8"
+      scan(/./u).size
+    else
+      size
+    end
+  end
 
   def camel_to_hyphy
     self.gsub(/([a-z])([A-Z0-9])/, '\1-\2').downcase