Class: Tmux::Server
Instance Attribute Summary collapse
- #clients(search = {}) ⇒ Array<Client> readonly
-
#info ⇒ String
readonly
Information about the server.
- #options ⇒ OptionsList readonly
-
#server ⇒ Server
readonly
Returns self.
-
#session ⇒ Session
readonly
The first session.
-
#sessions(search = {}) ⇒ Array<Session>
readonly
All sessions.
- #socket ⇒ String readonly
-
#version ⇒ String
readonly
Version of the tmux server.
Instance Method Summary collapse
- #<=>(other) ⇒ -1, ...
-
#check_for_version!(required)
Checks if a version requirement is being met.
-
#clients_information(search = {}) ⇒ Hash
A hash with information for all clients.
-
#create_session(args = {}) ⇒ Session?
Creates a new session.
-
#initialize(socket = "default") ⇒ Server
constructor
A new instance of Server.
-
#invoke_command(command, unset_tmux = false)
Invokes a tmux command.
- #kill
-
#sessions_information(search = {}) ⇒ Hash
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
#initialize(socket = "default") ⇒ Server
Returns 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
#clients(search = {}) ⇒ Array<Client> (readonly)
183 184 185 |
# File 'lib/tmux/server.rb', line 183 def clients @clients end |
#info ⇒ String (readonly)
Returns Information about the server.
193 194 195 |
# File 'lib/tmux/server.rb', line 193 def info @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
73 74 75 |
# File 'lib/tmux/server.rb', line 73 def server @server end |
#session ⇒ Session (readonly)
147 148 149 |
# File 'lib/tmux/server.rb', line 147 def session @session end |
#sessions(search = {}) ⇒ Array<Session> (readonly)
Returns All sessions.
136 137 138 |
# File 'lib/tmux/server.rb', line 136 def sessions @sessions end |
#socket ⇒ String (readonly)
55 56 57 |
# File 'lib/tmux/server.rb', line 55 def socket @socket end |
#version ⇒ String (readonly)
Returns Version of the tmux server.
200 201 202 |
# File 'lib/tmux/server.rb', line 200 def version @version end |
Instance Method Details
#<=>(other) ⇒ -1, ...
65 66 67 68 |
# File 'lib/tmux/server.rb', line 65 def <=>(other) return nil unless other.is_a?(Server) @socket <=> other.socket end |
#check_for_version!(required)
This method returns an undefined value.
Checks if a version requirement is being met
211 212 213 214 215 |
# File 'lib/tmux/server.rb', line 211 def check_for_version!(required) if required > version raise Exception::UnsupportedVersion, required end end |
#clients_information(search = {}) ⇒ Hash
Returns 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.match(/^(?<device>.+?): (?<session>\d+) \[(?<width>\d+)x(?<height>\d+) (?<term>.+?)\](?: \((?<utf8>utf8)\))?$/) device = params[:device] session = sessions[params[:session].to_i] 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 |
#create_session(args = {}) ⇒ Session?
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 |
#sessions_information(search = {}) ⇒ Hash
Returns 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 |