Class: Hiiro::Tmux::Panes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hiiro/tmux/panes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(panes) ⇒ Panes

Returns a new instance of Panes.



20
21
22
# File 'lib/hiiro/tmux/panes.rb', line 20

def initialize(panes)
  @panes = panes
end

Instance Attribute Details

#panesObject (readonly)

Returns the value of attribute panes.



18
19
20
# File 'lib/hiiro/tmux/panes.rb', line 18

def panes
  @panes
end

Class Method Details

.fetch(target: nil, all: false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hiiro/tmux/panes.rb', line 6

def self.fetch(target: nil, all: false)
  args = ['tmux', 'list-panes', '-F', Pane::FORMAT]
  args << '-a' if all
  args += ['-t', target] if target && !all

  output = `#{args.shelljoin} 2>/dev/null`
  return new([]) if output.nil? || output.empty?

  panes = output.each_line.map { |line| Pane.from_format_line(line) }.compact
  new(panes)
end

Instance Method Details

#activeObject



44
45
46
# File 'lib/hiiro/tmux/panes.rb', line 44

def active
  self.class.new(panes.select(&:active?))
end

#by_command(command) ⇒ Object



48
49
50
# File 'lib/hiiro/tmux/panes.rb', line 48

def by_command(command)
  self.class.new(panes.select { |p| p.command == command })
end

#by_path(path) ⇒ Object



52
53
54
# File 'lib/hiiro/tmux/panes.rb', line 52

def by_path(path)
  self.class.new(panes.select { |p| p.path == path })
end

#each(&block) ⇒ Object



24
25
26
# File 'lib/hiiro/tmux/panes.rb', line 24

def each(&block)
  panes.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/hiiro/tmux/panes.rb', line 70

def empty?
  panes.empty?
end

#find_by_id(id) ⇒ Object



28
29
30
# File 'lib/hiiro/tmux/panes.rb', line 28

def find_by_id(id)
  panes.find { |p| p.id == id }
end

#find_by_index(index) ⇒ Object



32
33
34
# File 'lib/hiiro/tmux/panes.rb', line 32

def find_by_index(index)
  panes.find { |p| p.index == index }
end

#idsObject



56
57
58
# File 'lib/hiiro/tmux/panes.rb', line 56

def ids
  panes.map(&:id)
end

#in_session(session_name) ⇒ Object



40
41
42
# File 'lib/hiiro/tmux/panes.rb', line 40

def in_session(session_name)
  self.class.new(panes.select { |p| p.session_name == session_name })
end

#in_window(window_id) ⇒ Object



36
37
38
# File 'lib/hiiro/tmux/panes.rb', line 36

def in_window(window_id)
  self.class.new(panes.select { |p| p.window_id == window_id })
end

#name_mapObject



64
65
66
67
68
# File 'lib/hiiro/tmux/panes.rb', line 64

def name_map
  panes.each_with_object({}) do |pane, h|
    h[pane.to_s] = pane.id
  end
end

#sizeObject Also known as: count, length



74
75
76
# File 'lib/hiiro/tmux/panes.rb', line 74

def size
  panes.size
end

#targetsObject



60
61
62
# File 'lib/hiiro/tmux/panes.rb', line 60

def targets
  panes.map(&:target)
end