Sha256: 0f5fdd60d476b407bc18ef9ce4e32f58af136200dfd3d65e50753425ac1bbdf5

Contents?: true

Size: 1.19 KB

Versions: 15

Compression:

Stored size: 1.19 KB

Contents

require 'sup/util/ncurses'

module Redwood

class Tagger
  def initialize mode, noun="thread", plural_noun=nil
    @mode = mode
    @tagged = {}
    @noun = noun
    @plural_noun = plural_noun || (@noun + "s")
  end

  def tagged? o; @tagged[o]; end
  def toggle_tag_for o; @tagged[o] = !@tagged[o]; end
  def tag o; @tagged[o] = true; end
  def untag o; @tagged[o] = false; end
  def drop_all_tags; @tagged.clear; end
  def drop_tag_for o; @tagged.delete o; end

  def apply_to_tagged action=nil
    targets = @tagged.select_by_value
    num_tagged = targets.size
    if num_tagged == 0
      BufferManager.flash "No tagged threads!"
      return
    end

    noun = num_tagged == 1 ? @noun : @plural_noun

    unless action
      c = BufferManager.ask_getch "apply to #{num_tagged} tagged #{noun}:"
      return if c.empty? # user cancelled
      action = @mode.resolve_input c
    end

    if action
      tagged_sym = "multi_#{action}".intern
      if @mode.respond_to? tagged_sym
        @mode.send tagged_sym, targets
      else
        BufferManager.flash "That command cannot be applied to multiple threads."
      end
    else
      BufferManager.flash "Unknown command #{c.to_character}."
    end
  end

end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
sup-1.2 lib/sup/tagger.rb
sup-1.1 lib/sup/tagger.rb
sup-1.0 lib/sup/tagger.rb
sup-0.23 lib/sup/tagger.rb
sup-0.22.1 lib/sup/tagger.rb
sup-0.22.0 lib/sup/tagger.rb
sup-0.21.0 lib/sup/tagger.rb
sup-0.20.0 lib/sup/tagger.rb
sup-0.19.0 lib/sup/tagger.rb
sup-0.18.0 lib/sup/tagger.rb
sup-0.17.0 lib/sup/tagger.rb
sup-0.16.0 lib/sup/tagger.rb
sup-0.15.4 lib/sup/tagger.rb
sup-0.15.3 lib/sup/tagger.rb
sup-0.15.2 lib/sup/tagger.rb