Class: Xtop::XtopView

Inherits:
Object
  • Object
show all
Includes:
Curses
Defined in:
lib/xtop/xtop_view.rb

Instance Method Summary collapse

Constructor Details

#initialize(checkers) ⇒ XtopView

Returns a new instance of XtopView.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/xtop/xtop_view.rb', line 32

def initialize(checkers)
  init_screen
  init_colors

  @statuses = Hash[checkers.map { |k,v| [k, "white"] }]

  Thread.new do
    while true
      UrlChecker.check(self, checkers)
      sleep(0.8)
    end
  end
end

Instance Method Details

#redrawObject

redraw the main view



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/xtop/xtop_view.rb', line 18

def redraw
  clear # clear screen
  setpos(0, 0) # start at top of screen
  add_col2_line("Xtop", "RentPath") # render title line

  setpos(2, 0) # skip a line
  add_col2_line("URL", "STATUS") # render column headers
  @statuses.each do |k,v| # render each line
    add_col2_line(k, v, color: @colormap[v.to_sym])
  end
  curs_set(0) # clear cursor
  refresh # show
end

#update_status(key, value) ⇒ Object

use this to update the status of a single URL.



12
13
14
15
# File 'lib/xtop/xtop_view.rb', line 12

def update_status(key, value)
  @statuses[key] = value
  redraw
end