sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit b1710574d5363fe84a3683a403b2baf374377a3c
parent 343b3c4fe1c6f3a3f4cb5c3ca928455fbd1ced88
Author: Gaute Hope <eg@gaute.vetsj.com>
Date:   Thu,  6 Feb 2014 15:01:54 +0100

Merge branch 'develop'

Diffstat:
M CONTRIBUTORS | 17 +++++++++--------
M History.txt | 4 ++++
M ReleaseNotes | 4 ++++
M lib/sup.rb | 4 ++--
M lib/sup/buffer.rb | 2 +-
M lib/sup/colormap.rb | 60 ++++++++++++++++++++++++++++++------------------------------
M lib/sup/keymap.rb | 22 +++++++++++-----------
M lib/sup/modes/thread_view_mode.rb | 2 +-
M lib/sup/textfield.rb | 1 +
9 files changed, 63 insertions(+), 53 deletions(-)
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
@@ -33,14 +33,14 @@ Michael Hamann <michael at the content-space dot des>
 Jonathan Lassoff <jof at the thejof dot coms>
 William Erik Baxter <web at the superscript dot coms>
 Grant Hollingworth <grant at the antiflux dot orgs>
-Markus Klinik <markus.klinik at the gmx dot des>
 Adeodato Simó <dato at the net.com.org dot ess>
+Markus Klinik <markus.klinik at the gmx dot des>
 Ico Doornekamp <ico at the pruts dot nls>
 Daniel Schoepe <daniel.schoepe at the googlemail dot coms>
-James Taylor <james at the jamestaylor dot orgs>
 Jason Petsod <jason at the petsod dot orgs>
-Robin Burchell <viroteck at the viroteck dot nets>
+James Taylor <james at the jamestaylor dot orgs>
 Steve Goldman <sgoldman at the tower-research dot coms>
+Robin Burchell <viroteck at the viroteck dot nets>
 Peter Harkins <ph at the malaprop dot orgs>
 Decklin Foster <decklin at the red-bean dot coms>
 Cameron Matheson <cam+sup at the cammunism dot orgs>
@@ -59,16 +59,17 @@ Steven Lawrance <stl at the koffein dot nets>
 Jonah <Jonah at the GoodCoffee dot cas>
 ian <itaylor at the uark dot edus>
 Todd Eisenberger <teisenbe at the andrew.cmu dot edus>
-MichaelRevell <mikearevell at the gmail dot coms>
-Adam Lloyd <adam at the alloy-d dot nets>
-Gregor Hoffleit <gregor at the sam.mediasupervision dot des>
 Per Andersson <avtobiff at the gmail dot coms>
+Adam Lloyd <adam at the alloy-d dot nets>
+MichaelRevell <mikearevell at the gmail dot coms>
 0xACE <0xACE at the users.noreply.github dot coms>
+Gregor Hoffleit <gregor at the sam.mediasupervision dot des>
 Steven Walter <swalter at the monarch.(none)>
-Matthias Vallentin <vallentin at the icir dot orgs>
-Jon M. Dugan <jdugan at the es dot nets>
+Atte Kojo <atte.kojo at the reaktor dot fis>
 Stefan Lundström <lundst at the snabb.(none)>
+Matthias Vallentin <vallentin at the icir dot orgs>
 akojo <atte.kojo at the gmail dot coms>
 Horacio Sanson <horacio at the skillupjapan.co dot jps>
+Jon M. Dugan <jdugan at the es dot nets>
 Johannes Larsen <johs.a.larsen at the gmail dot coms>
 Kirill Smelkov <kirr at the landau.phys.spbu dot rus>
diff --git a/History.txt b/History.txt
@@ -1,3 +1,7 @@
+== 0.15.4 / 2014-02-06
+
+* Various bugfixes
+
 == 0.15.3 / 2014-01-27
 
 * Revert non-functioning hidden_alternates and fix some bugs.
diff --git a/ReleaseNotes b/ReleaseNotes
@@ -1,3 +1,7 @@
+Release 0.15.4:
+
+Bugfixes.
+
 Release 0.15.3:
 
 Revert non-functioning hidden_alternates option and fix bugs.
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -7,7 +7,7 @@ require 'zlib'
 require 'thread'
 require 'fileutils'
 require 'locale'
-require 'curses'
+require 'ncursesw'
 require 'rmail'
 begin
   require 'fastthread'
@@ -253,7 +253,7 @@ EOS
 
     managers.each { |x| x.deinstantiate! if x.instantiated? }
 
