Class: TTYtest::Tmux::Driver
- Inherits:
-
Object
- Object
- TTYtest::Tmux::Driver
- Defined in:
- lib/ttytest/tmux/driver.rb
Overview
tmux driver
Defined Under Namespace
Classes: TmuxError
Constant Summary collapse
- COMMAND =
'tmux'- SOCKET_NAME =
'ttytest'- REQUIRED_TMUX_VERSION =
'1.8'- DEFAULT_CONFING_FILE_PATH =
File.('tmux.conf', __dir__)
- SLEEP_INFINITY =
'read x < /dev/fd/1'
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#initialize(debug: false, command: COMMAND, socket_name: SOCKET_NAME, config_file_path: DEFAULT_CONFING_FILE_PATH) ⇒ Driver
constructor
A new instance of Driver.
- #new_default_sh_terminal ⇒ Object
- #new_sh_terminal(width: 80, height: 24) ⇒ Object
- #new_terminal(cmd, width: 80, height: 24) ⇒ Object
- #tmux(*args) ⇒ Object private
Constructor Details
#initialize(debug: false, command: COMMAND, socket_name: SOCKET_NAME, config_file_path: DEFAULT_CONFING_FILE_PATH) ⇒ Driver
Returns a new instance of Driver.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ttytest/tmux/driver.rb', line 21 def initialize( debug: false, command: COMMAND, socket_name: SOCKET_NAME, config_file_path: DEFAULT_CONFING_FILE_PATH ) @debug = debug @tmux_cmd = command @socket_name = socket_name @config_file_path = config_file_path end |
Instance Method Details
#available? ⇒ Boolean
61 62 63 64 65 |
# File 'lib/ttytest/tmux/driver.rb', line 61 def available? return false unless tmux_version @available ||= (Gem::Version.new(tmux_version) >= Gem::Version.new(REQUIRED_TMUX_VERSION)) end |
#new_default_sh_terminal ⇒ Object
42 43 44 |
# File 'lib/ttytest/tmux/driver.rb', line 42 def new_default_sh_terminal new_terminal(%(PS1='$ ' /bin/sh), width: 80, height: 24) end |
#new_sh_terminal(width: 80, height: 24) ⇒ Object
46 47 48 |
# File 'lib/ttytest/tmux/driver.rb', line 46 def new_sh_terminal(width: 80, height: 24) new_terminal(%(PS1='$ ' /bin/sh), width: width, height: height) end |
#new_terminal(cmd, width: 80, height: 24) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/ttytest/tmux/driver.rb', line 33 def new_terminal(cmd, width: 80, height: 24) cmd = "#{cmd}\n#{SLEEP_INFINITY}" session_name = "ttytest-#{SecureRandom.uuid}" tmux(*%W[-f #{@config_file_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
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.
51 52 53 54 55 56 57 58 59 |
# File 'lib/ttytest/tmux/driver.rb', line 51 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.nil? && status.success? stdout end |