Class: Tmux::Pane

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/tmux/pane.rb

Overview

A window occupies the entire screen and may be split into rectangular panes, each of which is a separate pseudo terminal (the pty(4) manual page documents the technical details of pseudo terminals).

Instance Attribute Summary collapse

Modes collapse

Killing collapse

Input collapse

Selecting collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, number) ⇒ Pane



13
14
15
# File 'lib/tmux/pane.rb', line 13

def initialize(window, number)
  @window, @number = window, number
end

Instance Attribute Details

#activeBoolean (readonly) Also known as: active?

Returns True if the pane is the currently selected one in its window.

Required tmux version:

  • >=1.4



106
107
108
109
110
# File 'lib/tmux/pane.rb', line 106

def active
  server.check_for_version!("1.4")

  @window.panes_information[@number][:active]
end

#current_history_sizeInteger (readonly)

Required tmux version:

  • >=1.1



85
86
87
88
89
# File 'lib/tmux/pane.rb', line 85

def current_history_size
  server.check_for_version!("1.1")

  @window.panes_information[@number][:cur_history]
end

#heightInteger (readonly)

Required tmux version:

  • >=1.1



65
66
67
68
69
# File 'lib/tmux/pane.rb', line 65

def height
  server.check_for_version!("1.1")

  @window.panes_information[@number][:height]
end

#identifierString (readonly)



47
48
49
# File 'lib/tmux/pane.rb', line 47

def identifier
  @window.identifier + "." + @number.to_s
end

#max_history_sizeInteger (readonly)

Required tmux version:

  • >=1.1



75
76
77
78
79
# File 'lib/tmux/pane.rb', line 75

def max_history_size
  server.check_for_version!("1.1")

  @window.panes_information[@number][:max_history]
end

#memory_usageFilesize (readonly)

Required tmux version:

  • >=1.1



95
96
97
98
99
# File 'lib/tmux/pane.rb', line 95

def memory_usage
  server.check_for_version!("1.1")

  @window.panes_information[@number][:memory]
end

#numberNumber (readonly)



12
13
14
# File 'lib/tmux/pane.rb', line 12

def number
  @number
end

#serverServer (readonly)



40
41
42
# File 'lib/tmux/pane.rb', line 40

def server
  @window.server
end

#widthInteger (readonly)

Required tmux version:

  • >=1.1



55
56
57
58
59
# File 'lib/tmux/pane.rb', line 55

def width
  server.check_for_version!("1.1")

  @window.panes_information[@number][:width]
end

#windowWindow (readonly)



10
11
12
# File 'lib/tmux/pane.rb', line 10

def window
  @window
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

Breaks the pane off from its containing window to make it the only pane in a new window.

tmux command:

  • break-pane

Required tmux version:

  • >=1.0



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 = @window.session.any_client.message_stdout("#I:#P").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.

tmux command:

  • clear-history

Required tmux version:

  • >=1.0



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.

tmux command:

  • clock-mode

Required tmux version:

  • >=1.0



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.

tmux command:

  • copy-mode

Required tmux version:

  • >=1.0



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

#hashNumber



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.

Options Hash (args):

  • :make_active (Boolean) — default: true

    Switch to the newly generated pane

  • :direction (Symbol<:vertical, :horizontal>) — default: :vertical

    The direction to split in

  • :size (Number)

    Size of the new pane in lines (for vertical split) or in cells (for horizontal split)

  • :percentage (Number)

    Size of the new pane in percent.



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 = @window.session.any_client.message_stdout("#P")
    return Pane.new(@window, num)
  else
    return nil
  end
end

#kill

This method returns an undefined value.

Kills the pane.

tmux command:

  • kill-pane

Required tmux version:

  • >=1.0



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.

tmux command:

  • kill-pane -a

Required tmux version:

  • >=1.1



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.

See Also:

tmux command:

  • paste-buffer

Required tmux version:

  • >=1.3



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.

Raises:

  • (ArgumentError)


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.

Required tmux version:

  • >=1.0



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.

Required tmux version:

  • >=1.0



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?

Raises:

  • (ArgumentError)

Required tmux version:

  • >=1.3



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?

See Also:

Required tmux version:

  • >=1.3



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?

See Also:

Required tmux version:

  • >=1.3



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?

tmux command:

  • down-pane or select-pane -t:+

Required tmux version:

  • >=1.3 for num parameter



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?

tmux command:

  • up-pane or select-pane -t:-

Required tmux version:

  • >=1.3 for num parameter



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?

See Also:

Required tmux version:

  • >=1.3



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?

See Also:

Required tmux version:

  • >=1.3



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.

See Also:

Required tmux version:

  • >=1.0



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.

Required tmux version:

  • >=1.0



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.

Options Hash (args):

  • :make_active (Boolean) — default: true

    Switch to the newly generated pane

  • :direction (Symbol<:vertical, :horizontal>) — default: :vertical

    The direction to split in

  • :size (Number)

    Size of the new pane in lines (for vertical split) or in cells (for horizontal split)

  • :percentage (Number)

    Size of the new pane in percent.

  • :command (String)

    Command to run in the new pane (optional)

tmux command:

  • split-window

Required tmux version:

  • >=1.2



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 = @window.session.any_client.message_stdout("#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]

Raises:

  • (ArgumentError)


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.

Required tmux version:

  • >=1.0



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.

See Also:

Required tmux version:

  • >=1.0



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