-    @log_io.close
+    @log_io.close if @log_io
     @log_io = nil
     $config = nil
   end
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
@@ -633,7 +633,7 @@ EOS
     action, text = keymap.action_for c
     while action.is_a? Keymap # multi-key commands, prompt
       key = BufferManager.ask_getch text
-      unless key.empty? # user canceled, abort
+      unless key # user canceled, abort
         erase_flash
         raise InputSequenceAborted
       end
diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
@@ -1,4 +1,4 @@
-module Curses
+module Ncurses
   COLOR_DEFAULT = -1
 
   NUM_COLORS = `tput colors`.to_i
@@ -9,9 +9,9 @@ module Curses
   end
 
   ## numeric colors
-  Curses::NUM_COLORS.times { |x| color! x, x }
+  Ncurses::NUM_COLORS.times { |x| color! x, x }
 
-  if Curses::NUM_COLORS == 256
+  if Ncurses::NUM_COLORS == 256
     ## xterm 6x6x6 color cube
     6.times { |x| 6.times { |y| 6.times { |z| color! "c#{x}#{y}#{z}", 16 + z + 6*y + 36*x } } }
 
@@ -71,7 +71,7 @@ class Colormap
   def initialize
     raise "only one instance can be created" if @@instance
     @@instance = self
-    @color_pairs = {[Curses::COLOR_WHITE, Curses::COLOR_BLACK] => 0}
+    @color_pairs = {[Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK] => 0}
     @users = []
     @next_id = 0
     reset
@@ -81,15 +81,15 @@ class Colormap
   def reset
     @entries = {}
     @highlights = { :none => highlight_sym(:none)}
