Class: ItermWindow::Tab
- Inherits:
-
Object
- Object
- ItermWindow::Tab
- 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
-
#bookmark ⇒ Object
readonly
Returns the value of attribute bookmark.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#execute_block(&block) ⇒ Object
Runs a block on this tab with proper opening and closing statements.
-
#initialize(window, name, bookmark = nil, &block) ⇒ Tab
constructor
A new instance of Tab.
-
#select(&block) ⇒ Object
Brings a tab into focus, runs a block on it if passed.
-
#set_title(str) ⇒ Object
Sets the title of the tab (ie the text on the iTerm tab itself).
-
#write(command) ⇒ Object
Writes a command into the terminal tab.
Constructor Details
#initialize(window, name, bookmark = nil, &block) ⇒ Tab
Returns a new instance of Tab.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/iterm_window.rb', line 145 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
#bookmark ⇒ Object (readonly)
Returns the value of attribute bookmark.
143 144 145 |
# File 'lib/iterm_window.rb', line 143 def bookmark @bookmark end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
142 143 144 |
# File 'lib/iterm_window.rb', line 142 def name @name end |
Instance Method Details
#execute_block(&block) ⇒ Object
Runs a block on this tab with proper opening and closing statements
214 215 216 217 218 219 220 |
# File 'lib/iterm_window.rb', line 214 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
157 158 159 160 161 162 163 |
# File 'lib/iterm_window.rb', line 157 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)
175 176 177 178 179 180 181 |
# File 'lib/iterm_window.rb', line 175 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
166 167 168 169 170 171 172 |
# File 'lib/iterm_window.rb', line 166 def write(command) if @currently_executing_block output "write text '#{command}'" else execute_block { write command } end end |