Class: Termup::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/termup/base.rb

Direct Known Subclasses

Iterm, Terminal

Instance Method Summary collapse

Constructor Details

#initialize(project, process) ⇒ Base

Returns a new instance of Base.



3
4
5
6
7
8
9
# File 'lib/termup/base.rb', line 3

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

Instance Method Details

#startObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/termup/base.rb', line 11

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