Class: Tmux::Window

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/tmux/window.rb,
lib/tmux/window/status.rb,
lib/tmux/window/status/state.rb

Overview

TODO:

Figure out better names for some attributes, e.g. mode_mouse

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

Defined Under Namespace

Classes: Status

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, number) ⇒ Window

Returns a new instance of Window.



52
53
54
55
56
# File 'lib/tmux/window.rb', line 52

def initialize(session, number)
  @session, @number = session, number
  @options = OptionsList.new(:window, self, false)
  @status = Status.new(self)
end

Class Attribute Details

.options(server) ⇒ OptionsList (readonly)

Returns:



16
17
18
# File 'lib/tmux/window.rb', line 16

def options
  @options
end

Instance Attribute Details

#aggressive_resizeBoolean Also known as: aggressive_resize?

Aggressively resize the window. This means that tmux will resize the window to the size of the smallest session for which it is the current window, rather than the smallest session to which it is attached. The window may resize when the current window is changed on another session; this option is good for full-screen programs which support SIGWINCH and poor for interactive programs such as shells.

Returns:

  • (Boolean)


178
179
180
# File 'lib/tmux/window.rb', line 178

def aggressive_resize
  @aggressive_resize
end

#alternate_screenBoolean Also known as: alternate_screen?

This option configures whether programs running inside tmux may use the terminal alternate screen feature, which allows the smcup and rmcup terminfo(5) capabilities to be issued to preserve the existing window content on start and restore it on exit.

Returns:

  • (Boolean)


370
371
372
# File 'lib/tmux/window.rb', line 370

def alternate_screen
  @alternate_screen
end

#automatic_renameBoolean Also known as: automatic_rename?

Control automatic window renaming. When this setting is enabled, tmux will attempt – on supported platforms – to rename the window to reflect the command currently running in it. This flag is automatically disabled for an individual window when a name is specified at creation with Session#create_window or Server#create_session, or later with #name=.

Returns:

  • (Boolean)


198
199
200
# File 'lib/tmux/window.rb', line 198

def automatic_rename
  @automatic_rename
end

#clock_mode_colorSymbol Also known as: clock_mode_colour

Clock color.

Returns:

  • (Symbol)


402
403
404
# File 'lib/tmux/window.rb', line 402

def clock_mode_color
  @clock_mode_color
end

#clock_mode_styleSymbol<:twelve, :twenty_four>

Clock hour format.

Returns:

  • (Symbol<:twelve, :twenty_four>)


418
419
420
# File 'lib/tmux/window.rb', line 418

def clock_mode_style
  @clock_mode_style
end

#current_pane(return_if = :always) ⇒ Pane? (readonly)

Returns The current pane.

Parameters:

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

    When to return the current pane.

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

Returns:

  • (Pane, nil)

    The current pane



635
636
637
# File 'lib/tmux/window.rb', line 635

def current_pane
  @current_pane
end

#heightInteger (readonly)

Returns:

  • (Integer)

Required tmux version:

  • >=1.1



154
155
156
# File 'lib/tmux/window.rb', line 154

def height
  @height
end

#identifierString (readonly)

Returns:

  • (String)


163
164
165
# File 'lib/tmux/window.rb', line 163

def identifier
  @identifier
end

#layout=(layout) ⇒ Symbol (writeonly)

TODO:

attr_reader

Parameters:

  • Symbol<:even_horizontal, (Symbol<:even_horizontal, :even_vertical, :main_horizontal, :main_vertical] The layout to apply to the window)

    :even_vertical, :main_horizontal, :main_vertical] The layout to apply to the window

Returns:

  • (Symbol)

Raises:

tmux command:

  • select-layout

Required tmux version:

  • >=1.3 for :tiled layout

  • >=1.0 for all other layouts



539
540
541
# File 'lib/tmux/window.rb', line 539

def layout=(value)
  @layout = value
end

#main_pane_heightNumber

Set the height of the main (left or top) pane in the main-horizontal or main-vertical layouts.

Returns:

  • (Number)

See Also:



435
436
437
# File 'lib/tmux/window.rb', line 435

def main_pane_height
  @main_pane_height
end

#main_pane_widthNumber

Set the width of the main (left or top) pane in the main-horizontal or main-vertical layouts.

Returns:

  • (Number)

See Also:



451
452
453
# File 'lib/tmux/window.rb', line 451

def main_pane_width
  @main_pane_width
end

#max_heightNumber Also known as: force_height

Prevent tmux from resizing the window to greater than max_height. A value of zero restores the default unlimited setting.

Returns:

  • (Number)


315
316
317
# File 'lib/tmux/window.rb', line 315

def max_height
  @max_height
end

#max_widthNumber Also known as: force_width

Prevent tmux from resizing the window to greater than max_width. A value of zero restores the default unlimited setting.

Returns:

  • (Number)


297
298
299
# File 'lib/tmux/window.rb', line 297

def max_width
  @max_width
end

#mode_attrSymbol

Returns:

  • (Symbol)


