Class: Salticid::Interface
- Defined in:
- lib/salticid/interface.rb,
lib/salticid/interface/view.rb,
lib/salticid/interface/tab_view.rb,
lib/salticid/interface/host_view.rb,
lib/salticid/interface/resizable.rb
Defined Under Namespace
Modules: Resizeable Classes: HostView, TabView, View
Constant Summary collapse
- COLORS =
{ :info => Curses::COLOR_WHITE, :error => Curses::COLOR_RED, :warn => Curses::COLOR_YELLOW, :debug => Curses::COLOR_CYAN, :finished => Curses::COLOR_GREEN }
- COLOR_PAIRS =
{}
- KEY_SPACE =
Keys
32- KEY_ENTER =
13- KEY_SCROLL_UP =
258- KEY_SCROLL_DOWN =
259
Instance Attribute Summary collapse
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#salticid ⇒ Object
readonly
Returns the value of attribute salticid.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_tab(host) ⇒ Object
Add a new tab interface backed by source.
-
#colorize ⇒ Object
Set up colors.
- #delete_tab(target) ⇒ Object
-
#initialize(salticid) ⇒ Interface
constructor
A new instance of Interface.
-
#join ⇒ Object
Join the mainloop.
-
#main ⇒ Object
Mainloop.
-
#resize ⇒ Object
Resize to fit display.
-
#shutdown(and_exit = true) ⇒ Object
Shut down interface.
-
#switch(target = nil) ⇒ Object
Switch to a different conversation.
- #tab ⇒ Object
Constructor Details
#initialize(salticid) ⇒ Interface
Returns a new instance of Interface.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/salticid/interface.rb', line 37 def initialize(salticid) self.class.interfaces << self # Set up ncurses Curses.init_screen Curses.cbreak Curses.noecho Curses.nonl # Gone in Ruby Curses because ??? # Curses.stdscr.intrflush false Curses.stdscr.keypad true Curses.start_color Curses.use_default_colors @salticid = salticid @hosts = [] @tabs = TabView.new( self, :height => 1 ) @tabs.window.keypad true colorize end |
Instance Attribute Details
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
35 36 37 |
# File 'lib/salticid/interface.rb', line 35 def hosts @hosts end |
#salticid ⇒ Object (readonly)
Returns the value of attribute salticid.
35 36 37 |
# File 'lib/salticid/interface.rb', line 35 def salticid @salticid end |
Class Method Details
.interfaces ⇒ Object
25 26 27 |
# File 'lib/salticid/interface.rb', line 25 def self.interfaces @interfaces ||= [] end |
.shutdown(*args) ⇒ Object
29 30 31 32 33 |
# File 'lib/salticid/interface.rb', line 29 def self.shutdown *args @interfaces.each do |i| i.shutdown *args end end |
Instance Method Details
#add_tab(host) ⇒ Object
Add a new tab interface backed by source.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/salticid/interface.rb', line 65 def add_tab(host) @tabs.active.hide if tab hv = HostView.new( self, :host => host, :top => 1, :height => Curses.lines - 1 ) hv.on_state_change do |state| @tabs.render end @tabs << hv tab.show end |
#colorize ⇒ Object
Set up colors
82 83 84 85 86 87 88 |
# File 'lib/salticid/interface.rb', line 82 def colorize COLORS.each_with_index do |c, i| pair_num = i + 1 Curses.init_pair pair_num, c.last, -1 COLOR_PAIRS[c.first] = pair_num end end |
#delete_tab(target) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/salticid/interface.rb', line 90 def delete_tab(target) begin target.hide @tabs.delete target ensure tab.show if tab end end |
#join ⇒ Object
Join the mainloop.
100 101 102 |
# File 'lib/salticid/interface.rb', line 100 def join @main.join end |
#main ⇒ Object
Mainloop
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/salticid/interface.rb', line 105 def main @main = Thread.new do Thread.current.priority = -1 main_thread = Thread.current trap("WINCH") { resize if main_thread.alive? } loop do # Get character if IO.select [$stdin], nil, nil, 1 char = @tabs.window.getch else Thread.pass next end File.open("/tmp/curses.log", "a") { |f| f.puts char.inspect } # Do stuff case char when 9 # tab @tabs.scroll when "q" # q shutdown when Curses::KEY_LEFT @tabs.scroll -1 when Curses::KEY_RIGHT @tabs.scroll 1 when Curses::KEY_PPAGE tab.scroll -tab.height / 2 when Curses::KEY_NPAGE tab.scroll tab.height / 2 when Curses::KEY_UP tab.scroll -1 when Curses::KEY_DOWN tab.scroll 1 end end end end |
#resize ⇒ Object
Resize to fit display
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/salticid/interface.rb', line 148 def resize # We need to nuke ncurses to pick up the new dimensions Curses.def_prog_mode Curses.close_screen Curses.reset_prog_mode height, width = Curses.dimensions # Resize tabs @tabs.resize( :width => width, :height => height ) @tabs.render end |
#shutdown(and_exit = true) ⇒ Object
Shut down interface
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/salticid/interface.rb', line 164 def shutdown(and_exit = true) # Shut down views @tabs.shutdown # Shut down ncurses Curses.echo Curses.nocbreak Curses.nl Curses.close_screen # Stop interface @main.exit rescue nil # Exit if okay exit if and_exit end |
#switch(target = nil) ⇒ Object
Switch to a different conversation
182 183 184 185 186 187 188 189 190 |
# File 'lib/salticid/interface.rb', line 182 def switch(target = nil) if target # Switch to a specific tab @tabs.switch_to_label target else # Switch to the next tab @tabs.scroll end end |
#tab ⇒ Object
192 193 194 |
# File 'lib/salticid/interface.rb', line 192 def tab @tabs.active end |