Class: Terminitor::ItermCapture

Inherits:
AbstractCapture show all
Includes:
Appscript
Defined in:
lib/terminitor/capture/iterm_capture.rb

Overview

Captures terminal windows and tabs for Mac OS X

Constant Summary collapse

OPTIONS_MASK =

Defines what options of window or tab to capture and how just in case we’ll need to get other properties

{
  :window => {
    :bounds => "bounds"
  },
  :tab => {
    :settings => "current_settings.name"
  }
}

Instance Method Summary collapse

Methods inherited from AbstractCapture

#capture_settings

Constructor Details

#initializeItermCapture

Initialize @terminal with Terminal.app, Load the Windows, store the Termfile Terminitor::MacCore.new(‘/path’)



19
20
21
# File 'lib/terminitor/capture/iterm_capture.rb', line 19

def initialize
  @terminal = app('iTerm.app')
end

Instance Method Details

#capture_windowsObject

Returns settings of currently opened windows and tabs.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/terminitor/capture/iterm_capture.rb', line 24

def capture_windows
  windows = []
  # for some reason terminal.windows[] contain duplicated elements
  @terminal.windows.get.uniq.each do |window| 
    if window.visible.get
      tabs = window.tabs.get.inject([]) do |tabs, tab|
        tabs << {:options => object_options(tab)}
      end
      windows << {:options => object_options(window), :tabs => tabs}
    end
  end
  windows
end

#object_options(object) ⇒ Object

Returns hash of options of window or tab



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/terminitor/capture/iterm_capture.rb', line 39

def object_options(object)
  options = {}
  class_ =  object.class_.get
  if class_ && OPTIONS_MASK[class_]
    OPTIONS_MASK[class_].each_pair do |option, getter|
      value = object.instance_eval(getter).get
      options[option] = value
    end
  end
  options
end