463
464
465
# File 'lib/tmux/window.rb', line 463

def mode_attr
  @mode_attr
end

#mode_bgSymbol

Returns:

  • (Symbol)


475
476
477
# File 'lib/tmux/window.rb', line 475

def mode_bg
  @mode_bg
end

#mode_fgSymbol

Returns:

  • (Symbol)


487
488
489
# File 'lib/tmux/window.rb', line 487

def mode_fg
  @mode_fg
end

#mode_keysSymbol

Returns:

  • (Symbol)


499
500
501
# File 'lib/tmux/window.rb', line 499

def mode_keys
  @mode_keys
end

#mode_mouseBoolean Also known as: mode_mouse?

Mouse state in modes. If true, the mouse may be used to copy a selection by dragging in copy mode, or to select an option in choice mode.

Returns:

  • (Boolean)


387
388
389
# File 'lib/tmux/window.rb', line 387

def mode_mouse
  @mode_mouse
end

#monitor_activityBoolean Also known as: monitor_activity?

Monitor for activity in the window. Windows with activity are highlighted in the status line.

Returns:

  • (Boolean)


264
265
266
# File 'lib/tmux/window.rb', line 264

def monitor_activity
  @monitor_activity
end

#monitor_contentString

Monitor content in the window. When the fnmatch(3) pattern appears in the window, it is highlighted in the status line.

Returns:

  • (String)


281
282
283
# File 'lib/tmux/window.rb', line 281

def monitor_content
  @monitor_content
end

#nameString

Returns:

  • (String)

tmux command:

  • rename-window

Required tmux version:

  • >=1.1



128
129
130
# File 'lib/tmux/window.rb', line 128

def name
  @name
end

#numberNumber #number=(new_number) ⇒ Number

Overloads:

  • #numberNumber

    Returns:

    • (Number)
  • #number=(new_number) ⇒ Number

    Returns:

    • (Number)

    Raises:

    See Also:

Returns:

  • (Number)


30
31
32
# File 'lib/tmux/window.rb', line 30

def number
  @number
end

#optionsOptionsList (readonly)

Returns:



49
50
51
# File 'lib/tmux/window.rb', line 49

def options
  @options
end

#panesArray<Pane> (readonly)

Returns All panes.

Returns:

Required tmux version:

  • >=1.1



588
589
590
# File 'lib/tmux/window.rb', line 588

def panes
  @panes
end

#remain_on_exitBoolean Also known as: remain_on_exit?

A window with this flag set is not destroyed when the program running in it exits. The window may be reactivated with #respawn.

Returns:

  • (Boolean)


232
233
234
# File 'lib/tmux/window.rb', line 232

def remain_on_exit
  @remain_on_exit
end

#serverServer (readonly)

Returns:



119
120
121
# File 'lib/tmux/window.rb', line 119

def server
  @server
end

#sessionSession #session=(new_session) ⇒ Session

Overloads:

  • #sessionSession

    Returns:

  • #session=(new_session) ⇒ Session
    TODO:

    use base-index

    Moves the window to another session. First it tries to reuse the current number of the window. If that number is already used in the new session, the first free number will be used instead.

    Returns:

    Raises:

    See Also:

Returns:



46
47
48
# File 'lib/tmux/window.rb', line 46

def session
  @session
end

#statusStatus (readonly)

Returns:



51
52
53
# File 'lib/tmux/window.rb', line 51

def status
  @status
end

#synchronize_panesBoolean Also known as: synchronize_panes?

Duplicate input to any pane to all other panes in the same window (only for panes that are not in any special mode)

Returns:

  • (Boolean)


215
216
217
# File 'lib/tmux/window.rb', line 215

def synchronize_panes
  @synchronize_panes
end

#utf8Boolean Also known as: utf8?

Instructs tmux to expect UTF-8 sequences to appear in this window.

Returns:

  • (Boolean)


248
249
250
# File 'lib/tmux/window.rb', line 248

def utf8
  @utf8
end

#widthInteger (readonly)

Returns:

  • (Integer)

Required tmux version:

  • >=1.1



144
145
146
# File 'lib/tmux/window.rb', line 144

def width
  @width
end

#word_separatorsArray<String>

Sets the window's conception of what characters are considered word separators, for the purposes of the next and previous word commands in copy mode. The default is [" ", "-", "_", "@"].

Returns:

  • (Array<String>)


352
353
354
# File 'lib/tmux/window.rb', line 352

def word_separators
  @word_separators
end

#xterm_keysBoolean Also known as: xterm_keys?

If this option is set to true, tmux will generate xterm(1)-style function key sequences. These have a number included to indicate modifiers such as Shift, Alt or Ctrl. The default is false.

Returns:

  • (Boolean)


334
335
336
# File 'lib/tmux/window.rb', line 334

def xterm_keys
  @xterm_keys
end

Instance Method Details

#<=>(other) ⇒ Undefined



98
99
100
101
# File 'lib/tmux/window.rb', line 98

def <=>(other)
  return nil unless other.is_a?(Window)
  [@session, @number] <=> [other.session, other.number]
