Method: Mynu::Support::Terminal#create_tab

Defined in:
lib/mynu/support/terminal.rb

#create_tab(command, options = {}) ⇒ Object

For terminal.app I use an SIMBL plugin called Visor, this intergates tab support for your primary (first) window If someone wants to write support for multiple windows, it would help the project a lot!



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mynu/support/terminal.rb', line 26

def create_tab(command, options = {})
  options = {
    :exit => false,
    :focus => false
  }.merge(options)

  current_process  = nil
  terminal_process = nil

  terminals = self.windows.first.tabs.map do |terminal_tab|
    terminal_tab
  end

  system.processes.each do |process|
    current_process = process if process.frontmost
  end
  system.processes.each do |process|
    terminal_process = process if process.shortName == "Terminal"
  end

  terminal_process.setFrontmost true
  system.keystroke "t", Mynu::Support::System::CommandDown
  system.keystroke "#{command}\r" if command.length > 0

  current_terminals = self.windows.first.tabs.map do |terminal_tab|
    terminal_tab
  end

  new_terminal_tab = nil
  current_terminals.each do |terminal_tab|
    new_terminal_tab = terminal_tab unless terminals.include?(terminal_tab)
  end

  # exit the new tab
  if options[:exit]
    # broken: 
    # new_terminal_tab.send(:"closeSaving:savingIn:", TerminalSaveOptionsNo, nil)
    wait_for_terminal_tab(new_terminal_tab)
    system.keystroke("exit\r")
    wait_for_terminal_tab(new_terminal_tab)
    system.keystroke "w", Mynu::Support::System::CommandDown
  end

  current_process.setFrontmost true unless options[:focus]

  new_terminal_tab
end