class Teamocil::Layout::Window

This class represents a window within tmux

Attributes

clear[R]
filters[R]
index[R]
layout[R]
name[R]
options[R]
panes[R]
root[R]

Public Class Methods

new(session, index, attrs={}) click to toggle source

Initialize a new tmux window

@param session [Session] the session where the window is initialized @param index [Fixnnum] the window index @param attrs [Hash] the window data from the layout file

# File lib/teamocil/layout/window.rb, line 12
def initialize(session, index, attrs={})
  @name = attrs["name"] || "teamocil-window-#{index+1}"
  @root = attrs["root"] || "."
  @clear = attrs["clear"] == true ? "clear" : nil
  @options = attrs["options"] || {}
  @layout = attrs["layout"]

  @panes = attrs["panes"] || attrs["splits"] || []
  raise Teamocil::Error::LayoutError.new("You must specify a `panes` (or legacy `splits`) key for every window.") if @panes.empty?
  @panes = @panes.each_with_index.map { |pane, pane_index| Pane.new(self, pane_index + pane_base_index, pane) }

  @filters = attrs["filters"] || {}
  @filters["before"] ||= []
  @filters["after"] ||= []

  @index = index
  @session = session
end

Public Instance Methods

generate_commands() click to toggle source

Generate commands to send to tmux

@return [Array]

# File lib/teamocil/layout/window.rb, line 34
def generate_commands
  commands = []

  if @session.options.include?(:here) and @index == 0
    commands << "tmux rename-window \"#{@name}\""
  else
    commands << "tmux new-window -n \"#{@name}\""
  end

  pane_commands = @panes.map do |pane|
    c = pane.generate_commands
    c << "tmux select-layout \"#{@layout}\"" if @layout
    c
  end
  commands << pane_commands

  @options.each_pair do |option, value|
    value = "on"  if value === true
    value = "off" if value === false
    commands << "tmux set-window-option #{option} #{value}"
  end

  commands << "tmux select-layout \"#{@layout}\"" if @layout
  commands << "tmux select-pane -t #{@panes.map(&:focus).index(true) || 0}"

  commands
end
pane_base_index() click to toggle source

Return the `pane-base-index` option for the current window

@return [Fixnum]

# File lib/teamocil/layout/window.rb, line 65
def pane_base_index
  @pane_base_index ||= begin
    global_setting = %xtmux show-window-options -g | grep pane-base-index`.split(%r\s/).last
    local_setting = %xtmux show-window-options | grep pane-base-index`.split(%r\s/).last
    (local_setting || global_setting || "0").to_i
  end
end