class SidekiqSpy::Display::Subpanel

Attributes

content_width[R]
data[R]
dividers[R]
height[R]
left[R]
top[R]
width[R]

Public Class Methods

new(window, height, width, top, left, opts = {}) click to toggle source
# File lib/sidekiq-spy/display/subpanel.rb, line 13
def initialize(window, height, width, top, left, opts = {})
  @window = window
  @height = height
  @width  = width
  @top    = top
  @left   = left
  
  @data = {
    :left  => opts[:data_l] || '',
    :right => opts[:data_r] || '',
  }
  
  @dividers = {
    :left  => opts[:divider_l] || '',
    :right => opts[:divider_r] || '',
  }
  
  @content_width = @width - @dividers.values.map(&:length).inject(:+)
end

Public Instance Methods

refresh() click to toggle source
# File lib/sidekiq-spy/display/subpanel.rb, line 33
def refresh
  new_current = content(@data[:left], @data[:right], @content_width)
  
  unless new_current == @data[:current] # don't redraw if hasn't changed
    @window.setpos(@top, @left)
    @window.addstr(@dividers[:left] + new_current + @dividers[:right])
  end
  
  @data[:current] = new_current
end

Private Instance Methods

content(data_l, data_r, width) click to toggle source
# File lib/sidekiq-spy/display/subpanel.rb, line 46
def content(data_l, data_r, width)
  l = data_l.is_a?(Proc) ? data_l.call : data_l
  r = data_r.is_a?(Proc) ? data_r.call : data_r
  
  ("#{l}%#{width - l.to_s.length}s" % r)[0...width]
end