Class: ItermWindow

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

Overview

The ItermWindow class models an iTerm terminal window and allows for full control via Ruby commands.

Defined Under Namespace

Classes: Tab

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeItermWindow

While you can directly use ItermWindow.new, using either ItermWindow.open or ItermWindow.current is the preferred method.



96
97
98
99
100
101
# File 'lib/iterm_window.rb', line 96

def initialize
  @buffer = []
  @tabs = {}
  @tab_color_files = []
  @default_tab = nil
end

Instance Attribute Details

#tab_color_filesObject (readonly)

Returns the value of attribute tab_color_files.



74
75
76
# File 'lib/iterm_window.rb', line 74

def tab_color_files
  @tab_color_files
end

Class Method Details

.colorsObject



81
82
83
# File 'lib/iterm_window.rb', line 81

def colors
  @colors
end

.colors=(colors) ⇒ Object



77
78
79
# File 'lib/iterm_window.rb', line 77

def colors=(colors)
  @colors = colors
end

.current(&block) ⇒ Object

Selects the first terminal window, runs the block on it



113
114
115
# File 'lib/iterm_window.rb', line 113

def self.current(&block)
  self.new.run(:current, &block)
end

.open(options = {}, &block) ⇒ Object

Creates a new terminal window, runs the block on it



108
109
110
# File 'lib/iterm_window.rb', line 108

def self.open(options = {}, &block)
  self.new.run(:new, options, &block)
end

.run_file(file) ⇒ Object



103
104
105
# File 'lib/iterm_window.rb', line 103

def self.run_file(file)
  instance_eval(file)
end

Instance Method Details

#concatenated_bufferObject



143
144
145
# File 'lib/iterm_window.rb', line 143

def concatenated_buffer
  @buffer.join("\n")
end

#default_tab(name, options = {}, &block) ⇒ Object



134
135
136
# File 'lib/iterm_window.rb', line 134

def default_tab(name, options = {}, &block)
  open_tab(name, options.merge(:default => true), &block)
end

#open_bookmark(name, bookmark, &block) ⇒ Object

Creates a new tab from a bookmark, runs the block on it



124
125
126
# File 'lib/iterm_window.rb', line 124

def open_bookmark(name, bookmark, &block)
  create_tab(name, bookmark, &block)
end

#open_tab(name, options = {}, &block) ⇒ Object

Creates a new tab from ‘Default Session’, runs the block on it



129
130
131
132
# File 'lib/iterm_window.rb', line 129

def open_tab(name, options = {}, &block)
  create_tab(name, 'Default Session', options, &block)
  @default_tab = name if options[:default]
end

#output(command) ⇒ Object

Outputs a single line of Applescript code



139
140
141
# File 'lib/iterm_window.rb', line 139

def output(command)
  @buffer << command.gsub("'", '"').gsub('\\', '\\\\\\')
end

#run(window_type = :new, options = {}, &block) ⇒ Object



117
118
119
120
121
# File 'lib/iterm_window.rb', line 117

def run(window_type = :new, options = {}, &block)
  @options = options
  run_commands window_type, &block
  send_output
end