Class: Hiiro::Tmux::Windows
- Inherits:
-
Object
- Object
- Hiiro::Tmux::Windows
- Includes:
- Enumerable
- Defined in:
- lib/hiiro/tmux/windows.rb
Instance Attribute Summary collapse
-
#windows ⇒ Object
readonly
Returns the value of attribute windows.
Class Method Summary collapse
Instance Method Summary collapse
- #active ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #find_by_id(id) ⇒ Object
- #find_by_index(index) ⇒ Object
- #find_by_name(name) ⇒ Object
- #in_session(session_name) ⇒ Object
-
#initialize(windows) ⇒ Windows
constructor
A new instance of Windows.
- #name_map ⇒ Object
- #names ⇒ Object
- #size ⇒ Object (also: #count, #length)
- #targets ⇒ Object
Constructor Details
#initialize(windows) ⇒ Windows
Returns a new instance of Windows.
20 21 22 |
# File 'lib/hiiro/tmux/windows.rb', line 20 def initialize(windows) @windows = windows end |
Instance Attribute Details
#windows ⇒ Object (readonly)
Returns the value of attribute windows.
18 19 20 |
# File 'lib/hiiro/tmux/windows.rb', line 18 def windows @windows end |
Class Method Details
.fetch(session: nil, all: false) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/hiiro/tmux/windows.rb', line 6 def self.fetch(session: nil, all: false) args = ['tmux', 'list-windows', '-F', Window::FORMAT] args << '-a' if all args += ['-t', session] if session && !all output = `#{args.shelljoin} 2>/dev/null` return new([]) if output.nil? || output.empty? windows = output.each_line.map { |line| Window.from_format_line(line) }.compact new(windows) end |
Instance Method Details
#active ⇒ Object
44 45 46 |
# File 'lib/hiiro/tmux/windows.rb', line 44 def active self.class.new(windows.select(&:active?)) end |
#each(&block) ⇒ Object
24 25 26 |
# File 'lib/hiiro/tmux/windows.rb', line 24 def each(&block) windows.each(&block) end |
#empty? ⇒ Boolean
62 63 64 |
# File 'lib/hiiro/tmux/windows.rb', line 62 def empty? windows.empty? end |
#find_by_id(id) ⇒ Object
28 29 30 |
# File 'lib/hiiro/tmux/windows.rb', line 28 def find_by_id(id) windows.find { |w| w.id == id } end |
#find_by_index(index) ⇒ Object
36 37 38 |
# File 'lib/hiiro/tmux/windows.rb', line 36 def find_by_index(index) windows.find { |w| w.index == index } end |
#find_by_name(name) ⇒ Object
32 33 34 |
# File 'lib/hiiro/tmux/windows.rb', line 32 def find_by_name(name) windows.find { |w| w.name == name } end |
#in_session(session_name) ⇒ Object
40 41 42 |
# File 'lib/hiiro/tmux/windows.rb', line 40 def in_session(session_name) self.class.new(windows.select { |w| w.session_name == session_name }) end |
#name_map ⇒ Object
56 57 58 59 60 |
# File 'lib/hiiro/tmux/windows.rb', line 56 def name_map windows.each_with_object({}) do |window, h| h[window.to_s] = window.target end end |
#names ⇒ Object
48 49 50 |
# File 'lib/hiiro/tmux/windows.rb', line 48 def names windows.map(&:name) end |
#size ⇒ Object Also known as: count, length
66 67 68 |
# File 'lib/hiiro/tmux/windows.rb', line 66 def size windows.size end |
#targets ⇒ Object
52 53 54 |
# File 'lib/hiiro/tmux/windows.rb', line 52 def targets windows.map(&:target) end |