Class: TTYtest::Tmux::Driver
- Inherits:
-
Object
- Object
- TTYtest::Tmux::Driver
- Defined in:
- lib/ttytest/tmux/driver.rb
Defined Under Namespace
Classes: TmuxError
Constant Summary collapse
- COMMAND =
'tmux'- SOCKET_NAME =
'ttytest'- REQUIRED_TMUX_VERSION =
'1.8'- CONF_PATH =
File.('../tmux.conf', __FILE__)
- SLEEP_INFINITY =
'read x < /dev/fd/1'
Instance Method Summary collapse
- #available? ⇒ Boolean
- #debug? ⇒ Boolean
-
#initialize(debug: false, command: COMMAND, socket_name: SOCKET_NAME) ⇒ Driver
constructor
A new instance of Driver.
- #new_terminal(cmd, width: 80, height: 24) ⇒ Object
- #tmux(*args) ⇒ Object
Constructor Details
#initialize(debug: false, command: COMMAND, socket_name: SOCKET_NAME) ⇒ Driver
Returns a new instance of Driver.
20 21 22 23 24 |
# File 'lib/ttytest/tmux/driver.rb', line 20 def initialize(debug: false, command: COMMAND, socket_name: SOCKET_NAME) @debug = debug @tmux_cmd = command @socket_name = socket_name end |
Instance Method Details
#available? ⇒ Boolean
44 45 46 |
# File 'lib/ttytest/tmux/driver.rb', line 44 def available? @available ||= (Gem::Version.new(tmux_version) >= Gem::Version.new(REQUIRED_TMUX_VERSION)) end |
#debug? ⇒ Boolean
48 49 50 |
# File 'lib/ttytest/tmux/driver.rb', line 48 def debug? @debug end |
#new_terminal(cmd, width: 80, height: 24) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/ttytest/tmux/driver.rb', line 26 def new_terminal(cmd, width: 80, height: 24) cmd = "#{cmd};#{SLEEP_INFINITY}" session_name = "ttytest-#{SecureRandom.uuid}" tmux(*%W[-f #{CONF_PATH} new-session -s #{session_name} -d -x #{width} -y #{height} #{cmd}]) session = Session.new(self, session_name) Terminal.new(session) end |
#tmux(*args) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/ttytest/tmux/driver.rb', line 35 def tmux(*args) ensure_available puts "tmux(#{args.inspect[1...-1]})" if debug? stdout, stderr, status = Open3.capture3(@tmux_cmd, '-L', SOCKET_NAME, *args) raise TmuxError, "tmux(#{args.inspect[1...-1]}) failed\n#{stderr}" unless status.success? stdout end |