Class: Pssh::Console
- Inherits:
-
Object
- Object
- Pssh::Console
- Defined in:
- lib/pssh/console.rb
Constant Summary collapse
- COMMANDS =
%w(list block unblock sessions kill-session exit).sort
- BANNER =
" ------------------------------------------------------------------\n help\\t\\tDisplays this help menu.\n info\\t\\tDisplays current tmux settings and configuration.\n list[ sessions]\\tShow the currently open sessions.\n kill-session[s]\\tKill either all sessions or a specific by id.\n --all\\t\\tKills all the open sessions.\n 'session id'\\tKills only the session specified by the id.\n exit\\t\\tCloses all active sessions and exits.\n ------------------------------------------------------------------\n Tip: Use tab-completion for commands and session ids.\n"
Instance Method Summary collapse
- #completion_proc ⇒ Object
-
#initialize(opts = {}) ⇒ Console
constructor
A new instance of Console.
Constructor Details
#initialize(opts = {}) ⇒ Console
Returns a new instance of Console.
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pssh/console.rb', line 18 def initialize(opts = {}) @pty = opts[:pty] @web = opts[:web] begin puts "[ pssh terminal ]" puts "Service started on port #{Pssh.port}." puts "Type 'help' for more information." Readline.completion_append_character = " " Readline.completion_proc = completion_proc while command = Readline.readline(Pssh.prompt, true) command.strip! command.gsub!(/\s+/, ' ') case command when 'help' puts BANNER.gsub(/^ {6}/,'') when 'exit' @pty.kill_all_sessions Kernel.exit! when 'info' puts 'Current Configuration:' if @pty.path puts "Socket: #{@pty.path}" puts "(Attach to this socket with `#{@pty.attach_cmd}`)" else puts 'Connections are made to a vanilla shell.' end when 'list sessions', 'list' @pty.sessions.each do |k,v| puts v[:user_string] end when /^kill-sessions?\s?(.*)$/ if $1 == '--all' puts 'disconnecting all clients' @pty.kill_all_sessions else puts "disconnecting #{$1}" if @pty.sessions.keys.include?($1) @pty.sessions[$1][:socket].close! else @pty.sessions.each do |k, sess| if sess[:username] == $1 sess[:socket].close! end end end end end end rescue Exception => e puts e.inspect puts e.backtrace retry end end |
Instance Method Details
#completion_proc ⇒ Object
77 78 79 |
# File 'lib/pssh/console.rb', line 77 def completion_proc @completion_proc ||= proc { |s| (COMMANDS + Pssh.open_sessions.keys + Pssh.open_sessions.values.uniq).grep( /^#{Regexp.escape(s)}/ ) } end |