Class: Teamocil::Tmux::Window

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Window

Returns a new instance of Window.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/teamocil/tmux/window.rb', line 4

def initialize(object)
  super

  # Make sure paths like `~/foo/bar` work
  self.root = File.expand_path(root) if root

  self.options ||= {}
  self.panes ||= []
  self.panes = panes.each_with_index.map do |pane, index|
    # Support single command instead of `commands` key in Hash
    pane = { commands: [pane] } if pane.is_a?(String)

    # Panes need to know their position
    pane.merge! index: index

    # Panes need to know the window root directory
    pane.merge! root: root

    # Panes need to know the window layout
    pane.merge! layout: layout

    # Panes need to know the window name
    pane.merge! name: name

    Teamocil::Tmux::Pane.new(pane)
  end
end

Class Method Details

.window_base_indexObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/teamocil/tmux/window.rb', line 53

def self.window_base_index
  @window_base_index ||= begin
    base_index = Teamocil::Tmux.option('base-index', default: 0)
    current_window_count = Teamocil::Tmux.window_count

    # If `--here` is specified, treat the current window as a new one
    current_window_count -= 1 if Teamocil.options[:here]

    base_index + current_window_count
  end
end

Instance Method Details

#as_tmuxObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/teamocil/tmux/window.rb', line 32

def as_tmux
  [].tap do |tmux|
    # Create a new window or use the current one
    tmux << spawn_window_commands

    # Set specific window options
    tmux << set_window_options_commands

    # Execute all panes commands
    tmux << panes.map(&:as_tmux).flatten

    # Set the focus on the right pane or the first one
    tmux << focus_pane_commands

  end.flatten
end

#internal_indexObject



49
50
51
# File 'lib/teamocil/tmux/window.rb', line 49

def internal_index
  index + self.class.window_base_index
end