class Opsicle::Monitor::Panel

Attributes

divider_length[R]
dividers[R]
height[R]
left[R]
top[R]
width[R]

Public Class Methods

new(height, width, top, left, structure = [], opts = {}) click to toggle source
# File lib/opsicle/monitor/panel.rb, line 19
def initialize(height, width, top, left, structure = [], opts = {})
  @height = height
  @width  = width
  @top    = top
  @left   = left

  @dividers = {
    :left  => opts[:divider_l].to_s,
    :right => opts[:divider_r].to_s,
  }

  @divider_length = @dividers.values.map(&:length).inject(:+)

  @window = Curses::Window.new(@height, @width, @top, @left)

  @subpanels = build_subpanels(structure)

  @spies = {} # data sources for #structure
end

Public Instance Methods

close() click to toggle source
# File lib/opsicle/monitor/panel.rb, line 39
def close
  @window.close
end
refresh() click to toggle source
# File lib/opsicle/monitor/panel.rb, line 43
def refresh
  @subpanels.each(&:refresh) # build changes

  @window.refresh # push changes to window
end
refresh_spies() click to toggle source
# File lib/opsicle/monitor/panel.rb, line 49
def refresh_spies
  @spies.each { |_, s| s.refresh } # refresh data sources
end

Private Instance Methods

build_subpanels(structure) click to toggle source
# File lib/opsicle/monitor/panel.rb, line 55
def build_subpanels(structure)
  subpanels = []

  structure.each_with_index do |row, i|
    next if row.nil? # skip blank rows

    row_cols = row.map { |e| e[0] }.inject(:+)

    col_width = (@width / row_cols) + @divider_length

    col_i = 0

    row.each_with_index do |(tag_cols, data_l, data_r), row_i|
      first_col = row_i == 0
      last_col  = row_i + 1 == row.length

      tag_col_width = if last_col
        @width - ((row_cols - tag_cols) * col_width)
      else
        tag_cols * col_width
      end

      subpanels << Monitor::Subpanel.new(
        @window,
        1,
        tag_col_width,
        i,
        col_i,
        :data_l    => data_l,
        :data_r    => data_r,
        :divider_l => (@dividers[:left] unless first_col),
        :divider_r => (@dividers[:right] unless last_col)
      )

      col_i += tag_col_width
    end
  end

  subpanels
end