Class: TTYtest::Tmux::Session

Inherits:
Object
  • Object
show all
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

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

#captureObject

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_keys(*keys) ⇒ Object



41
42
43
# File 'lib/ttytest/tmux/session.rb', line 41

def send_keys(*keys)
  driver.tmux(*%W[send-keys -t #{name} -l], *keys)
end

#send_keys_one_at_a_time(*keys) ⇒ Object



45
46
47
48
49
# File 'lib/ttytest/tmux/session.rb', line 45

def send_keys_one_at_a_time(*keys)
  keys.each do |key|
    driver.tmux(*%W[send-keys -t #{name} -l], key)
  end
end