class Barr::Manager
Constants
- ERROR_ICON
Attributes
blocks[R]
count[R]
Public Class Methods
new()
click to toggle source
# File lib/barr/manager.rb, line 11 def initialize @count = 0 @blocks = [] end
Public Instance Methods
add(block)
click to toggle source
# File lib/barr/manager.rb, line 16 def add(block) block.manager = self @blocks << block end
add_block(block)
click to toggle source
# File lib/barr/manager.rb, line 79 def add_block(block); add(block); end
destroy()
click to toggle source
# File lib/barr/manager.rb, line 78 def destroy; destroy!; end
destroy!()
click to toggle source
# File lib/barr/manager.rb, line 21 def destroy! @blocks.each(&:destroy!) end
draw()
click to toggle source
# File lib/barr/manager.rb, line 25 def draw outputs = { l: [], c: [], r: [] } @blocks.each do |block| outputs[block.align] << block.draw end left_blocks = outputs[:l].join '' centre_blocks = outputs[:c].join '' right_blocks = outputs[:r].join '' bar_render = '' bar_render << "%{l}#{left_blocks} " if left_blocks.length > 0 bar_render << "%{c} #{centre_blocks} " if centre_blocks.length > 0 bar_render << "%{r} #{right_blocks}" if right_blocks.length > 0 bar_render.gsub! "\n", '' system('echo', '-e', bar_render.encode('UTF-8')) end
id()
click to toggle source
# File lib/barr/manager.rb, line 68 def id @id ||= SecureRandom.uuid end
run()
click to toggle source
# File lib/barr/manager.rb, line 77 def run; run!; end
run!()
click to toggle source
# File lib/barr/manager.rb, line 46 def run! while true self.update! self.draw sleep 1 end end
update()
click to toggle source
compatibility methods. alias_method would work here, but for consistency with Block
I’ll define them this way
# File lib/barr/manager.rb, line 76 def update; update!; end
update!()
click to toggle source
# File lib/barr/manager.rb, line 54 def update! @blocks.each do |block| begin block.update! if @count == 0 || (@count % block.interval == 0) rescue StandardError => e STDERR.puts e.message block << ERROR_ICON unless block.output.include?(ERROR_ICON) next end end @count += 1 end