Sha256: e8d75b02cdd86c0745594b4a85750019b9595f5e0d61a84ca342fc2e2804ec71

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

module Termup
  class Base
    def initialize(project, process)
      @config = YAML.load_file(Termup::Dir.join("#{project}.yml"))
      @options = @config['options'] || {}
      @tabs = @config['tabs'] || {}
      @process = process
      @lines = []
    end

    def start
      script = <<-JS.gsub(/^\s+/, '')
        var app = Application(#{@process.pid});
        var se = Application('System Events');
        app.activate();
        #{@lines.join(";\n")}
      JS
      ExecJS.exec script

    rescue ExecJS::RuntimeError => e
      script.split("\n").each.with_index do |line, i|
        index = (i+1).to_s.rjust(3)
        puts "#{index}: #{line}"
      end
      puts e.message
    end

    protected

    def hit(key, *using)
      # activate
      using = using.map{|i| i.to_s.gsub(/_/,' ') }
      case key
      when Integer
        @lines << "se.keyCode(#{key}, { using: #{using} })"
      when String
        @lines << "se.keystroke('#{key}', { using: #{using} })"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
termup-3.0.1 lib/termup/base.rb