end

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def ==(other)
  self.class == other.class && @session == other.session && @number == other.number
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/tmux/window.rb', line 114

def eql?(other)
  self == other
end

#hashNumber

Returns:

  • (Number)


109
110
111
# File 'lib/tmux/window.rb', line 109

def hash
  [@session.hash, @number].hash
end

#kill

This method returns an undefined value.

Kills the window.

tmux command:

  • kill-window



513
514
515
# File 'lib/tmux/window.rb', line 513

def kill
  server.invoke_command "kill-window -t #{identifier}"
end

#move(new_session, new_number)

This method returns an undefined value.

Moves the window to either a different session, a different position or both.

Parameters:

  • new_session (Session)
  • new_number (Number)

Raises:

See Also:

tmux command:

  • move-window



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/tmux/window.rb', line 86

def move(new_session, new_number)
  return if @session == new_session && @number == new_number
  target = "%s:%s" % [new_session.identifier, new_number]

  res = server.invoke_command("move-window -s #{identifier} -t #{target}")
  if res =~ /^can't move window: index in use: \d+/
    raise IndexInUse, [new_session, new_number]
  end
  @session = new_session
  @number  = new_number
end

#panes_information(search = {}) ⇒ Hash

Returns A hash with information for all panes.

Parameters:

Returns:

  • (Hash)

    A hash with information for all panes

tmux command:

  • list-panes

Required tmux version:

  • >=1.1



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/tmux/window.rb', line 555

def panes_information(search={})
  server.check_for_version!("1.1")

  hash = {}
  output = server.invoke_command "list-panes -t #{identifier}"
  output.each_line do |pane|
    params = pane.match(/^(?<num>\d+): \[(?<width>\d+)x(?<height>\d+)\] \[history (?<cur_history>\d+)\/(?<max_history>\d+), (?<memory>\d+) bytes\](?<active> \(active\))?$/)
    num = params[:num].to_i
    width = params[:width].to_i
    height = params[:height].to_i
    cur_history = params[:cur_history].to_i
    max_history = params[:max_history].to_i
    memory = Filesize.new(params[:memory].to_i)

    # this flag requires tmux >=1.4
    active = !params[:active].nil?

    hash[num] = {
      :num => num,
      :width => width,
      :height => height,
      :cur_history => cur_history,
      :max_history => max_history,
      :memory => memory,
      :active => active,
    }
  end
  hash.extend FilterableHash
  hash.filter(search)
end

#paste(buffer, pop = false, translate = true, separator = nil)

This method returns an undefined value.

Pastes a buffer into the window.

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



608
609
610
# File 'lib/tmux/window.rb', line 608

def paste(buffer, pop = false, translate = true, separator = nil)
  buffer.paste(self, pop, translate, separator)
end

#respawn(command = nil, kill = false)

TODO:

escape command

This method returns an undefined value.

Reactivates a window in which the command has exited.

Parameters:

  • command (String, nil) (defaults to: nil)

    The command to use to respawn the window. If nil, the command used when the window was created is executed.

  • kill (Boolean) (defaults to: false)

    Unless kill is true, only inactive windows can be respawned

See Also:

tmux command:

  • respawn-window



688
689
690
691
692
693
694
695
# File 'lib/tmux/window.rb', line 688

def respawn(command = nil, kill = false)
  flags = []
  flags << "-k" if kill
  flags << "-t #{identifier}"
  flags << "\"#{command}\"" if command

  server.invoke_command "respawn-window #{flags.join(" ")}"
end

#rotate(direction = :upward)

This method returns an undefined value.

Rotates the positions of the panes within a window.

tmux command:

  • rotate-window



521
522
523
524
525
526
527
528
529
530
531
# File 'lib/tmux/window.rb', line 521

def rotate(direction = :upward)
  flag = case direction
         when :upward
           "U"
         when :downward
           "D"
         else
           raise ArgumentError
         end
  server.invoke_command "rotate-window -#{flag} -t #{identifier}"
end

#select

This method returns an undefined value.

Select the window.

tmux command:

  • select-window



616
617
618
# File 'lib/tmux/window.rb', line 616

def select
  server.invoke_command "select-window -t #{identifier}"
end

#select_last_pane(return_if = :always) ⇒ Pane?

Select the previously selected pane.

Parameters:

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

    When to return the current pane.

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

Returns:

  • (Pane, nil)

    The current pane

tmux command:

  • last-pane

Required tmux version:

  • >=1.4



673
674
675
676
# File 'lib/tmux/window.rb', line 673

def select_last_pane(return_if = :always)
  server.invoke_command("last-pane -t #{identifier}")
  current_pane(return_if)
end

#swap_with(window)

This method returns an undefined value.

Swap the window with another one.

Parameters:

  • window (Window)

    The window to swap with

tmux command:

  • swap-window



625
626
627
# File 'lib/tmux/window.rb', line 625

def swap_with(window)
  server.invoke_command "swap-window -s #{identifier} -t #{window.identifier}"
end