Class: Osaka::Terminal

Inherits:
TypicalApplication
  • Object
show all
Defined in:
lib/multiterm/terminal.rb

Instance Method Summary collapse

Constructor Details

#initializeTerminal

Returns a new instance of Terminal.



5
6
7
# File 'lib/multiterm/terminal.rb', line 5

def initialize
  super "Terminal"
end

Instance Method Details

#tab_configure(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/multiterm/terminal.rb', line 9

def tab_configure(options={})
  tab_name = options[:name]
  script = options[:script]
  directory = options[:directory]
  control.keystroke('t', :command) if options[:new_tab]
  if directory != nil
    control.tell('do script "cd \'' + directory + '\'" in front window')
  end
  if tab_name != nil
    tab_name.gsub!(/[^a-zA-Z0-9 \_\-\.]/, '')

    # This low-level block is needed because Osaka naively splits
    # on ';' character, which we need to use mid-script.
    script_commands = [
      'tell application "Terminal"',
      'do script "printf \'\\\\\e]1;' + tab_name.to_s + '\\\\\a\'" in front window',
      'end tell'
    ].map { |c| c.gsub("\"", "\\\"") }
    escaped_commands = ""
    script_commands.each { |l| escaped_commands += " -e \"#{l.strip}\"" }
    new_tab_output = `osascript#{escaped_commands} 2>&1`
  end
  control.tell('do script "clear" in front window')
  if script != nil
    # LOL, yes, we need to triple-escape for double quotes.
    # Single quotes should Just Work.
    control.tell('do script "' + script.gsub("\"", "\\\\\\\"") + '" in front window')
  end
  return nil
end