Class: Terminal::Multiplexer

Inherits:
Object
  • Object
show all
Includes:
Exceptions
Defined in:
lib/terminal-multiplexer.rb

Instance Method Summary collapse

Constructor Details

#initializeMultiplexer

Returns a new instance of Multiplexer.



12
13
14
# File 'lib/terminal-multiplexer.rb', line 12

def initialize
  @sessions = []
end

Instance Method Details

#active_window(num) ⇒ Object

Set the active window in that session



66
67
68
69
70
# File 'lib/terminal-multiplexer.rb', line 66

def active_window(num)
  # the active window will always be set for the last defined session
  session = get_last_session
  session.active_window(num)
end

#new_session(options = {}) ⇒ Object

Creates a new tmux session



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/terminal-multiplexer.rb', line 21

def new_session(options={})

  options = { 
    :session_name => 'default',
    :window_name => 'tab',
    :command => 'zsh'
  }.update options

  if @sessions.find { |s| s.session_name == options[:session_name] }
    raise DuplicateSessionIdentifier , "Please do not reuse the session identifier. You used \"#{options[:session_name]}\" at least twice."
  end

  session = Session.new(options[:session_name], options[:window_name], options[:command])
  @sessions <<  session
  session
end

#new_window(options = {}) ⇒ Object

Creates a new tmux window



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/terminal-multiplexer.rb', line 42

def new_window(options={})

  options = { 
    :name => 'tab',
    :command => 'zsh'
  }.update options

  # windows will be attached to the last session defined
  session = get_last_session

  #if no sessions have been created, create a new one
  if session == nil
    say "Warning: No valid session found. Create a default one"
    session = new_session
  end
 
  #windows belong to a session
  session.add_window Window.new( options[:name] , options[:command] )

end

#start(process_info = {}) ⇒ Object

Start tmux



92
93
94
95
96
97
# File 'lib/terminal-multiplexer.rb', line 92

def start(process_info={})

  process_info[:cmd] = 'tmux'
  process_info[:status] = system("#{process_info[:cmd]} #{build_multiplexer_command_string} attach") 

end