Class: SshTunnels::UI
- Inherits:
-
Object
- Object
- SshTunnels::UI
- Defined in:
- lib/ssh_tunnels/ui.rb
Overview
rubocop:disable Metrics/ClassLength User Interface
Constant Summary collapse
- IDENTIFIERS =
['1'..'9', 'a'..'z', 'A'..'Z'].map(&:to_a).flatten
Instance Method Summary collapse
-
#initialize(tunnels) ⇒ UI
constructor
A new instance of UI.
- #run ⇒ Object
- #setup ⇒ Object
- #shutdown(error = nil) ⇒ Object
Constructor Details
#initialize(tunnels) ⇒ UI
Returns a new instance of UI.
9 10 11 |
# File 'lib/ssh_tunnels/ui.rb', line 9 def initialize(tunnels) @tunnels = tunnels end |
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/ssh_tunnels/ui.rb', line 26 def run setup monitor rescue Net::SSH::Disconnect, Errno::ECONNRESET => e shutdown("Error encountered: #{e}") ensure Curses.close_screen end |
#setup ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ssh_tunnels/ui.rb', line 13 def setup Curses.init_screen Curses.start_color Curses.init_pair(1, Curses::COLOR_WHITE, Curses::COLOR_BLACK) Curses.init_pair(2, Curses::COLOR_BLUE, Curses::COLOR_BLACK) Curses.init_pair(3, Curses::COLOR_GREEN, Curses::COLOR_BLACK) Curses.init_pair(4, Curses::COLOR_CYAN, Curses::COLOR_BLACK) Curses.init_pair(5, Curses::COLOR_RED, Curses::COLOR_BLACK) Curses.timeout = 1000 Curses.curs_set(0) Curses.noecho end |
#shutdown(error = nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/ssh_tunnels/ui.rb', line 35 def shutdown(error = nil) Curses.close_screen puts error unless error.nil? puts 'Shutting down connections.' @tunnels.select(&:active?).each(&:shutdown) puts 'Shutdown complete.' end |