Class: Xlogin::Telnet
- Inherits:
-
Net::Telnet
- Object
- Net::Telnet
- Xlogin::Telnet
- Includes:
- SessionModule
- Defined in:
- lib/xlogin/telnet.rb
Instance Attribute Summary
Attributes included from SessionModule
Instance Method Summary collapse
-
#initialize(args) ⇒ Telnet
constructor
A new instance of Telnet.
- #interact! ⇒ Object
Methods included from SessionModule
#close, #disable_log, #duplicate, #enable_log, #expect, #log_message, #print, #prompt, #prompt_pattern, #puts, #type, #waitfor
Constructor Details
#initialize(args) ⇒ Telnet
Returns a new instance of Telnet.
10 11 12 13 14 15 16 |
# File 'lib/xlogin/telnet.rb', line 10 def initialize(args) username = args.delete('Username') password = args.delete('Password') super(args) login(*[username, password].compact) if username || password end |
Instance Method Details
#interact! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/xlogin/telnet.rb', line 18 def interact! $stdin.raw! enable_log($stdout) loop do rs, _ = IO.select([$stdin, @sock]) rs.each do |fh| case fh when $stdin bs = '' begin bs = fh.read_nonblock(1) if bs == "\e" bs << fh.read_nonblock(3) bs << fh.read_nonblock(2) end rescue IO::WaitReadable end raise EOFError if bs == "\u001D" # <Ctrl-]> to force quit @sock.syswrite(bs) when @sock begin (fh.readpartial(1024)) rescue Errno::EAGAIN retry end end end end rescue EOFError, Errno::ECONNRESET $stdout.puts "\r\n", "Conneciton closed.", "\r\n" close ensure $stdin.cooked! end |