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

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Window) initialize(session, number)



32
33
34
35
36
# File 'lib/tmux/window.rb', line 32

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

Instance Attribute Details

- (Boolean) aggressive_resize 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.



174
175
176
# File 'lib/tmux/window.rb', line 174

def aggressive_resize
  @options.aggressive_resize
end

- (Boolean) alternate_screen 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.



375
376
377
# File 'lib/tmux/window.rb', line 375

def alternate_screen
  @options.alternate_screen
end

- (Boolean) automatic_rename 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=.



195
196
197
# File 'lib/tmux/window.rb', line 195

def automatic_rename
  @options.automatic_rename
end

- (Symbol<:twelve, :twenty_four>) clock_mode_style

Clock hour format.



426
427
428
# File 'lib/tmux/window.rb', line 426

def clock_mode_style
  @options.clock_mode_style
end

- (Integer) height (readonly)

Required tmux version:

  • >=1.1



150
151
152
153
154
# File 'lib/tmux/window.rb', line 150

def height
  server.check_for_version!("1.1")

  @session.windows_information[@number][:height]
end

- (String) identifier (readonly)



159
160
161
# File 'lib/tmux/window.rb', line 159

def identifier
  "%s:%s" % [@session.identifier, @number]
end

- (Symbol<:even_horizontal, :even_vertical, :main_horizontal, :main_vertical>) layout=(value) (writeonly)

TODO:

attr_reader

Raises:

tmux command:

  • select-layout

Required tmux version:

  • >=1.3 for :tiled layout

  • >=1.0 for all other layouts



550
551
552
553
554
555
556
557
558
# File 'lib/tmux/window.rb', line 550

def layout=(layout)
  server.check_for_version!("1.0")
  raise Exception::UnsupportedVersion, "1.3" if layout == :tiled && server.version < "1.3"

  valid_layouts = [:even_horizontal, :even_vertical, :main_horizontal, :main_vertical, :tiled]
  raise ArgumentError unless valid_layouts.include?(layout)
  layout = layout.to_s.tr("_", "-")
  server.invoke_command "select-layout -t #{identifier} #{layout}"
end

- (Number) main_pane_height

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

See Also:



443
444
445
# File 'lib/tmux/window.rb', line 443

def main_pane_height
  @options.main_pane_height
end

- (Number) main_pane_width

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

See Also:



460
461
462
# File 'lib/tmux/window.rb', line 460

def main_pane_width
  @options.main_pane_width
end

- (Number) max_height 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.



318
319
320
# File 'lib/tmux/window.rb', line 318

def max_height
  @options.force_height
end

- (Number) max_width 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.



299
300
301
# File 'lib/tmux/window.rb', line 299

def max_width
  @options.force_width
end

- (Symbol) mode_attr



473
474
475
# File 'lib/tmux/window.rb', line 473

def mode_attr
  @options.mode_attr
end

- (Symbol) mode_bg



485
486
487
# File 'lib/tmux/window.rb', line 485

def mode_bg
  @options.mode_bg
end

- (Symbol) mode_fg



497
498
499
# File 'lib/tmux/window.rb', line 497

def mode_fg
  @options.mode_fg
end

- (Symbol) mode_keys



510
511
512
# File 'lib/tmux/window.rb', line 510

def mode_keys
  @options.mode_keys
end

- (Boolean) mode_mouse 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.



393
394
395
# File 'lib/tmux/window.rb', line 393

def mode_mouse
  @options.mode_mouse
end

- (Boolean) monitor_activity Also known as: monitor_activity?

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



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

def monitor_activity
  @options.monitor_activity
end

- (String) monitor_content

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



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

def monitor_content
  @options.monitor_content
end

- (String) name

tmux command:

  • rename-window

Required tmux version:

  • >=1.1



124
125
126
127
128
# File 'lib/tmux/window.rb', line 124

def name
  server.check_for_version!("1.1")

  @session.windows_information[@number][:name]
end

- (Number) number

Raises:

See Also:



22
23
24
# File 'lib/tmux/window.rb', line 22

def number
  @number
end

- (OptionsList) options (readonly)



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

def options
  @options
end

- (Array<Pane>) panes (readonly)

Returns All panes

Required tmux version:

  • >=1.1



