Class: FortMux::Status
- Inherits:
-
Object
- Object
- FortMux::Status
- Defined in:
- lib/FortMux.rb
Constant Summary collapse
- NO_SERVER_RE =
however backtick doesn’t see stderr
/server\s*not\s*found/i
- SESSION_RE =
/(?<session>[^:]*):.*windows.*\[(?<x>\d*)x(?<y>\d*)\]/
- WINDOW_RE =
/(?<index>\d*):\s*(?<window>\S*).*\[(?<x>\d*)x(?<y>\d*)\]/
- PANE_RE =
/(?<index>\d*):\s*\[(?<x>\d*)x(?<y>\d*)\]/
Instance Attribute Summary collapse
-
#sessions ⇒ Object
readonly
Returns the value of attribute sessions.
Instance Method Summary collapse
- #find(sessionName, windowName = nil) ⇒ Object
-
#initialize ⇒ Status
constructor
A new instance of Status.
- #window_count(sessionName) ⇒ Object
Constructor Details
#initialize ⇒ Status
Returns a new instance of Status.
107 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 133 134 135 |
# File 'lib/FortMux.rb', line 107 def initialize @sessions = [] # server not found: No such file or directory # on stderr, not stdout listSessions = `tmux list-sessions` if listSessions.length == 0 return end listSessions.split("\n").each do |line| if line =~ SESSION_RE sessions << {:session => $~[:session], :x => $~[:x], :y => $~[:y], :windows => []} end end @sessions.each do |s| listWindows = `tmux list-windows -t #{s[:session]}` listWindows.split("\n").each do |line| if line =~ WINDOW_RE s[:windows] << {:window => $~[:window], :index => $~[:index], :x => $~[:x], :y => $~[:y], :panes => []} end end s[:windows].each do |w| listPanes = `tmux list-panes -t #{s[:session]}:#{s[:window]}` listPanes.split("\n").each do |line| if line =~ PANE_RE w[:panes] << {:index => $~[:index], :x => $~[:x], :y => $~[:y]} end end end end end |
Instance Attribute Details
#sessions ⇒ Object (readonly)
Returns the value of attribute sessions.
85 86 87 |
# File 'lib/FortMux.rb', line 85 def sessions @sessions end |
Instance Method Details
#find(sessionName, windowName = nil) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/FortMux.rb', line 91 def find(sessionName,windowName=nil) session = @sessions.detect { |s| s[:session].downcase == sessionName.downcase } if session && windowName session[:windows].detect { |w| w[:window].downcase == windowName.downcase } else session end end |
#window_count(sessionName) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/FortMux.rb', line 99 def window_count(sessionName) session = find sessionName if session && session.has_key?(:windows) session[:windows].length else 0 end end |