Class: TTYtest::Tmux::Session
- Inherits:
-
Object
- Object
- TTYtest::Tmux::Session
- Defined in:
- lib/ttytest/tmux/session.rb
Overview
represents a tmux session and how to send output to the current tmux session
Instance Method Summary collapse
-
#capture ⇒ Object
private
def self.finalize(driver, name) proc { driver.tmux(*%W[kill-session -t ##name]) } end.
-
#initialize(driver, name) ⇒ Session
constructor
private
A new instance of Session.
- #send_backspace ⇒ Object
- #send_backspaces(number_of_times) ⇒ Object
- #send_delete ⇒ Object
- #send_deletes(number_of_times) ⇒ Object
- #send_down_arrow ⇒ Object
- #send_down_arrows(number_of_times) ⇒ Object
-
#send_keys(*keys) ⇒ Object
Send the array of keys as a string literal to tmux.
-
#send_keys_exact(keys) ⇒ Object
Useful to send send-keys commands to tmux without sending them as a string literal.
-
#send_keys_one_at_a_time(keys) ⇒ Object
Send a string of keys one character at a time as literals to tmux.
- #send_left_arrow ⇒ Object
- #send_left_arrows(number_of_times) ⇒ Object
- #send_newline ⇒ Object
- #send_newlines(number_of_times) ⇒ Object
- #send_right_arrow ⇒ Object
- #send_right_arrows(number_of_times) ⇒ Object
- #send_up_arrow ⇒ Object
- #send_up_arrows(number_of_times) ⇒ Object
Constructor Details
#initialize(driver, name) ⇒ Session
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Session.
8 9 10 11 12 13 |
# File 'lib/ttytest/tmux/session.rb', line 8 def initialize(driver, name) @driver = driver @name = name # ObjectSpace.define_finalizer(self, self.class.finalize(driver, name)) end |
Instance Method Details
#capture ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
def self.finalize(driver, name)
proc { driver.tmux(*%W[kill-session -t #{name}]) }
end
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ttytest/tmux/session.rb', line 20 def capture contents = driver.tmux(*%W[capture-pane -t #{name} -p]) str = driver.tmux(*%W[display-message -t #{name} -p #\{cursor_x},#\{cursor_y},#\{cursor_flag},#\{pane_width},#\{pane_height},#\{pane_dead},#\{pane_dead_status},]) x, y, cursor_flag, width, height, pane_dead, pane_dead_status, _newline = str.split(',') if pane_dead == '1' raise Driver::TmuxError, "Tmux pane has died\nCommand exited with status: #{pane_dead_status}\nEntire screen:\n#{contents}" end TTYtest::Capture.new( contents.chomp("\n"), cursor_x: x.to_i, cursor_y: y.to_i, width: width.to_i, height: height.to_i, cursor_visible: (cursor_flag != '0') ) end |
#send_backspace ⇒ Object
78 79 80 |
# File 'lib/ttytest/tmux/session.rb', line 78 def send_backspace send_keys_exact(%(BSpace)) end |
#send_backspaces(number_of_times) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/ttytest/tmux/session.rb', line 82 def send_backspaces(number_of_times) while number_of_times.positive? send_backspace number_of_times -= 1 end end |
#send_delete ⇒ Object
67 68 69 |
# File 'lib/ttytest/tmux/session.rb', line 67 def send_delete send_keys_exact(%(DC)) end |
#send_deletes(number_of_times) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/ttytest/tmux/session.rb', line 71 def send_deletes(number_of_times) while number_of_times.positive? send_delete number_of_times -= 1 end end |
#send_down_arrow ⇒ Object
122 123 124 |
# File 'lib/ttytest/tmux/session.rb', line 122 def send_down_arrow send_keys(TTYtest::DOWN_ARROW) end |
#send_down_arrows(number_of_times) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/ttytest/tmux/session.rb', line 126 def send_down_arrows(number_of_times) while number_of_times.positive? send_down_arrow number_of_times -= 1 end end |
#send_keys(*keys) ⇒ Object
Send the array of keys as a string literal to tmux. Will not be interpreted as send-keys values like Enter, Escape, DC for Delete, etc.
44 45 46 |
# File 'lib/ttytest/tmux/session.rb', line 44 def send_keys(*keys) driver.tmux(*%W[send-keys -t #{name} -l], *keys) end |
#send_keys_exact(keys) ⇒ Object
Useful to send send-keys commands to tmux without sending them as a string literal. So you can send Escape for escape key, DC for delete, etc. Uses the same key bindings as bind-key as well. C-c represents Ctrl + C keys, F1 is F1 key, etc.
137 138 139 |
# File 'lib/ttytest/tmux/session.rb', line 137 def send_keys_exact(keys) driver.tmux(*%W[send-keys -t #{name}], keys) end |
#send_keys_one_at_a_time(keys) ⇒ Object
Send a string of keys one character at a time as literals to tmux.
50 51 52 53 54 |
# File 'lib/ttytest/tmux/session.rb', line 50 def send_keys_one_at_a_time(keys) keys.split('').each do |key| driver.tmux(*%W[send-keys -t #{name} -l], key) end end |
#send_left_arrow ⇒ Object
100 101 102 |
# File 'lib/ttytest/tmux/session.rb', line 100 def send_left_arrow send_keys(TTYtest::LEFT_ARROW) end |
#send_left_arrows(number_of_times) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/ttytest/tmux/session.rb', line 104 def send_left_arrows(number_of_times) while number_of_times.positive? send_left_arrow number_of_times -= 1 end end |
#send_newline ⇒ Object
56 57 58 |
# File 'lib/ttytest/tmux/session.rb', line 56 def send_newline driver.tmux(*%W[send-keys -t #{name} -l], %(\n)) end |
#send_newlines(number_of_times) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/ttytest/tmux/session.rb', line 60 def send_newlines(number_of_times) while number_of_times.positive? send_newline number_of_times -= 1 end end |
#send_right_arrow ⇒ Object
89 90 91 |
# File 'lib/ttytest/tmux/session.rb', line 89 def send_right_arrow send_keys(TTYtest::RIGHT_ARROW) end |
#send_right_arrows(number_of_times) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/ttytest/tmux/session.rb', line 93 def send_right_arrows(number_of_times) while number_of_times.positive? send_right_arrow number_of_times -= 1 end end |
#send_up_arrow ⇒ Object
111 112 113 |
# File 'lib/ttytest/tmux/session.rb', line 111 def send_up_arrow send_keys(TTYtest::UP_ARROW) end |
#send_up_arrows(number_of_times) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/ttytest/tmux/session.rb', line 115 def send_up_arrows(number_of_times) while number_of_times.positive? send_up_arrow number_of_times -= 1 end end |