599
600
601
602
603
604
605
# File 'lib/tmux/window.rb', line 599

def panes
  server.check_for_version!("1.1")

  panes_information.map do |num, information|
    Pane.new(self, num)
  end
end

- (Boolean) remain_on_exit 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.



230
231
232
# File 'lib/tmux/window.rb', line 230

def remain_on_exit
  @options.remain_on_exit
end

- (Server) server (readonly)



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

def server
  @session.server
end

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

Raises:

See Also:



25
26
27
# File 'lib/tmux/window.rb', line 25

def session
  @session
end

- (Status) status (readonly)



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

def status
  @status
end

- (Boolean) synchronize_panes 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)



213
214
215
# File 'lib/tmux/window.rb', line 213

def synchronize_panes
  @options.synchronize_panes
end

- (Boolean) utf8 Also known as: utf8?

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



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

def utf8
  @options.utf8
end

- (Integer) width (readonly)

Required tmux version:

  • >=1.1



140
141
142
143
144
# File 'lib/tmux/window.rb', line 140

def width
  server.check_for_version!("1.1")

  @session.windows_information[@number][:width]
end

- (Array<String>) word_separators

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 [" ", "-", "_", "@"].



357
358
359
# File 'lib/tmux/window.rb', line 357

def word_separators
  @options.word_separators
end

- (Boolean) xterm_keys 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.



338
339
340
# File 'lib/tmux/window.rb', line 338

def xterm_keys
  @options.xterm_keys
end

Class Method Details

+ (OptionsList) options(server)



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

def options(server)
  OptionsList.new(:window, server, true)
end

Instance Method Details

- (Undefined) <=>(other)



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

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

- (Boolean) ==(other)



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

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

- (Symbol) clock_mode_color Also known as: clock_mode_colour

Clock color.



409
410
411
# File 'lib/tmux/window.rb', line 409

def clock_mode_color
  @options.clock_mode_colour
end

- (Symbol) clock_mode_color=(color) Also known as: clock_mode_colour=



416
417
418
# File 'lib/tmux/window.rb', line 416

def clock_mode_color=(color)
  @options.clock_mode_colour = color
end

- (Pane?) current_pane(return_if = :always)



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'lib/tmux/window.rb', line 644

def current_pane(return_if = :always)
  if server.version >= "1.4"
    self.panes.find(&:active?)
  else
    # In tmux <1.4, we can only determine the selected pane of the
    # current window.
    #
    # If the user specified return_if = :always, we select this
    # window (if it is not already selected), determine the
    # current pane and select the lastly selected window again.
    cur_window = self.session.any_client.current_window
    same_window = cur_window == self
    return_if_b = ((return_if == :if_same_window && same_window) || (return_if == :always))

    self.select if return_if_b && !same_window

    new_pane = nil
    if return_if_b
      num = self.session.any_client.message_stdout("#P")
      new_pane = Pane.new(self, num.to_i)
    end

    if return_if == :always && !same_window
      self.session.select_previous_window
    end

    return new_pane if new_pane
  end
end

- (Boolean) eql?(other)



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

def eql?(other)
  self == other
end

- (Number) hash



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

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

- kill

This method returns an undefined value.

Kills the window.

tmux command:

  • kill-window



523
524
525
# File 'lib/tmux/window.rb', line 523

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.

Raises:

See Also:

tmux command:

  • move-window



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/tmux/window.rb', line 81

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

- (Hash) panes_information(search = {})

Returns A hash with information for all panes

tmux command:

  • list-panes

Required tmux version:

  • >=1.1



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/tmux/window.rb', line 564

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\]( %\d+)?(?<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.

See Also:

tmux command:

  • paste-buffer



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

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.

See Also:

tmux command:

  • respawn-window



695
696
697
698
699
700
701
702
# File 'lib/tmux/window.rb', line 695

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



531
532
533
534
535
536
537
538
539
540
541
# File 'lib/tmux/window.rb', line 531

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



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

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

- (Pane?) select_last_pane(return_if = :always)

Select the previously selected pane.

tmux command:

  • last-pane

Required tmux version:

  • >=1.4



680
681
682
683
# File 'lib/tmux/window.rb', line 680

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.

tmux command:

  • swap-window



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

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