-    @entries[highlight_sym(:none)] = highlight_for(Curses::COLOR_WHITE,
-                                                   Curses::COLOR_BLACK,
+    @entries[highlight_sym(:none)] = highlight_for(Ncurses::COLOR_WHITE,
+                                                   Ncurses::COLOR_BLACK,
                                                    []) + [nil]
   end
 
   def add sym, fg, bg, attr=nil, highlight=nil
     raise ArgumentError, "color for #{sym} already defined" if @entries.member? sym
-    raise ArgumentError, "color '#{fg}' unknown" unless (-1...Curses::NUM_COLORS).include? fg
-    raise ArgumentError, "color '#{bg}' unknown" unless (-1...Curses::NUM_COLORS).include? bg
+    raise ArgumentError, "color '#{fg}' unknown" unless (-1...Ncurses::NUM_COLORS).include? fg
+    raise ArgumentError, "color '#{bg}' unknown" unless (-1...Ncurses::NUM_COLORS).include? bg
     attrs = [attr].flatten.compact
 
     @entries[sym] = [fg, bg, attrs, nil]
@@ -109,33 +109,33 @@ class Colormap
   def highlight_for fg, bg, attrs
     hfg =
       case fg
-      when Curses::COLOR_BLUE
-        Curses::COLOR_WHITE
-      when Curses::COLOR_YELLOW, Curses::COLOR_GREEN
+      when Ncurses::COLOR_BLUE
+        Ncurses::COLOR_WHITE
+      when Ncurses::COLOR_YELLOW, Ncurses::COLOR_GREEN
         fg
       else
-        Curses::COLOR_BLACK
+        Ncurses::COLOR_BLACK
       end
 
     hbg =
       case bg
-      when Curses::COLOR_CYAN
-        Curses::COLOR_YELLOW
-      when Curses::COLOR_YELLOW
-        Curses::COLOR_BLUE
+      when Ncurses::COLOR_CYAN
+        Ncurses::COLOR_YELLOW
+      when Ncurses::COLOR_YELLOW
+        Ncurses::COLOR_BLUE
       else
-        Curses::COLOR_CYAN
+        Ncurses::COLOR_CYAN
       end
 
     attrs =
-      if fg == Curses::COLOR_WHITE && attrs.include?(Curses::A_BOLD)
-        [Curses::A_BOLD]
+      if fg == Ncurses::COLOR_WHITE && attrs.include?(Ncurses::A_BOLD)
+        [Ncurses::A_BOLD]
       else
         case hfg
-        when Curses::COLOR_BLACK
+        when Ncurses::COLOR_BLACK
           []
         else
-          [Curses::A_BOLD]
+          [Ncurses::A_BOLD]
         end
       end
     [hfg, hbg, attrs]
@@ -143,7 +143,7 @@ class Colormap
 
   def color_for sym, highlight=false
     sym = @highlights[sym] if highlight
-    return Curses::COLOR_BLACK if sym == :none
+    return Ncurses::COLOR_BLACK if sym == :none
     raise ArgumentError, "undefined color #{sym}" unless @entries.member? sym
 
     ## if this color is cached, return it
@@ -153,14 +153,14 @@ class Colormap
     if(cp = @color_pairs[[fg, bg]])
       ## nothing
     else ## need to get a new colorpair
-      @next_id = (@next_id + 1) % Curses::MAX_PAIRS
+      @next_id = (@next_id + 1) % Ncurses::MAX_PAIRS
       @next_id += 1 if @next_id == 0 # 0 is always white on black
       id = @next_id
       debug "colormap: for color #{sym}, using id #{id} -> #{fg}, #{bg}"
-      Curses.init_pair id, fg, bg or raise ArgumentError,
+      Ncurses.init_pair id, fg, bg or raise ArgumentError,
         "couldn't initialize curses color pair #{fg}, #{bg} (key #{id})"
 
-      cp = @color_pairs[[fg, bg]] = Curses.color_pair(id)
+      cp = @color_pairs[[fg, bg]] = Ncurses.COLOR_PAIR(id)
       ## delete the old mapping, if it exists
       if @users[cp]
         @users[cp].each do |usym|
@@ -192,22 +192,22 @@ class Colormap
 
     Colormap::DEFAULT_COLORS.merge(user_colors||{}).each_pair do |k, v|
       fg = begin
-        Curses.const_get "COLOR_#{v[:fg].to_s.upcase}"
+        Ncurses.const_get "COLOR_#{v[:fg].to_s.upcase}"
       rescue NameError
         warn "there is no color named \"#{v[:fg]}\""
-        Curses::COLOR_GREEN
+        Ncurses::COLOR_GREEN
       end
 
       bg = begin
-        Curses.const_get "COLOR_#{v[:bg].to_s.upcase}"
+        Ncurses.const_get "COLOR_#{v[:bg].to_s.upcase}"
       rescue NameError
         warn "there is no color named \"#{v[:bg]}\""
-        Curses::COLOR_RED
+        Ncurses::COLOR_RED
       end
 
       attrs = (v[:attrs]||[]).map do |a|
         begin
-          Curses.const_get "A_#{a.upcase}"
+          Ncurses.const_get "A_#{a.upcase}"
         rescue NameError
           warn "there is no attribute named \"#{a}\", using fallback."
           nil
diff --git a/lib/sup/keymap.rb b/lib/sup/keymap.rb
@@ -19,19 +19,19 @@ EOS
 
   def self.keysym_to_keycode k
     case k
-    when :down then Curses::KEY_DOWN
-    when :up then Curses::KEY_UP
-    when :left then Curses::KEY_LEFT
-    when :right then Curses::KEY_RIGHT
-    when :page_down then Curses::KEY_NPAGE
-    when :page_up then Curses::KEY_PPAGE
-    when :backspace then Curses::KEY_BACKSPACE
-    when :home then Curses::KEY_HOME
-    when :end then Curses::KEY_END
+    when :down then Ncurses::KEY_DOWN
+    when :up then Ncurses::KEY_UP
+    when :left then Ncurses::KEY_LEFT
+    when :right then Ncurses::KEY_RIGHT
+    when :page_down then Ncurses::KEY_NPAGE
+    when :page_up then Ncurses::KEY_PPAGE
+    when :backspace then Ncurses::KEY_BACKSPACE
+    when :home then Ncurses::KEY_HOME
+    when :end then Ncurses::KEY_END
     when :ctrl_l then "\f".ord
     when :ctrl_g then "\a".ord
     when :tab then "\t".ord
-    when :enter, :return then 10 #Curses::KEY_ENTER
+    when :enter, :return then 10 #Ncurses::KEY_ENTER
     else
       if k.is_a?(String) && k.length == 1
         k.ord
@@ -56,7 +56,7 @@ EOS
     when :tab then "tab"
     when " " then "<space>"
     else
-      Curses::keyname(keysym_to_keycode(k))
+      Ncurses::keyname(keysym_to_keycode(k))
     end
   end
 
diff --git a/lib/sup/modes/thread_view_mode.rb b/lib/sup/modes/thread_view_mode.rb
@@ -239,7 +239,7 @@ EOS
           else hookcmd
           end + ' ' + to.map { |t| t.email }.join(' ')
 
-    bt = to.size > 1 ? "#{to.size} recipients" : to.to_s
+    bt = to.size > 1 ? "#{to.size} recipients" : to[0].to_s
 
     if BufferManager.ask_yes_or_no "Really bounce to #{bt}?"
       debug "bounce command: #{cmd}"
diff --git a/lib/sup/textfield.rb b/lib/sup/textfield.rb
@@ -234,6 +234,7 @@ private
   end
 
   def set_cursed_value v
+    v = "" if v.nil?
     @field.set_field_buffer 0, v
   end