Class: Consular::Terminator
- Inherits:
-
Core
- Object
- Core
- Consular::Terminator
- Defined in:
- lib/consular/terminator.rb,
lib/consular/terminator/version.rb
Overview
Consular core for interacting with Terminator.
Since we don’t have any real API to work with and just send keypresses via XTEST, we don’t have tab references either. Instead we just count tabs and return tab indexes.
Largely adapted from github.com/achiu/consular-osx
Defined Under Namespace
Modules: Version
Constant Summary collapse
Class Method Summary collapse
-
.valid_system? ⇒ Boolean
Check to see if current system is valid for this core.
Instance Method Summary collapse
-
#execute_command(cmd, options = {}) ⇒ Object
Execute the given command in the context of the active window.
-
#execute_window(content, options = {}) ⇒ Object
Executes the commands for each designated window.
-
#initialize(path) ⇒ Terminator
constructor
Initialize.
-
#open_tab(options = nil) ⇒ Object
Opens a new tab and return the last instantiated tab(itself).
-
#open_window(options = nil) ⇒ Object
Opens a new window and returns its last instantiated tab.(The first ‘tab’ in the window).
-
#prepend_befores(commands, befores = nil) ⇒ Array<String>
Prepends the :before commands to the current context’s commands if it exists.
-
#process! ⇒ Object
Method called by runner to execute Termfile.
-
#set_title(title, commands) ⇒ Object
Prepend a title setting command prior to the other commands.
-
#setup! ⇒ Object
Method called by runner to Execute Termfile setup.
Constructor Details
#initialize(path) ⇒ Terminator
Initialize
40 41 42 43 |
# File 'lib/consular/terminator.rb', line 40 def initialize(path) super @tabidx = nil end |
Class Method Details
.valid_system? ⇒ Boolean
Check to see if current system is valid for this core
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/consular/terminator.rb', line 20 def valid_system? if (RbConfig::CONFIG['host_os'] =~ /linux/) != nil if !(xdotool = `which xdotool`.chomp).empty? begin return File::Stat.new(xdotool).executable? rescue return false end end end return false end |
Instance Method Details
#execute_command(cmd, options = {}) ⇒ Object
Execute the given command in the context of the active window.
156 157 158 |
# File 'lib/consular/terminator.rb', line 156 def execute_command(cmd, = {}) run_in_active_terminator cmd, end |
#execute_window(content, options = {}) ⇒ Object
Executes the commands for each designated window. .run_windows will iterate through each of the tabs in sorted order to execute the tabs in the order they were set. The logic follows this:
If the content is for the 'default' window,
then use the current active window and generate the commands.
If the content is for a new window,
then generate a new window and activate the windows.
Otherwise, open a new tab and execute the commands.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/consular/terminator.rb', line 86 def execute_window(content, = {}) = content[:options] _contents = content[:tabs] _first_run = true _contents.keys.sort.each do |key| _content = _contents[key] = content[:options] _name = [:name] _tab = if _first_run && ![:default] open_window .merge() else key == 'default' ? nil : open_tab() end _first_run = false commands = prepend_befores _content[:commands], content[:before] commands = set_title _name, commands commands.each { |cmd| execute_command cmd, :in => _tab } end end |
#open_tab(options = nil) ⇒ Object
Opens a new tab and return the last instantiated tab(itself).
172 173 174 175 176 177 |
# File 'lib/consular/terminator.rb', line 172 def open_tab( = nil) send_keypress(active_terminator_window, "ctrl+shift+t") # FIXME: horribly hacky but can't come up with any way # to truly make sure tab has opened. sleep 1 end |
#open_window(options = nil) ⇒ Object
Opens a new window and returns its last instantiated tab.(The first ‘tab’ in the window).
193 194 195 196 197 198 199 200 201 |
# File 'lib/consular/terminator.rb', line 193 def open_window( = nil) windowid_before = active_terminator_window send_keypress(active_terminator_window, "ctrl+shift+i") # wait for the active window to change -> new window opened while active_terminator_window == windowid_before sleep 1 end return (@tabidx = 0) end |
#prepend_befores(commands, befores = nil) ⇒ Array<String>
Prepends the :before commands to the current context’s commands if it exists.
136 137 138 139 140 141 142 |
# File 'lib/consular/terminator.rb', line 136 def prepend_befores(commands, befores = nil) unless befores.nil? || befores.empty? commands.insert(0, befores).flatten! else commands end end |
#process! ⇒ Object
Method called by runner to execute Termfile.
55 56 57 58 59 60 |
# File 'lib/consular/terminator.rb', line 55 def process! windows = @termfile[:windows] default = windows.delete('default') execute_window(default, :default => true) unless default[:tabs].empty? windows.each_pair { |_, cont| execute_window(cont) } end |
#set_title(title, commands) ⇒ Object
Prepend a title setting command prior to the other commands.
119 120 121 122 |
# File 'lib/consular/terminator.rb', line 119 def set_title(title, commands) cmd = "PS1=\"$PS1\\[\\e]2;#{title}\\a\\]\"" title ? commands.insert(0, cmd) : commands end |
#setup! ⇒ Object
Method called by runner to Execute Termfile setup.
48 49 50 |
# File 'lib/consular/terminator.rb', line 48 def setup! @termfile[:setup].each { |cmd| execute_command(cmd, :in => active_window) } end |