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'
- DEFAULT_CONFING_FILE_PATH =
File.('../tmux.conf', __FILE__)
- 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_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.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ttytest/tmux/driver.rb', line 20 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
51 52 53 |
# File 'lib/ttytest/tmux/driver.rb', line 51 def available? @available ||= (Gem::Version.new(tmux_version) >= Gem::Version.new(REQUIRED_TMUX_VERSION)) end |
#new_terminal(cmd, width: 80, height: 24) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/ttytest/tmux/driver.rb', line 32 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.
42 43 44 45 46 47 48 49 |
# File 'lib/ttytest/tmux/driver.rb', line 42 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 |