Class: Rdeadman::Display

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

Instance Method Summary collapse

Constructor Details

#initializeDisplay

Returns a new instance of Display.



57
58
59
60
61
62
63
64
# File 'lib/rdeadman/monitor.rb', line 57

def initialize
  Curses.init_screen
  Curses.curs_set(0) # Invisible cursor
  Curses.start_color
  Curses.use_default_colors
  Curses.init_pair(1, Curses::COLOR_GREEN, -1)
  Curses.init_pair(2, Curses::COLOR_RED, -1)
end

Instance Method Details

#closeObject



66
67
68
# File 'lib/rdeadman/monitor.rb', line 66

def close
  Curses.close_screen
end

#draw(host_monitors) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/rdeadman/monitor.rb', line 70

def draw(host_monitors)
  Curses.clear
  draw_title
  draw_reference
  host_monitors.each_with_index { |host_monitor, index| draw_host_status(host_monitor, index + 4) }
  Curses.refresh
end

#draw_host_status(host_monitor, line) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rdeadman/monitor.rb', line 90

def draw_host_status(host_monitor, line)
  Curses.setpos(line, 0)
  status = [
    host_monitor.host.ljust(16),
    host_monitor.address.ljust(17),
    "#{host_monitor.loss_rate}%".rjust(5),
    "#{host_monitor.results.last}".rjust(5),
    "#{host_monitor.avg_rtt}".rjust(5),
    "#{host_monitor.sent_packets}".rjust(5),
    "#{host_monitor.result_graph}"
  ].join("  ")

  Curses.addstr(status)
end

#draw_referenceObject



85
86
87
88
# File 'lib/rdeadman/monitor.rb', line 85

def draw_reference
  Curses.setpos(3, 0)
  Curses.addstr(" HOSTNAME           ADDRESS             LOSS   RTT   AVG   SNT  RESULT")
end

#draw_titleObject



78
79
80
81
82
83
# File 'lib/rdeadman/monitor.rb', line 78

def draw_title
  Curses.setpos(0, 0)
  Curses.addstr(" From: #{Socket.gethostname} [ver #{Rdeadman::VERSION}]")
  Curses.setpos(1, 0)
  Curses.addstr("   RTT Scale 10ms. Keys: (r)efresh")
end