Class: Tmux::Session
Overview
A session is a single collection of pseudo terminals under the management of tmux. Each session has one or more windows linked to it. 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). Any number of tmux instances may connect to the same session, and any number of windows may be present in the same session. Once all sessions are killed, tmux exits.
Instance Attribute Summary collapse
- #attached ⇒ Boolean (also: #attached?) readonly
-
#buffers ⇒ Array<Buffer>
readonly
All buffers.
-
#clients ⇒ Array<Client>
readonly
All clients.
- #creation_time ⇒ Time (also: #created_at) readonly
-
#current_pane ⇒ Pane
readonly
The currently displayed pane.
-
#current_window ⇒ Window
readonly
The currently displayed window.
- #height ⇒ Integer readonly
- #identifier ⇒ String readonly
- #name ⇒ String
- #num_windows ⇒ Integer readonly
- #options ⇒ OptionsList readonly
- #server ⇒ Server readonly
- #status_bar ⇒ StatusBar readonly
- #width ⇒ Integer readonly
-
#windows ⇒ Hash{Number => Window}
readonly
All windows.
Selecting collapse
-
#select_last_window ⇒ Window
Select the last (previously selected) window.
-
#select_next_window(num = 1) ⇒ Window
Selects the next (higher index) window.
-
#select_previous_window(num = 1) ⇒ Window
Selects the previous (lower index) window.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Undefined
- #==(other) ⇒ Boolean
-
#any_client ⇒ Client?
Returns a client that is displaying the session.
-
#attach
Attach to a session.
-
#buffers_information(search = {}) ⇒ Hash
A hash with information for all buffers.
-
#create_window(args = {}) ⇒ Window
Creates a new window.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Number
-
#initialize(server, name) ⇒ Session
constructor
A new instance of Session.
-
#kill
Kills the session.
-
#lock
Locks the session.
- #windows_information(search = {}) ⇒ Hash
Constructor Details
#initialize(server, name) ⇒ Session
Returns a new instance of Session.
122 123 124 125 126 |
# File 'lib/tmux/session.rb', line 122 def initialize(server, name) @server, @name = server, name @status_bar = StatusBar.new(self) @options = OptionsList.new(:session, self, false) end |
Instance Attribute Details
#attached ⇒ Boolean (readonly) Also known as: attached?
187 188 189 |
# File 'lib/tmux/session.rb', line 187 def attached @attached end |
#buffers ⇒ Array<Buffer> (readonly)
Returns All buffers.
272 273 274 |
# File 'lib/tmux/session.rb', line 272 def buffers @buffers end |
#clients ⇒ Array<Client> (readonly)
Returns All clients.
195 196 197 |
# File 'lib/tmux/session.rb', line 195 def clients @clients end |
#creation_time ⇒ Time (readonly) Also known as: created_at
165 166 167 |
# File 'lib/tmux/session.rb', line 165 def creation_time @creation_time end |
#current_pane ⇒ Pane (readonly)
Returns The currently displayed pane.
72 73 74 |
# File 'lib/tmux/session.rb', line 72 def current_pane @current_pane end |
#current_window ⇒ Window (readonly)
Returns The currently displayed window.
64 65 66 |
# File 'lib/tmux/session.rb', line 64 def current_window @current_window end |
#height ⇒ Integer (readonly)
180 181 182 |
# File 'lib/tmux/session.rb', line 180 def height @height end |
#identifier ⇒ String (readonly)
140 141 142 |
# File 'lib/tmux/session.rb', line 140 def identifier @identifier end |
#name ⇒ String #name=(new_name) ⇒ String
114 115 116 |
# File 'lib/tmux/session.rb', line 114 def name @name end |
#num_windows ⇒ Integer (readonly)
158 159 160 |
# File 'lib/tmux/session.rb', line 158 def num_windows @num_windows end |
#options ⇒ OptionsList (readonly)
119 120 121 |
# File 'lib/tmux/session.rb', line 119 def @options end |
#server ⇒ Server (readonly)
117 118 119 |
# File 'lib/tmux/session.rb', line 117 def server @server end |
#status_bar ⇒ StatusBar (readonly)
121 122 123 |
# File 'lib/tmux/session.rb', line 121 def @status_bar end |
#width ⇒ Integer (readonly)
173 174 175 |
# File 'lib/tmux/session.rb', line 173 def width @width end |
Class Method Details
.options(session) ⇒ Options
15 16 17 |
# File 'lib/tmux/session.rb', line 15 def self.(session) OptionsList.new(:session, session, true) end |
Instance Method Details
#<=>(other) ⇒ Undefined
100 101 102 103 |
# File 'lib/tmux/session.rb', line 100 def <=>(other) return nil unless other.is_a?(Session) [@server, @name] <=> [other.server, other.name] end |
#==(other) ⇒ Boolean
86 87 88 |
# File 'lib/tmux/session.rb', line 86 def ==(other) self.class == other.class && @server == other.server && @name == other.name end |
#any_client ⇒ Client?
Returns a client that is displaying the session.
81 82 83 |
# File 'lib/tmux/session.rb', line 81 def any_client @server.clients({:session => self}).first end |
#attach
This method returns an undefined value.
Attach to a session. Replaces the ruby process.
205 206 207 |
# File 'lib/tmux/session.rb', line 205 def attach exec "#{Tmux::BINARY} attach -t #{identifier}" end |
#buffers_information(search = {}) ⇒ Hash
Returns A hash with information for all buffers.
259 260 261 262 263 264 265 266 267 268 |
# File 'lib/tmux/session.rb', line 259 def buffers_information(search = {}) hash = {} buffers = @server.invoke_command "list-buffers -t #{identifier}" buffers.each_line do |buffer| num, size = buffer.match(/^(\d+): (\d+) bytes/)[1..2] hash[num] = {:size => size} end hash.extend FilterableHash hash.filter(search) end |
#create_window(args = {}) ⇒ Window
Creates a new window.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tmux/session.rb', line 38 def create_window(args = {}) args = { :kill_existing => false, :make_active => true, :after_number => false, }.merge(args) flags = [] # flags << "-d" unless args[:make_active] flags << "-a" if args[:after_number] flags << "-k" if args[:kill_existing] flags << "-n '#{args[:name]}'" if args[:name] # FIXME escaping flags << "-t #{args[:number]}" if args[:number] flags << args[:command] if args[:command] @server.invoke_command "new-window #{flags.join(" ")}" new_window = current_window unless args[:make_active] select_last_window end # return Window.new(self, num) return new_window end |
#eql?(other) ⇒ Boolean
96 97 98 |
# File 'lib/tmux/session.rb', line 96 def eql?(other) self == other end |
#hash ⇒ Number
91 92 93 |
# File 'lib/tmux/session.rb', line 91 def hash [@server.hash, @number].hash end |
#kill
This method returns an undefined value.
Kills the session.
213 214 215 |
# File 'lib/tmux/session.rb', line 213 def kill @server.invoke_command "kill-session -t #{identifier}" end |
#lock
This method returns an undefined value.
Locks the session.
151 152 153 154 155 |
# File 'lib/tmux/session.rb', line 151 def lock @server.check_for_version!("1.1") @server.invoke_command "lock-session -t #{identifier}" end |
#select_last_window ⇒ Window
Select the last (previously selected) window.
285 286 287 288 |
# File 'lib/tmux/session.rb', line 285 def select_last_window @server.invoke_command "last-window -t #{identifier}" current_window end |
#select_next_window(num = 1) ⇒ Window
Selects the next (higher index) window
295 296 297 298 |
# File 'lib/tmux/session.rb', line 295 def select_next_window(num = 1) @server.invoke_command "select-window -t #{identifier}:+#{num}" current_window end |
#select_previous_window(num = 1) ⇒ Window
Selects the previous (lower index) window
305 306 307 308 |
# File 'lib/tmux/session.rb', line 305 def select_previous_window(num = 1) @server.invoke_command "select-window -t:-#{num}" current_window end |
#windows_information(search = {}) ⇒ Hash
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/tmux/session.rb', line 222 def windows_information(search = {}) @server.check_for_version!("1.1") hash = {} output = @server.invoke_command "list-windows -t #{identifier}" output.each_line do |session| params = session.match(/^(?<num>\d+): (?<name>.+?) \[(?<width>\d+)x(?<height>\d+)\]$/) next if params.nil? # >=1.3 displays layout information in indented lines num = params[:num].to_i name = params[:name] width = params[:width].to_i height = params[:height].to_i hash[num] = {:num => num, :name => name, :width => width, :height => height} end hash.extend FilterableHash hash.filter(search) end |