Class: Tmux::Server
- Inherits:
-
Object
- Object
- Tmux::Server
- Includes:
- Comparable
- Defined in:
- lib/tmux/server.rb
Instance Attribute Summary (collapse)
- - (Array<Client>) clients readonly
-
- (String) info
readonly
Information about the server.
- - (OptionsList) options readonly
-
- (Server) server
readonly
Returns self.
-
- (Session) session
readonly
The first session.
-
- (Array<Session>) sessions
readonly
All sessions.
- - (String) socket readonly
-
- (String) version
readonly
Version of the tmux server.
Instance Method Summary (collapse)
- - (-1, ...) <=>(other)
-
- (Array<Buffer>) buffers
Returns all buffers of all sessions.
-
- check_for_version!(required)
Checks if a version requirement is being met.
-
- (Hash) clients_information(search = {})
A hash with information for all clients.
-
- (Session?) create_session(args = {})
Creates a new session.
-
- (Server) initialize(socket = "default")
constructor
A new instance of Server.
-
- invoke_command(command, unset_tmux = false)
Invokes a tmux command.
- - kill
-
- (Hash) sessions_information(search = {})
A hash with information for all sessions.
-
- source_file(file)
(also: #load)
Sources a file, that is load and evaluate it in tmux.
Constructor Details
- (Server) initialize(socket = "default")
A new instance of Server
59 60 61 62 |
# File 'lib/tmux/server.rb', line 59 def initialize(socket = "default") @socket = socket @options = OptionsList.new(:server, self, false) end |
Instance Attribute Details
- (Array<Client>) clients (readonly)
185 186 187 188 189 |
# File 'lib/tmux/server.rb', line 185 def clients(search = {}) clients_information(search).map { |device, information| Client.new(self, device) } end |
- (String) info (readonly)
Information about the server
195 196 197 |
# File 'lib/tmux/server.rb', line 195 def info invoke_command "server-info" end |
- (Server) server (readonly)
Returns self. This is useful for other classes which can operate on Server, Tmux::Session, Window, Pane and so on
75 76 77 |
# File 'lib/tmux/server.rb', line 75 def server self end |
- (Session) session (readonly)
149 150 151 |
# File 'lib/tmux/server.rb', line 149 def session sessions.first end |
- (Array<Session>) sessions (readonly)
All sessions
138 139 140 141 142 |
# File 'lib/tmux/server.rb', line 138 def sessions(search = {}) sessions_information(search).map do |name, information| Session.new(self, name) end end |
- (String) socket (readonly)
55 56 57 |
# File 'lib/tmux/server.rb', line 55 def socket @socket end |
- (String) version (readonly)
Version of the tmux server
201 202 203 |
# File 'lib/tmux/server.rb', line 201 def version @version ||= info.lines.first.split(",").first[/([.\d]+)/] end |
Instance Method Details
- (-1, ...) <=>(other)
65 66 67 68 |
# File 'lib/tmux/server.rb', line 65 def <=>(other) return nil unless other.is_a?(Server) @socket <=> other.socket end |
- (Array<Buffer>) buffers
Returns all buffers of all sessions.
210 211 212 213 214 215 216 217 218 |
# File 'lib/tmux/server.rb', line 210 def buffers if @server.version < "1.5" # Manually walk all sessions sessions.flat_map {|s| s.buffers} else # There's only a global stack, so any session will do session.buffers end end |
- check_for_version!(required)
This method returns an undefined value.
Checks if a version requirement is being met
225 226 227 228 229 |
# File 'lib/tmux/server.rb', line 225 def check_for_version!(required) if required > version raise Exception::UnsupportedVersion, required end end |
- (Hash) clients_information(search = {})
A hash with information for all clients
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/tmux/server.rb', line 156 def clients_information(search = {}) clients = invoke_command "list-clients" hash = {} clients.each_line do |client| params = client.strip.match(/^(?<device>.+?): (?<session>.+?) \[(?<width>\d+)x(?<height>\d+) (?<term>.+?)\](?: \((?<utf8>utf8)\))?$/) device = params[:device] session = sessions(:name => params[:session]).first width = params[:width].to_i height = params[:height].to_i term = params[:term] utf8 = !!params[:utf8] hash[device] = { :device => device, :session => session, :width => width, :height => height, :term => term, :utf8 => utf8, } end hash.extend FilterableHash hash.filter(search) end |
- (Session?) create_session(args = {})
Creates a new session
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tmux/server.rb', line 25 def create_session(args = {}) check_for_version!("1.4") if args[:group_with] && (args[:window_name] || args[:command]) raise ArgumentError, "Cannot combine :group_with and :window_name or :command" end # FIXME shell escape names flags = [] flags << "-d" unless args[:attach] flags << "-n '#{args[:window_name]}'" if args[:window_name] flags << "-s '#{args[:name]}'" if args[:name] flags << "-t '#{args[:group_with].name}'" if args[:group_with] flags << args[:command] if args[:command] command = "new-session #{flags.join(" ")}" ret = invoke_command(command, true) if ret.start_with?("duplicate session:") raise RuntimeError, ret elsif ret.start_with?("sessions should be nested with care.") raise Exception::InTmux("new-session") else if args[:name] and !args[:attach] return Session.new(self, args[:name]) end end end |
- invoke_command(command, unset_tmux = false)
This method returns an undefined value.
Invokes a tmux command.
83 84 85 |
# File 'lib/tmux/server.rb', line 83 def invoke_command(command, unset_tmux = false) Tmux.invoke_command("-L #@socket #{command}", unset_tmux) end |
- kill
91 92 93 |
# File 'lib/tmux/server.rb', line 91 def kill invoke_command "kill-server" end |
- (Hash) sessions_information(search = {})
A hash with information for all sessions
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/tmux/server.rb', line 108 def sessions_information(search = {}) hash = {} output = invoke_command "list-sessions" output.each_line do |session| params = session.match(/^(?<name>[\w-]+?): (?<num_windows>\d+) windows \(created (?<creation_time>.+?)\) \[(?<width>\d+)x(?<height>\d+)\](?: \((?<attached>attached)\))?$/) name = params[:name] num_windows = params[:num_windows].to_i creation_time = Date.parse(params[:creation_time]) width = params[:width].to_i height = params[:height].to_i attached = !!params[:attached] hash[name] = { :name => name, :num_windows => num_windows, :creation_time => creation_time, :width => width, :height => height, :attached => attached, } end hash.extend FilterableHash hash.filter(search) end |
- source_file(file) Also known as: load
This method returns an undefined value.
Sources a file, that is load and evaluate it in tmux.
100 101 102 |
# File 'lib/tmux/server.rb', line 100 def source_file(file) invoke_command "source-file #{file}" end |