class Xtop::XtopView
Public Class Methods
new(checkers)
click to toggle source
# 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
Public Instance Methods
redraw()
click to toggle source
redraw the main view
# 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)
click to toggle source
use this to update the status of a single URL.
# File lib/xtop/xtop_view.rb, line 12 def update_status(key, value) @statuses[key] = value redraw end
Private Instance Methods
add_col2_line(val1, val2, opts={color: 4})
click to toggle source
# File lib/xtop/xtop_view.rb, line 58 def add_col2_line(val1, val2, opts={color: 4}) attron(color_pair(opts[:color])) # change color addstr(sprintf("%-#{cols-10}s%-10s", val1, val2)) # write string attroff(color_pair(opts[:color])) # change color back end
init_colors(colormap=[:green, :yellow, :red, :white])
click to toggle source
# File lib/xtop/xtop_view.rb, line 48 def init_colors(colormap=[:green, :yellow, :red, :white]) constants = {green: COLOR_GREEN, yellow: COLOR_YELLOW, red: COLOR_RED, white: COLOR_WHITE} start_color # initialize color output @colormap = {} colormap.each_with_index do |color, i| @colormap[color] = i+1 init_pair(i+1, constants[color], COLOR_BLACK) # save a fg/bg color pair at index i+1 end end