Sha256: 05d873e61adf3b89c6394de8fde1e129965e881bf8009f4e020a596e4daa23fd

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module Nutella
  
  class Tmux
  
    def initialize( run_id )
      @run_id = run_id
    end
  
    def new_bot_window( bot )
      if defined? @sessions
        # If a session already exists,
        # simply create a new window for 'bot'.
        # -k destroys the window if it can't be created
        # Print info about creation of window
        `tmux new-window -kP -n #{bot} &> /dev/null`
        @sessions.push bot
      else
        # If there is no sessions, let's create one and, at the same time, create a new window for the bot
        `tmux new-session -d -s #{@run_id} -n #{bot} &> /dev/null`
        @sessions = [bot]
      end
      # Select window
    	`tmux select-window -t #{@run_id}:#{@sessions.length-1} &> /dev/null`
      # Start bot
      `tmux send-keys "cd bots/#{bot};./startup #{@run_id} #{Nutella.config['broker']}" C-m`
    end

    def self.kill_session( run_id )
      `tmux kill-session -t #{run_id} &> /dev/null`
    end

    def self.session_exist?( run_id )
      system( "tmux has-session -t #{run_id} &> /dev/null" )
    end
      
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nutella_framework-0.3.1 lib/core/tmux.rb
nutella_framework-0.3.0 lib/core/tmux.rb