sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit e79c3fed32712390ef2cceaae4dc07b133c1d7d8
parent fe293d382fd9c534672361c6efd5c7ac4322e6bb
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Thu, 13 Jan 2011 21:01:43 -0800

Merge branch 'scrolling' into next

Diffstat:
M lib/sup.rb | 3 ++-
M lib/sup/colormap.rb | 2 ++
M lib/sup/modes/scroll-mode.rb | 12 +++++++-----
M lib/sup/util.rb | 3 ++-
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -282,7 +282,8 @@ EOS
         :sent_source => "sup://sent",
         :poll_interval => 300,
         :wrap_width => 0,
-        :slip_rows => 0
+        :slip_rows => 0,
+        :col_jump => 2
       }
       begin
         Redwood::save_yaml_obj config, filename
diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
@@ -220,6 +220,8 @@ class Colormap
     Colormap.new unless @@instance
     @@instance.send meth, *a
   end
+  # Performance shortcut
+  def self.color_for *a; @@instance.color_for *a; end
 end
 
 end
diff --git a/lib/sup/modes/scroll-mode.rb b/lib/sup/modes/scroll-mode.rb
@@ -12,8 +12,6 @@ class ScrollMode < Mode
 
   attr_reader :status, :topline, :botline, :leftcol
 
-  COL_JUMP = 2
-
   register_keymap do |k|
     k.add :line_down, "Down one line", :down, 'j', 'J', "\C-e"
     k.add :line_up, "Up one line", :up, 'k', 'K', "\C-y"
@@ -98,19 +96,23 @@ class ScrollMode < Mode
   def search_start_line; @topline end
   def search_goto_line line; jump_to_line line end
 
+  def col_jump
+    $config[:col_jump] || 2
+  end
+
   def col_left
     return unless @leftcol > 0
-    @leftcol -= COL_JUMP
+    @leftcol -= col_jump
     buffer.mark_dirty
   end
 
   def col_right
-    @leftcol += COL_JUMP
+    @leftcol += col_jump
     buffer.mark_dirty
   end
 
   def jump_to_col col
-    col = col - (col % COL_JUMP)
+    col = col - (col % col_jump)
     buffer.mark_dirty unless @leftcol == col
     @leftcol = col
   end
diff --git a/lib/sup/util.rb b/lib/sup/util.rb
@@ -212,7 +212,8 @@ class String
   ## 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
+      # scan hack is somewhat slow, worth trying to cache
+      @display_length ||= scan(/./u).size
     else
       size
     end