Class: ItermWindow::Tab

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

Overview

The Tab class models a tab (session) in an iTerm terminal window and allows for it to be controlled by Ruby.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, name, bookmark = nil, &block) ⇒ Tab

Returns a new instance of Tab.



159
160
161
162
163
164
165
166
167
168
# File 'lib/iterm_window.rb', line 159

def initialize(window, name, bookmark = nil, &block)
  @name = name
  @bookmark = bookmark
  @window = window
  @currently_executing_block = false
  output "launch session '#{@bookmark}'"
  # store tty id for later access
  output "set #{name}_tty to the tty of the last session"
  execute_block &block if block_given?
end

Instance Attribute Details

#bookmarkObject (readonly)

Returns the value of attribute bookmark.



157
158
159
# File 'lib/iterm_window.rb', line 157

def bookmark
  @bookmark
end

#nameObject (readonly)

Returns the value of attribute name.



156
157
158
# File 'lib/iterm_window.rb', line 156

def name
  @name
end

Instance Method Details

#execute_block(&block) ⇒ Object

Runs a block on this tab with proper opening and closing statements



198
199
200
201
202
203
204
# File 'lib/iterm_window.rb', line 198

def execute_block(&block)
  @currently_executing_block = true
  output "tell session id #{name}_tty"
  self.instance_eval(&block)
  output "end tell"
  @currently_executing_block = false
end

#select(&block) ⇒ Object

Brings a tab into focus, runs a block on it if passed



171
172
173
174
175
176
177
# File 'lib/iterm_window.rb', line 171

def select(&block)
  if block_given?
    execute_block &block
  else
    output "select session id #{name}_tty"
  end
end

#set_title(str) ⇒ Object

Sets the title of the tab (ie the text on the iTerm tab itself)



189
190
191
192
193
194
195
# File 'lib/iterm_window.rb', line 189

def set_title(str)
  if @currently_executing_block
    output "set name to '#{str}'"
  else
    execute_block { set_title = str }
  end
end

#write(command) ⇒ Object

Writes a command into the terminal tab



180
181
182
183
184
185
186
# File 'lib/iterm_window.rb', line 180

def write(command)
  if @currently_executing_block
    output "write text '#{command}'"
  else
    execute_block { write command }
  end
end