Class: Rios::Proxy
Constant Summary collapse
- DEFAULT_COMMAND =
ENV["SHELL"]
Instance Method Summary collapse
-
#initialize ⇒ Proxy
constructor
A new instance of Proxy.
-
#input(string) ⇒ Object
emulate user input.
-
#listen(command = nil, &block) ⇒ Object
begin proxy session.
-
#on_finish(&block) ⇒ Object
register handler which will be called when target program exits.
-
#on_input(&block) ⇒ Object
register handler which will be called when user inputs characters.
-
#on_output(&block) ⇒ Object
register handler which will be called when target program outputs characters.
-
#output(string) ⇒ Object
output string to the stdout (usually terminal).
Constructor Details
Instance Method Details
#input(string) ⇒ Object
emulate user input
36 37 38 39 40 41 |
# File 'lib/rios/proxy.rb', line 36 def input(string) @pty_lock.synchronize { terminal.master.syswrite(string) } nil end |
#listen(command = nil, &block) ⇒ Object
begin proxy session
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rios/proxy.rb', line 54 def listen(command = nil, &block) @command = command || DEFAULT_COMMAND in_raw_mode { fork { fork { do_command(block) } do_output() } Signal.trap(:CHLD) { terminal.master.close() } # TODO: Is this OK? do_input() } end |
#on_finish(&block) ⇒ Object
register handler which will be called when target program exits
30 31 32 |
# File 'lib/rios/proxy.rb', line 30 def on_finish(&block) @on_finishes.push(block) end |
#on_input(&block) ⇒ Object
register handler which will be called when user inputs characters
18 19 20 |
# File 'lib/rios/proxy.rb', line 18 def on_input(&block) @input_filters.push(block) end |
#on_output(&block) ⇒ Object
register handler which will be called when target program outputs characters
24 25 26 |
# File 'lib/rios/proxy.rb', line 24 def on_output(&block) @output_filters.push(block) end |
#output(string) ⇒ Object
output string to the stdout (usually terminal)
45 46 47 48 49 50 |
# File 'lib/rios/proxy.rb', line 45 def output(string) @pty_lock.synchronize { $stdout.syswrite(string) } nil end |