Class: Xing::Managers::TmuxPane

Inherits:
Tmux
  • Object
show all
Defined in:
lib/xing/managers/tmux.rb

Constant Summary

Constants inherited from Tmux

Xing::Managers::Tmux::MINIMUM_WINDOW_COLUMNS, Xing::Managers::Tmux::MINIMUM_WINDOW_LINES

Instance Attribute Summary collapse

Attributes inherited from Tmux

#shell

Instance Method Summary collapse

Methods inherited from Tmux

available?, #copied_env_vars, #default_env, #env_string, #existing?, #rake_command, #session_env, shell, #tmux, #tmux_exe

Constructor Details

#initialize(shell = nil) ⇒ TmuxPane

Returns a new instance of TmuxPane.



83
84
85
86
87
88
# File 'lib/xing/managers/tmux.rb', line 83

def initialize(shell=nil)
  super
  @window_name = "Dev Servers"
  @pane_count = 0
  @window_count = 1
end

Instance Attribute Details

#window_nameObject

Returns the value of attribute window_name.



89
90
91
# File 'lib/xing/managers/tmux.rb', line 89

def window_name
  @window_name
end

Instance Method Details

#calculate_layoutObject



120
121
122
123
124
125
126
127
128
# File 'lib/xing/managers/tmux.rb', line 120

def calculate_layout
  min_cols = (ENV["XING_TMUX_MIN_COLS"] || MINIMUM_WINDOW_COLUMNS).to_i
  cols = tput_cols
  if cols > min_cols * 2
    "tiled"
  else
    "even-vertical"
  end
end

#calculate_lines_per_windowObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/xing/managers/tmux.rb', line 105

def calculate_lines_per_window
  lines = tput_lines
  min_lines = (ENV["XING_TMUX_MIN_LINES"] || MINIMUM_WINDOW_LINES).to_i
  min_lines = [1, lines / min_lines].max
  if layout == "tiled"
    min_lines * 2
  else
    min_lines
  end
end

#layoutObject



116
117
118
# File 'lib/xing/managers/tmux.rb', line 116

def layout
  @layout ||= calculate_layout
end

#new_window_afterObject



91
92
93
# File 'lib/xing/managers/tmux.rb', line 91

def new_window_after
  @new_window_after ||= calculate_lines_per_window
end

#open_additional_window(_name, task) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/xing/managers/tmux.rb', line 148

def open_additional_window(_name, task)
  tmux "select-layout -t '#@window_name' #{layout}"
  @window_count = @window_count + 1
  @window_name = "Dev Servers #{@window_count}"
  tmux "new-window -d -n '#@window_name' '#{rake_command(task)}' \\; set-window-option remain-on-exit on"
  @pane_count = 0
end

#open_first_window(name, task) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/xing/managers/tmux.rb', line 135

def open_first_window(name, task)
  if tmux('list-windows -F \'#{window_name}\'') =~ /#{name}|#{@window_name}/
    puts "It looks like there are already windows open for this tmux?"
    exit 2
  end

  if existing?
    tmux "new-window -n '#@window_name' '#{rake_command(task)}' \\; set-window-option remain-on-exit on"
  else
    tmux "new-session -d -n '#@window_name' '#{rake_command(task)}' \\; set-window-option remain-on-exit on"
  end
end

#open_new_pane(name, task) ⇒ Object



130
131
132
133
# File 'lib/xing/managers/tmux.rb', line 130

def open_new_pane(name, task)
  tmux "new-window -d -n '#{name}' '#{rake_command(task)}' \\; set-window-option remain-on-exit on"
  tmux "join-pane -d -s '#{name}.0' -t '#{@window_name}.bottom'"
end

#start_child(name, task) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/xing/managers/tmux.rb', line 156

def start_child(name, task)
  if @first_child
    open_first_window(name, task)
  elsif @pane_count >= new_window_after
    open_additional_window(name, task)
  else
    open_new_pane(name, task)
  end
  @pane_count = @pane_count + 1
  @first_child = false
end

#tput_colsObject



101
102
103
# File 'lib/xing/managers/tmux.rb', line 101

def tput_cols
  %x"tput cols".chomp.to_i
end

#tput_linesObject

need to use %x here rather than open a Caliph subshell won’t ahve the same terminal with subshell



97
98
99
# File 'lib/xing/managers/tmux.rb', line 97

def tput_lines
  %x"tput lines".chomp.to_i
end

#wait_allObject



168
169
170
171
# File 'lib/xing/managers/tmux.rb', line 168

def wait_all
  tmux "select-layout -t '#@window_name' #{layout}"
  super
end