sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 941084696f939e2db0c00360d444d30741158ea8
parent a62b2809b8db73170a019c51bf2ff4d5e8d35338
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Sat, 19 Dec 2009 09:56:12 -0800

bugfix: wrapping crashed when defaulting to current buffer width

Diffstat:
M lib/sup/modes/thread-view-mode.rb | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb
@@ -134,7 +134,6 @@ EOS
     @layout[earliest].state = :detailed if earliest.has_label?(:unread) || @thread.size == 1
 
     @thread.remove_label :unread
-    regen_text
   end
 
   def toggle_wrap
@@ -153,6 +152,14 @@ EOS
   def lines; @text.length; end
   def [] i; @text[i]; end
 
+  ## a little hacky---since regen_text can depend on buffer features like the
+  ## content_width, we don't call it in the constructor, and instead call it
+  ## here, which is set before we're responsible for drawing ourself.
+  def buffer= b
+    super
+    regen_text
+  end
+
   def show_header
     m = @message_lines[curpos] or return
     BufferManager.spawn_unless_exists("Full header for #{m.id}") do
@@ -744,7 +751,10 @@ private
       raise "Bad chunk: #{chunk.inspect}" unless chunk.respond_to?(:inlineable?) ## debugging
       if chunk.inlineable?
         lines = chunk.lines
-        lines = lines.map { |l| l.chomp.wrap buffer.content_width }.flatten if @wrap
+        if @wrap
+          width = buffer.content_width
+          lines = lines.map { |l| l.chomp.wrap width }.flatten
+        end
         lines.map { |line| [[chunk.color, "#{prefix}#{line}"]] }
       elsif chunk.expandable?
         case state