Class: Hiiro::Tmux::Buffers

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffers) ⇒ Buffers

Returns a new instance of Buffers.



16
17
18
# File 'lib/hiiro/tmux/buffers.rb', line 16

def initialize(buffers)
  @buffers = buffers
end

Instance Attribute Details

#buffersObject (readonly)

Returns the value of attribute buffers.



14
15
16
# File 'lib/hiiro/tmux/buffers.rb', line 14

def buffers
  @buffers
end

Class Method Details

.fetchObject



6
7
8
9
10
11
12
# File 'lib/hiiro/tmux/buffers.rb', line 6

def self.fetch
  output = `tmux list-buffers -F '#{Buffer::FORMAT}' 2>/dev/null`
  return new([]) if output.nil? || output.empty?

  buffers = output.each_line.map { |line| Buffer.from_format_line(line) }.compact
  new(buffers)
end

Instance Method Details

#clear_allObject



53
54
55
# File 'lib/hiiro/tmux/buffers.rb', line 53

def clear_all
  buffers.each(&:delete)
end

#each(&block) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/hiiro/tmux/buffers.rb', line 43

def empty?
  buffers.empty?
end

#find_by_name(name) ⇒ Object



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

def find_by_name(name)
  buffers.find { |b| b.name == name }
end

#matching(pattern) ⇒ Object



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

def matching(pattern)
  regex = Regexp.new(pattern)
  self.class.new(buffers.select { |b| b.name =~ regex || b.sample =~ regex })
end

#name_mapObject



37
38
39
40
41
# File 'lib/hiiro/tmux/buffers.rb', line 37

def name_map
  buffers.each_with_object({}) do |buffer, h|
    h[buffer.to_s] = buffer.name
  end
end

#namesObject



33
34
35
# File 'lib/hiiro/tmux/buffers.rb', line 33

def names
  buffers.map(&:name)
end

#sizeObject Also known as: count, length



47
48
49
# File 'lib/hiiro/tmux/buffers.rb', line 47

def size
  buffers.size
end