Class: Teamocil::Tmux::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/teamocil/tmux/session.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Session

Returns a new instance of Session.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/teamocil/tmux/session.rb', line 4

def initialize(object)
  super

  # Sessions need a name
  self.name = "teamocil-session-#{rand(1_000_000)}" unless name

  self.windows = windows.each_with_index.map do |window, index|
    # Windows need to know their position
    window.merge! index: index

    Teamocil::Tmux::Window.new(window)
  end
end

Instance Method Details

#as_tmuxObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/teamocil/tmux/session.rb', line 18

def as_tmux
  [].tap do |tmux|
    tmux << Teamocil::Command::RenameSession.new(name: name)
    tmux << windows.map(&:as_tmux)

    # Set the focus on the right window or do nothing
    focused_window = windows.find(&:focus)
    tmux << Teamocil::Command::SelectWindow.new(index: focused_window.internal_index) if focused_window
  end.flatten
end