Class: Godo::TerminalSession

Inherits:
Session
  • Object
show all
Defined in:
lib/sessions/terminal_session.rb

Instance Attribute Summary

Attributes inherited from Session

#path

Instance Method Summary collapse

Methods inherited from Session

#counter, #create, #set_label

Constructor Details

#initialize(path) ⇒ TerminalSession

Returns a new instance of TerminalSession.



8
9
10
11
12
# File 'lib/sessions/terminal_session.rb', line 8

def initialize( path )
  super( path )
  @@terminal ||= Appscript::app('Terminal')
  @window = nil
end

Instance Method Details

#execute(command) ⇒ Object



29
30
31
# File 'lib/sessions/terminal_session.rb', line 29

def execute( command )
  @@terminal.do_script(command, :in => @window.tabs.last.get)
end

#startObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sessions/terminal_session.rb', line 14

def start
  if @window
    @window.frontmost.set(true)
    Appscript::app('Terminal').activate
    Appscript::app("System Events").application_processes["Terminal.app"].keystroke("t", :using => :command_down)
    while (@window.tabs.last.busy.get)
      # we're not on the new tab yet.  wait a bit...
      sleep 0.1
    end
  else
    first_tab = @@terminal.do_script('')
    @window = eval('Appscript::' + first_tab.to_s.gsub(/\.tabs.*$/, '')) # nasty hack.  is there a legit way to find my mommy?
  end
end