Class: Rexec::Terminal
- Inherits:
-
Object
- Object
- Rexec::Terminal
- Defined in:
- lib/rexec/terminal.rb
Overview
WebSocket terminal connection.
Instance Attribute Summary collapse
-
#closed ⇒ Object
(also: #closed?)
readonly
Returns the value of attribute closed.
Instance Method Summary collapse
-
#close ⇒ Object
Close the terminal connection.
-
#initialize(ws) ⇒ Terminal
constructor
A new instance of Terminal.
-
#on_close { ... } ⇒ Object
Register a handler for connection close.
-
#on_data {|data| ... } ⇒ Object
Register a handler for incoming data.
-
#on_error {|error| ... } ⇒ Object
Register a handler for errors.
-
#resize(cols, rows) ⇒ Object
Resize the terminal.
-
#write(data) ⇒ Object
Send data to the terminal.
Constructor Details
#initialize(ws) ⇒ Terminal
Returns a new instance of Terminal.
10 11 12 13 14 15 16 17 18 |
# File 'lib/rexec/terminal.rb', line 10 def initialize(ws) @ws = ws @closed = false @data_handlers = [] @close_handlers = [] @error_handlers = [] setup_handlers end |
Instance Attribute Details
#closed ⇒ Object (readonly) Also known as: closed?
Returns the value of attribute closed.
8 9 10 |
# File 'lib/rexec/terminal.rb', line 8 def closed @closed end |
Instance Method Details
#close ⇒ Object
Close the terminal connection.
62 63 64 65 66 67 |
# File 'lib/rexec/terminal.rb', line 62 def close return if @closed @closed = true @ws.close end |
#on_close { ... } ⇒ Object
Register a handler for connection close.
50 51 52 |
# File 'lib/rexec/terminal.rb', line 50 def on_close(&block) @close_handlers << block end |
#on_data {|data| ... } ⇒ Object
Register a handler for incoming data.
43 44 45 |
# File 'lib/rexec/terminal.rb', line 43 def on_data(&block) @data_handlers << block end |
#on_error {|error| ... } ⇒ Object
Register a handler for errors.
57 58 59 |
# File 'lib/rexec/terminal.rb', line 57 def on_error(&block) @error_handlers << block end |
#resize(cols, rows) ⇒ Object
Resize the terminal.
33 34 35 36 37 38 |
# File 'lib/rexec/terminal.rb', line 33 def resize(cols, rows) raise TerminalClosedError if @closed msg = { type: "resize", cols: cols, rows: rows }.to_json @ws.send(msg) end |
#write(data) ⇒ Object
Send data to the terminal.
23 24 25 26 27 |
# File 'lib/rexec/terminal.rb', line 23 def write(data) raise TerminalClosedError if @closed @ws.send(data) end |