Sha256: 8c275cbcf83d1ad6b445492b1cb7ccb9feeb724d818a45b78284a807134910ae

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module TTYtest
  module Tmux
    # tmux session manager
    class Session
      # @api private
      def initialize(driver, name)
        @driver = driver
        @name = name

        # ObjectSpace.define_finalizer(self, self.class.finalize(driver, name))
      end

      # @api private
      # def self.finalize(driver, name)
      #   proc { driver.tmux(*%W[kill-session -t #{name}]) }
      # end

      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

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

      private

      attr_reader :driver, :name
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ttytest2-0.8.1 lib/ttytest/tmux/session.rb