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

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

#activeBoolean (readonly) Also known as: active?

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

Returns:

  • (Boolean)

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

Required tmux version:

  • >=1.4



104
105
106
# File 'lib/tmux/pane.rb', line 104

def active
  @active
end

#current_history_sizeInteger (readonly)

Returns:

  • (Integer)

Required tmux version:

  • >=1.1



83
84
85
# File 'lib/tmux/pane.rb', line 83

def current_history_size
  @current_history_size
end

#heightInteger (readonly)

Returns:

  • (Integer)

Required tmux version:

  • >=1.1



63
64
65
# File 'lib/tmux/pane.rb', line 63

def height
  @height
end

#identifierString (readonly)

Returns:

  • (String)


45
46
47
# File 'lib/tmux/pane.rb', line 45

def identifier
  @identifier
end

#max_history_sizeInteger (readonly)

Returns:

  • (Integer)

Required tmux version:

  • >=1.1



73
74
75
# File 'lib/tmux/pane.rb', line 73

def max_history_size
  @max_history_size
end

#memory_usageFilesize (readonly)

Returns:

  • (Filesize)

Required tmux version:

  • >=1.1



93
94
95
# File 'lib/tmux/pane.rb', line 93

def memory_usage
  @memory_usage
end

#numberNumber (readonly)

Returns:

  • (Number)


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

def number
  @number
end

#serverServer (readonly)

Returns:



38
39
40
# File 'lib/tmux/pane.rb', line 38

def server
  @server
end

#widthInteger (readonly)

Returns:

  • (Integer)

Required tmux version:

  • >=1.1



53
54
55
# File 'lib/tmux/pane.rb', line 53

def width
  @width
end

#windowWindow (readonly)

Returns:



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

Returns:

  • (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.

Parameters:

  • select (Boolean) (defaults to: true)

    If true, the new window will be selected automatically

Returns:

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 = 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.

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/tmux/pane.rb', line 28

def eql?(other)
  self == other
end

#hashNumber

Returns:

  • (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.

Parameters:

  • pane (Pane)

    The pane to join

  • args (Hash) (defaults to: {})

    a customizable set of options

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 = 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.

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.

Parameters:

  • buffer (Buffer)

    The buffer to paste

  • pop (Boolean) (defaults to: false)

    If true, delete the buffer from the stack

  • translate (Boolean) (defaults to: true)

    If true, any linefeed (LF) characters in the paste buffer are replaced with carriage returns (CR)

  • separator (String) (defaults to: nil)

    Replace any linefeed (LF) in the buffer with this separator. +translate+ must be false.

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.

Parameters:

  • direction (Symbol<:up, :down, :left, :right>)

    Direction in which to resize

  • adjustment (Number) (defaults to: 1)

    How many lines or cells to resize.

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.

Parameters:

  • command (String)

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?

Parameters:

  • direction (Symbol<:up, :down, :left, :right>)

    direction to move to

  • return_new (Symbol<:never, :if_same_window, :always>) (defaults to: :if_same_window)

    whether to return the pane we moved to.

    Note: In tmux versions prior to 1.4, :always can lead to flickering Note: Since tmux version 1.4, :always is forced

Returns:

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?

Parameters:

  • return_new (Symbol<:never, :if_same_window, :always>) (defaults to: :if_same_window)

    whether to return the pane we moved to.

    Note: In tmux versions prior to 1.4, :always can lead to flickering Note: Since tmux version 1.4, :always is forced

Returns:

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?

Parameters:

  • return_new (Symbol<:never, :if_same_window, :always>) (defaults to: :if_same_window)

    whether to return the pane we moved to.

    Note: In tmux versions prior to 1.4, :always can lead to flickering Note: Since tmux version 1.4, :always is forced

Returns:

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?

Parameters:

  • num (Number) (defaults to: 1)

    how many panes to move down. Note: will be ignored on tmux versions <1.3

  • return_new (Symbol<:never, :if_same_window, :always>) (defaults to: :if_same_window)

    whether to return the pane we moved to.

    Note: In tmux versions prior to 1.4, :always can lead to flickering Note: Since tmux version 1.4, :always is forced

Returns:

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?

Parameters:

  • num (Number) (defaults to: 1)

    how many panes to move up. Note: will be ignored on tmux versions <1.3

  • return_new (Symbol<:never, :if_same_window, :always>) (defaults to: :if_same_window)

    whether to return the pane we moved to.

    Note: In tmux versions prior to 1.4, :always can lead to flickering Note: Since tmux version 1.4, :always is forced

Returns:

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?

Parameters:

  • return_new (Symbol<:never, :if_same_window, :always>) (defaults to: :if_same_window)

    whether to return the pane we moved to.

    Note: In tmux versions prior to 1.4, :always can lead to flickering Note: Since tmux version 1.4, :always is forced

Returns:

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?

Parameters:

  • return_new (Symbol<:never, :if_same_window, :always>) (defaults to: :if_same_window)

    whether to return the pane we moved to.

    Note: In tmux versions prior to 1.4, :always can lead to flickering Note: Since tmux version 1.4, :always is forced

Returns:

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.

Parameters:

  • key (String)

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.

Parameters:

  • keys (Array<String>)

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.

Parameters:

  • args (Hash) (defaults to: {})

    a customizable set of options

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)

Returns:

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 = 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]

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.

Parameters:

  • pane (Pane)

    The pane to swap with.

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.

Parameters:

  • text (String)

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