Module: PtyCompat::NodePty
- Defined in:
- lib/pty_compat/node_pty.rb
Overview
Provide a similar interface as the PTY one that could work on platforms that don't support PTY (for example Windows). Internally uses NodeJS's node-pty.
Public API collapse
-
#last_status ⇒ Process::Status
Last process status.
-
#spawn(*args) {|r, w, pid| ... } ⇒ Array<IO, Integer>?
Spawn a command in a PTY and return or yield its outputs, input and pid.
Instance Method Details
#last_status ⇒ Process::Status
Returns Last process status.
36 37 38 |
# File 'lib/pty_compat/node_pty.rb', line 36 def last_status @last_wait_thr.value end |
#spawn(*args) {|r, w, pid| ... } ⇒ Array<IO, Integer>?
Spawn a command in a PTY and return or yield its outputs, input and pid
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pty_compat/node_pty.rb', line 20 def spawn(*args) env, cmd = args.first.is_a?(Hash) ? [[args.first], args[1..]] : [[], args] node_args = env + ['node', "#{__dir__}/assets/node_pty_bridge.js"] + cmd if block_given? Open3.popen3(*node_args) do |stdin, stdout, stderr, wait_thr| @last_wait_thr = wait_thr yield popen3_to_pty(stdin, stdout, stderr, wait_thr) end else stdin, stdout, stderr, wait_thr = Open3.popen3(*node_args) @last_wait_thr = wait_thr popen3_to_pty(stdin, stdout, stderr, wait_thr) end end |