sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/

lib/sup/tagger.rb (1223B) - raw

      1 require 'sup/util/ncurses'
      2 
      3 module Redwood
      4 
      5 class Tagger
      6   def initialize mode, noun="thread", plural_noun=nil
      7     @mode = mode
      8     @tagged = {}
      9     @noun = noun
     10     @plural_noun = plural_noun || (@noun + "s")
     11   end
     12 
     13   def tagged? o; @tagged[o]; end
     14   def toggle_tag_for o; @tagged[o] = !@tagged[o]; end
     15   def tag o; @tagged[o] = true; end
     16   def untag o; @tagged[o] = false; end
     17   def drop_all_tags; @tagged.clear; end
     18   def drop_tag_for o; @tagged.delete o; end
     19 
     20   def apply_to_tagged action=nil
     21     targets = @tagged.select_by_value
     22     num_tagged = targets.size
     23     if num_tagged == 0
     24       BufferManager.flash "No tagged threads!"
     25       return
     26     end
     27 
     28     noun = num_tagged == 1 ? @noun : @plural_noun
     29 
     30     unless action
     31       c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
     32       return if c.empty? # user cancelled
     33       action = @mode.resolve_input c
     34     end
     35 
     36     if action
     37       tagged_sym = "multi_#{action}".intern
     38       if @mode.respond_to? tagged_sym
     39         @mode.send tagged_sym, targets
     40       else
     41         BufferManager.flash "That command cannot be applied to multiple threads."
     42       end
     43     else
     44       BufferManager.flash "Unknown command #{c.to_character}."
     45     end
     46   end
     47 
     48 end
     49 
     50 end