Class: Salticid::Interface::HostView
- Defined in:
- lib/salticid/interface/host_view.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#state ⇒ Object
Returns the value of attribute state.
-
#window ⇒ Object
Returns the value of attribute window.
Attributes inherited from View
Instance Method Summary collapse
- #<<(message) ⇒ Object
-
#initialize(interface, params = {}) ⇒ HostView
constructor
A new instance of HostView.
- #on_state_change(&block) ⇒ Object
- #render ⇒ Object
-
#scroll(delta) ⇒ Object
Scrolls the window by delta messages.
- #shutdown ⇒ Object
- #to_s ⇒ Object
Methods inherited from View
Methods included from Resizeable
Constructor Details
#initialize(interface, params = {}) ⇒ HostView
Returns a new instance of HostView.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/salticid/interface/host_view.rb', line 7 def initialize(interface, params = {}) @messages = [] @scroll_position = -1 super @host = params[:host] @host.on_log do || self << end @state = nil @on_state_change = proc { |state| } end |
Instance Attribute Details
#messages ⇒ Object
Returns the value of attribute messages.
5 6 7 |
# File 'lib/salticid/interface/host_view.rb', line 5 def @messages end |
#state ⇒ Object
Returns the value of attribute state.
5 6 7 |
# File 'lib/salticid/interface/host_view.rb', line 5 def state @state end |
#window ⇒ Object
Returns the value of attribute window.
5 6 7 |
# File 'lib/salticid/interface/host_view.rb', line 5 def window @window end |
Instance Method Details
#<<(message) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/salticid/interface/host_view.rb', line 23 def <<() # Scroll if at bottom @scroll_position += 1 if @scroll_position == @messages.size - 1 @messages << if @state != .severity @state = .severity @on_state_change.call(@state) end render end |
#on_state_change(&block) ⇒ Object
37 38 39 |
# File 'lib/salticid/interface/host_view.rb', line 37 def on_state_change(&block) @on_state_change = block end |
#render ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/salticid/interface/host_view.rb', line 41 def render return if @hidden @window.clear lines_left = @height = @scroll_position while >= 0 # Message = @messages[] -= 1 # Time time = .time.strftime "%H:%M:%S" text = .text color = Interface::COLOR_PAIRS[.severity] offset = time.length + 1 width = @width - offset lines = text.scan(/[^\n]{1,#{width}}/m) # Put lines in reverse i = lines.size while i > 0 i -= 1 line = lines[i] lines_left -= 1 break if lines_left < 0 if i.zero? # Put top line @window.setpos lines_left, 0 @window.addstr time + ' ' @window.attron Curses::A_BOLD @window.color_set color if color @window.addstr line else # Put hanging line @window.attron Curses::A_BOLD @window.color_set color if color @window.setpos lines_left, offset @window.addstr line end @window.color_set Interface::COLOR_PAIRS[:info] if color @window.attroff Curses::A_BOLD unless @window.cursor[1] == 0 # Clear rest of line @window.clrtoeol end end end @window.refresh end |
#scroll(delta) ⇒ Object
Scrolls the window by delta messages
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/salticid/interface/host_view.rb', line 104 def scroll(delta) @scroll_position += delta if @scroll_position < 0 @scroll_position = 0 elsif @scroll_position >= @messages.size @scroll_position = @messages.size - 1 end render end |
#shutdown ⇒ Object
115 116 117 118 119 120 |
# File 'lib/salticid/interface/host_view.rb', line 115 def shutdown @host.on_log do || puts .text end @host = nil end |
#to_s ⇒ Object
99 100 101 |
# File 'lib/salticid/interface/host_view.rb', line 99 def to_s @host.name end |