class Subtle::Subtler::Runner

  1. data/subtler/runner.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. run

Public Class methods

new ()
initialize {{{

Intialize class

[show source]
# File data/subtler/runner.rb, line 29
def initialize
  @mod    = nil
  @group  = nil
  @action = nil
  @proc   = nil

  # Getopt options
  @opts = GetoptLong.new(
    # Groups
    [ '--Client',  '-c', GetoptLong::NO_ARGUMENT ],
    [ '--Gravity', '-g', GetoptLong::NO_ARGUMENT ],
    [ '--Screen',  '-e', GetoptLong::NO_ARGUMENT ],
    [ '--Sublet',  '-s', GetoptLong::NO_ARGUMENT ],
    [ '--Tag',     '-t', GetoptLong::NO_ARGUMENT ],
    [ '--Tray',    '-y', GetoptLong::NO_ARGUMENT ],
    [ '--View',    '-v', GetoptLong::NO_ARGUMENT ],

    # Actions
    [ '--add',     '-a', GetoptLong::NO_ARGUMENT ],
    [ '--kill',    '-k', GetoptLong::NO_ARGUMENT ],
    [ '--find',    '-f', GetoptLong::NO_ARGUMENT ],
    [ '--focus',   '-o', GetoptLong::NO_ARGUMENT ],
    [ '--full',    '-F', GetoptLong::NO_ARGUMENT ],
    [ '--float',   '-O', GetoptLong::NO_ARGUMENT ],
    [ '--stick',   '-S', GetoptLong::NO_ARGUMENT ],
    [ '--urgent',  '-N', GetoptLong::NO_ARGUMENT ],
    [ '--jump',    '-j', GetoptLong::NO_ARGUMENT ],
    [ '--list',    '-l', GetoptLong::NO_ARGUMENT ],
    [ '--tag',     '-T', GetoptLong::NO_ARGUMENT ],
    [ '--untag',   '-U', GetoptLong::NO_ARGUMENT ],
    [ '--tags',    '-G', GetoptLong::NO_ARGUMENT ],
    [ '--retag',   '-A', GetoptLong::NO_ARGUMENT ],
    [ '--clients', '-I', GetoptLong::NO_ARGUMENT ],
    [ '--views',   '-W', GetoptLong::NO_ARGUMENT ],
    [ '--update',  '-u', GetoptLong::NO_ARGUMENT ],
    [ '--data',    '-D', GetoptLong::NO_ARGUMENT ],
    [ '--gravity', '-Y', GetoptLong::NO_ARGUMENT ],
    [ '--screen',  '-n', GetoptLong::NO_ARGUMENT ],
    [ '--raise',   '-E', GetoptLong::NO_ARGUMENT ],
    [ '--lower',   '-L', GetoptLong::NO_ARGUMENT ],

    # Modifiers
    [ '--reload',  '-r', GetoptLong::NO_ARGUMENT       ],
    [ '--restart', '-R', GetoptLong::NO_ARGUMENT       ],
    [ '--quit',    '-q', GetoptLong::NO_ARGUMENT       ],
    [ '--current', '-C', GetoptLong::NO_ARGUMENT       ],
    [ '--select',  '-X', GetoptLong::NO_ARGUMENT       ],
    [ '--proc',    '-p', GetoptLong::REQUIRED_ARGUMENT ],

    # Other
    [ '--display', '-d', GetoptLong::REQUIRED_ARGUMENT ],
    [ '--help',    '-h', GetoptLong::NO_ARGUMENT       ],
    [ '--version', '-V', GetoptLong::NO_ARGUMENT       ]
  )
end

Public Instance methods

run ()
run {{{

Run subtler

[show source]
# File data/subtler/runner.rb, line 89
def run
  # Parse arguments
  @opts.each do |opt, arg|
    case opt
      # Groups
      when '--Client'  then @group  = Subtlext::Client
      when '--Gravity' then @group  = Subtlext::Gravity
      when '--Screen'  then @group  = Subtlext::Screen
      when '--Sublet'  then @group  = Subtlext::Sublet
      when '--Tag'     then @group  = Subtlext::Tag
      when '--Tray'    then @group  = Subtlext::Tray
      when '--View'    then @group  = Subtlext::View

      # Actions
      when '--add'     then @action = :new
      when '--kill'    then @action = :kill
      when '--find'    then @action = :find
      when '--focus'   then @action = :focus
      when '--full'    then @action = :toggle_full
      when '--float'   then @action = :toggle_float
      when '--stick'   then @action = :toggle_stick
      when '--urgent'  then @action = :toggle_urgent
      when '--jump'    then @action = :jump
      when '--list'    then @action = :list
      when '--tag'     then @action = :tag
      when '--untag'   then @action = :untag
      when '--tags'    then @action = :tags
      when '--retag'   then @action = :retag
      when '--clients' then @action = :clients
      when '--views'   then @action = :views
      when '--update'  then @action = :update
      when '--data'    then @action = :send_data
      when '--gravity' then @action = :gravity=
      when '--raise'   then @action = :raise
      when '--lower'   then @action = :lower

      # Modifiers
      when '--reload'  then @mod = :reload
      when '--restart' then @mod = :restart
      when '--quit'    then @mod = :quit
      when '--current' then @mod = :current
      when '--select'  then @mod = :select

      # Other
      when '--proc'
        @proc = Proc.new { |param| eval(arg) }
      when '--display'
        Subtlext::Subtle.display = arg 
      when '--help'
        usage(@group)
        exit
      when '--version'
        version
        exit
      else
        usage
        exit
    end
  end

  # Get arguments
  arg1 = ARGV.shift
  arg2 = ARGV.shift

  # Convert window ids
  arg1 = Integer(arg1) rescue arg1
  arg2 = Integer(arg2) rescue arg2

  # Pipes?
  arg1 = ARGF.read.chop if '-' == arg1

  if '-' == arg2
    # Read pipe until EOF
    begin
      while (arg2 = ARGF.readline) do
        handle_command(arg1, arg2.chop)
      end
    rescue EOFError
      # Just ignore this
    end
  else
    handle_command(arg1, arg2)
  end
end