Class: Opsicle::Monitor::Subpanel

Inherits:
Object
  • Object
show all
Defined in:
lib/opsicle/monitor/subpanel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, height, width, top, left, opts = {}) ⇒ Subpanel

Returns a new instance of Subpanel.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/opsicle/monitor/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

Instance Attribute Details

#content_widthObject (readonly)

Returns the value of attribute content_width.



11
12
13
# File 'lib/opsicle/monitor/subpanel.rb', line 11

def content_width
  @content_width
end

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/opsicle/monitor/subpanel.rb', line 9

def data
  @data
end

#dividersObject (readonly)

Returns the value of attribute dividers.



10
11
12
# File 'lib/opsicle/monitor/subpanel.rb', line 10

def dividers
  @dividers
end

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/opsicle/monitor/subpanel.rb', line 5

def height
  @height
end

#leftObject (readonly)

Returns the value of attribute left.



8
9
10
# File 'lib/opsicle/monitor/subpanel.rb', line 8

def left
  @left
end

#topObject (readonly)

Returns the value of attribute top.



7
8
9
# File 'lib/opsicle/monitor/subpanel.rb', line 7

def top
  @top
end

#widthObject (readonly)

Returns the value of attribute width.



6
7
8
# File 'lib/opsicle/monitor/subpanel.rb', line 6

def width
  @width
end

Instance Method Details

#refreshObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/opsicle/monitor/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