module Powerplay::Play::Tmux

Public Class Methods

current_tty() click to toggle source
# File lib/ansible-powerplay/powerplay.rb, line 12
def self.current_tty
  %x[tty].chop
end
grab_a_tty() click to toggle source

thread-safe way to grab a new tty

# File lib/ansible-powerplay/powerplay.rb, line 58
def self.grab_a_tty
  tty = nil
  CRITICAL.synchronize {
    @@tty_count ||= -1
    @@tty_count = (@@tty_count+1) % pane_ttys.size
    tty = pane_ttys.values[@@tty_count]
  }
  tty
end
list_of_pane_indices() click to toggle source

Either this list is empty, or a list of window indices that was passed in from command-line.

# File lib/ansible-powerplay/powerplay.rb, line 18
def self.list_of_pane_indices
  @slst ||= Play::clopts[:tmux].split(':')[1]
  @lst ||= unless @slst.nil?
             @slst
               .split(',')
               .map{ |n| n.to_i }
           else
             []
           end
end
pane_ttys() click to toggle source

Get a list of the ptys Note that this code is a bit innefficient, but will only be executed once in the loop.

# File lib/ansible-powerplay/powerplay.rb, line 32
def self.pane_ttys
  @window = if Play::clopts.nil? or Play::clopts[:tmux].nil? or Play::clopts[:tmux].split(':').first.to_i == 0
              ''
            else
              " -t #{Play::clopts[:tmux].split(':').first} "
            end
  @ptys ||= if Play::clopts[:ttys]
              Play::clopts[:ttys]
            elsif Play::clopts.nil? or Play::clopts[:tmux]
              %x[tmux list-panes #{@window} -F '\#{pane_index}:\#{pane_tty},']
                .inspect
                .chop
                .split(',')
                .map{ |s| s.strip.sub(/\\n|\"/, '') }
                .reject{ |pty| pty == '' }
                .map{ |s| s.split(':') }
                .reject{ |idx,pty| pty == '' }
                .map{ |i,t| [i.to_i, t] }
                .reject{ |i,pty| not (list_of_pane_indices.empty? or list_of_pane_indices.member?(i)) }
                .to_h
            else
              {nur: current_tty}
            end        
end