Class: Tmux::Pane
Overview
Instance Attribute Summary collapse
-
#active ⇒ Boolean
(also: #active?)
readonly
True if the pane is the currently selected one in its window.
- #current_history_size ⇒ Integer readonly
- #height ⇒ Integer readonly
- #identifier ⇒ String readonly
- #max_history_size ⇒ Integer readonly
- #memory_usage ⇒ Filesize readonly
- #number ⇒ Number readonly
- #server ⇒ Server readonly
- #width ⇒ Integer readonly
- #window ⇒ Window readonly
Modes collapse
-
#clock_mode
(also: #show_clock)
Displays a clock in the pane.
-
#copy_mode
Enter copy mode.
Killing collapse
-
#kill
Kills the pane.
-
#kill_others
Kills all other panes.
Input collapse
-
#paste(buffer, pop = false, translate = true, separator = nil)
Pastes a buffer into the pane.
-
#run(command)
Runs a command in the pane.
-
#send_key(key)
Sends a key to the pane.
-
#send_keys(keys)
Sends keys to the pane.
-
#write(text)
Writes text to the pane.
Selecting collapse
-
#select
Selects the pane.
- #select_direction(direction, return_new = :if_same_window) ⇒ Pane?
- #select_down(return_new = :if_same_window) ⇒ Pane?
- #select_left(return_new = :if_same_window) ⇒ Pane?
- #select_next(num = 1, return_new = :if_same_window) ⇒ Pane?
- #select_previous(num = 1, return_new = :if_same_window) ⇒ Pane?
- #select_right(return_new = :if_same_window) ⇒ Pane?
- #select_up(return_new = :if_same_window) ⇒ Pane?
Instance Method Summary collapse
- #<=>(other) ⇒ Undefined
- #==(other) ⇒ Boolean
- #break(select = true) ⇒ Pane
-
#clear_history
Removes and frees the history of the pane.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Number
-
#initialize(window, number) ⇒ Pane
constructor
A new instance of Pane.
-
#join(pane, args = {}) ⇒ Undefined
Split the pane and move an existing pane into the new area.
-
#resize(direction, adjustment = 1)
Resizes the pane.
-
#split(args = {}) ⇒ Pane?
Splits the pane.
-
#split_or_join_flags(args) ⇒ Undefined
private
join-pane [-dhv] [-l size | -p percentage] [-s src-pane] [-t dst-pane] split-window [-dhv] [-l size | -p percentage] [-t target-pane] [shell-command].
-
#swap_with(pane)
Swaps the pane with another one.
Constructor Details
#initialize(window, number) ⇒ Pane
Returns a new instance of Pane.
13 14 15 |
# File 'lib/tmux/pane.rb', line 13 def initialize(window, number) @window, @number = window, number end |
Instance Attribute Details
#active ⇒ Boolean (readonly) Also known as: active?
Returns True if the pane is the currently selected one in its window.
104 105 106 |
# File 'lib/tmux/pane.rb', line 104 def active @active end |
#current_history_size ⇒ Integer (readonly)
83 84 85 |
# File 'lib/tmux/pane.rb', line 83 def current_history_size @current_history_size end |
#height ⇒ Integer (readonly)
63 64 65 |
# File 'lib/tmux/pane.rb', line 63 def height @height end |
#identifier ⇒ String (readonly)
45 46 47 |
# File 'lib/tmux/pane.rb', line 45 def identifier @identifier end |
#max_history_size ⇒ Integer (readonly)
73 74 75 |
# File 'lib/tmux/pane.rb', line 73 def max_history_size @max_history_size end |
#memory_usage ⇒ Filesize (readonly)
93 94 95 |
# File 'lib/tmux/pane.rb', line 93 def memory_usage @memory_usage end |
#number ⇒ Number (readonly)
12 13 14 |
# File 'lib/tmux/pane.rb', line 12 def number @number end |
#width ⇒ Integer (readonly)
53 54 55 |
# File 'lib/tmux/pane.rb', line 53 def width @width end |
Instance Method Details
#<=>(other) ⇒ Undefined
32 33 34 35 |
# File 'lib/tmux/pane.rb', line 32 def <=>(other) return nil unless other.is_a?(Pane) [@window, @number] <=> [other.window, other.number] end |
#==(other) ⇒ Boolean
18 19 20 |
# File 'lib/tmux/pane.rb', line 18 def ==(other) self.class == other.class && @window == other.window && @number = other.number end |
#break(select = true) ⇒ Pane
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/tmux/pane.rb', line 148 def break(select = true) server.check_for_version!("1.0") server.invoke_command "break-pane -t #{identifier}" num_window, num_pane = server.invoke_command("display -p -t #{@window.session.any_client.identifier} '#I:#P'").chomp.split(":") session = @window.session window = Window.new(session, num_window) pane = Pane.new(window, num_pane) unless select session.select_last_window end return pane end |
#clear_history
This method returns an undefined value.
Removes and frees the history of the pane.
193 194 195 196 197 |
# File 'lib/tmux/pane.rb', line 193 def clear_history server.check_for_version!("1.0") server.invoke_command "clear-history -t #{identifier}" end |
#clock_mode Also known as: show_clock
This method returns an undefined value.
Displays a clock in the pane.
131 132 133 134 135 |
# File 'lib/tmux/pane.rb', line 131 def clock_mode server.check_for_version!("1.0") server.invoke_command "clock-mode -t #{identifier}" end |
#copy_mode
This method returns an undefined value.
Enter copy mode.
120 121 122 123 124 |
# File 'lib/tmux/pane.rb', line 120 def copy_mode server.check_for_version!("1.0") server.invoke_command "copy-mode -t #{identifier}" end |
#eql?(other) ⇒ Boolean
28 29 30 |
# File 'lib/tmux/pane.rb', line 28 def eql?(other) self == other end |
#hash ⇒ Number
23 24 25 |
# File 'lib/tmux/pane.rb', line 23 def hash [@window.hash, @number].hash end |
#join(pane, args = {}) ⇒ Undefined
Split the pane and move an existing pane into the new area.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/tmux/pane.rb', line 297 def join(pane, args = {}) server.check_for_version!("1.2") args = { :make_active => true, :direction => :vertical, }.merge(args) flags = split_or_join_flags(args) flags << "-s #{pane.identifier}" flags << "-t #{identifier}" server.invoke_command "join-pane #{flags.join(" ")} " if args[:make_active] num = server.invoke_command("display -p -t #{@window.session.any_client.identifier} '#P'").chomp return Pane.new(@window, num) else return nil end end |
#kill
This method returns an undefined value.
Kills the pane.
169 170 171 172 173 |
# File 'lib/tmux/pane.rb', line 169 def kill server.check_for_version!("1.0") server.invoke_command "kill-pane -t #{identifier}" end |
#kill_others
This method returns an undefined value.
Kills all other panes.
180 181 182 183 184 |
# File 'lib/tmux/pane.rb', line 180 def kill_others server.check_for_version!("1.1") server.invoke_command "kill-pane -a -t #{identifier}" end |
#paste(buffer, pop = false, translate = true, separator = nil)
This method returns an undefined value.
Pastes a buffer into the pane.
281 282 283 284 285 |
# File 'lib/tmux/pane.rb', line 281 def paste(buffer, pop = false, translate = true, separator = nil) server.check_for_version!("1.3") buffer.paste(self, pop, translate, separator) end |
#resize(direction, adjustment = 1)
This method returns an undefined value.
Resizes the pane.
398 399 400 401 402 |
# File 'lib/tmux/pane.rb', line 398 def resize(direction, adjustment = 1) raise ArgumentError unless [:up, :down, :left, :right].include?(direction) direction = direction.to_s.upcase[0..0] server.invoke_command "resize-pane -#{direction} -t #{identifier} #{adjustment}" end |
#run(command)
This method returns an undefined value.
Runs a command in the pane. Note: this is experimental, hacky and might and will break.
250 251 252 253 254 255 |
# File 'lib/tmux/pane.rb', line 250 def run(command) server.check_for_version!("1.0") write(command) send_key "Enter" end |
#select
This method returns an undefined value.
Selects the pane.
488 489 490 491 492 |
# File 'lib/tmux/pane.rb', line 488 def select server.check_for_version!("1.0") server.invoke_command "select-pane -t #{identifier}" end |
#select_direction(direction, return_new = :if_same_window) ⇒ Pane?
414 415 416 417 418 419 420 |
# File 'lib/tmux/pane.rb', line 414 def select_direction(direction, return_new = :if_same_window) raise ArgumentError unless [:up, :down, :left, :right].include?(direction) direction = direction.to_s.upcase[0..0] server.invoke_command "select-pane -#{direction} -t #{identifier}" return @window.current_pane(return_new) end |
#select_down(return_new = :if_same_window) ⇒ Pane?
434 435 436 |
# File 'lib/tmux/pane.rb', line 434 def select_down(return_new = :if_same_window) select_direction(:down, return_new) end |
#select_left(return_new = :if_same_window) ⇒ Pane?
442 443 444 |
# File 'lib/tmux/pane.rb', line 442 def select_left(return_new = :if_same_window) select_direction(:left, return_new) end |
#select_next(num = 1, return_new = :if_same_window) ⇒ Pane?
459 460 461 462 463 464 465 466 467 |
# File 'lib/tmux/pane.rb', line 459 def select_next(num = 1, return_new = :if_same_window) if server.version > "1.2" server.invoke_command "select-pane -t #{@window.identifier}.+#{num}" else server.invoke_command "down-pane -t #{identifier}" end return @window.current_pane(return_new) end |
#select_previous(num = 1, return_new = :if_same_window) ⇒ Pane?
474 475 476 477 478 479 480 481 482 |
# File 'lib/tmux/pane.rb', line 474 def select_previous(num = 1, return_new = :if_same_window) if server.version > "1.2" server.invoke_command "select-pane -t #{@window.identifier}.-#{num}" else server.invoke_command "up-pane -t #{identifier}" end return @window.current_pane(return_new) end |
#select_right(return_new = :if_same_window) ⇒ Pane?
450 451 452 |
# File 'lib/tmux/pane.rb', line 450 def select_right(return_new = :if_same_window) select_direction(:right, return_new) end |
#select_up(return_new = :if_same_window) ⇒ Pane?
426 427 428 |
# File 'lib/tmux/pane.rb', line 426 def select_up(return_new = :if_same_window) select_direction(:up, return_new) end |
#send_key(key)
This method returns an undefined value.
Sends a key to the pane.
218 219 220 221 222 |
# File 'lib/tmux/pane.rb', line 218 def send_key(key) server.check_for_version!("1.0") send_keys([key]) end |
#send_keys(keys)
This method returns an undefined value.
Sends keys to the pane.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/tmux/pane.rb', line 229 def send_keys(keys) server.check_for_version!("1.0") keychain = [] keys.each do |key| case key when '"' keychain << '"\\' + key + '"' else keychain << '"' + key + '"' end end server.invoke_command "send-keys -t #{identifier} #{keychain.join(" ")}" end |
#split(args = {}) ⇒ Pane?
Splits the pane.
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/tmux/pane.rb', line 357 def split(args = {}) server.check_for_version!("1.2") args = { :make_active => true, :direction => :vertical, }.merge(args) # Since tmux 1.4 we have the last-pane command, which allows us # to temporarily select the new pane, get its identifer and # select the last pane again. temporarily_make_active = false if server.version >= "1.4" && !args[:make_active] args[:make_active] = true temporarily_make_active = true end flags = split_or_join_flags(args) flags << "-t #{identifier}" flags << '"' + args[:command] + '"' if args[:command] # TODO escape server.invoke_command "split-window #{flags.join(" ")} " if args[:make_active] num = server.invoke_command("display -p -t #{@window.session.any_client.identifier} '#P'").chomp if temporarily_make_active @window.select_last_pane(:never) end return Pane.new(@window, num) else return nil end end |
#split_or_join_flags(args) ⇒ Undefined (private)
join-pane [-dhv] [-l size | -p percentage] [-s src-pane] [-t dst-pane] split-window [-dhv] [-l size | -p percentage] [-t target-pane] [shell-command]
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/tmux/pane.rb', line 319 def split_or_join_flags(args) flags = [] flags << "-d" unless args[:make_active] flags << case args[:direction] when :vertical "-v" when :horizontal "-h" else raise ArgumentError end raise ArgumentError if args[:size] && args[:percentage] if args[:size] flags << "-l #{args[:size]}" elsif args[:percentage] flags << "-p #{args[:percentage]}" end return flags end |
#swap_with(pane)
This method returns an undefined value.
Swaps the pane with another one.
204 205 206 207 208 |
# File 'lib/tmux/pane.rb', line 204 def swap_with(pane) server.check_for_version!("1.0") server.invoke_command "swap-pane -s #{identifier} -t #{pane.identifier}" end |
#write(text)
This method returns an undefined value.
Writes text to the pane. This is basically the same as #run, but without sending a final Return.
264 265 266 267 268 |
# File 'lib/tmux/pane.rb', line 264 def write(text) server.check_for_version!("1.0") send_keys(text.split("")) end |