diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-09 14:11:14 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-09 14:11:14 +0000 |
commit | 881bee60d0781b2b4d842aaa3bc2c5a3b04c108f (patch) | |
tree | dfd2ca1ccdc7c91653ee18a11bc5b5a350f6f428 /sample | |
parent | 3f1737d844e29e707003f66acd3fe75cb96776e5 (diff) |
merge revision(s) 57531,57532,57533,57537: [Backport #13191]
pty/shl.rb: update [ci skip]
* sample/pty/shl.rb: stop writer loop when the child exited.
PTY::ChildExited no longer raises asynchronously since r20298.
[ruby-dev:49974] [Bug #13191]
pty/shl.rb: update [ci skip]
* sample/pty/shl.rb: use io/console instead of stty.
[ruby-dev:49974] [Bug #13191]
pty/shl.rb: update [ci skip]
* sample/pty/shl.rb: do not manage array length separately.
[ruby-dev:49974] [Bug #13191]
pty/shl.rb: update [ci skip]
* sample/pty/shl.rb: leap exited child process.
[ruby-dev:49974] [Bug #13191]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@58620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r-- | sample/pty/shl.rb | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/sample/pty/shl.rb b/sample/pty/shl.rb index cdaf8d7398..7bddf7c1ac 100644 --- a/sample/pty/shl.rb +++ b/sample/pty/shl.rb @@ -10,15 +10,15 @@ # q quit require 'pty' +require 'io/console' $shells = [] -$n_shells = 0 $r_pty = nil $w_pty = nil def writer - system "stty -echo raw" + STDIN.raw! begin while true c = STDIN.getc @@ -33,16 +33,17 @@ def writer $reader.raise(nil) return 'Exit' ensure - system "stty echo -raw" + STDIN.cooked! end end $reader = Thread.new { while true begin - next if $r_pty.nil? + Thread.stop unless $r_pty c = $r_pty.getc if c.nil? then + Thread.main.raise('Exit') Thread.stop end print c.chr @@ -59,19 +60,14 @@ $reader = Thread.new { while true print ">> " STDOUT.flush + n = nil case gets when /^c/i - $shells[$n_shells] = PTY.spawn("/bin/csh") - $r_pty,$w_pty = $shells[$n_shells] - $n_shells += 1 - $reader.run - if writer == 'Exit' - $n_shells -= 1 - $shells[$n_shells] = nil - end + $shells << PTY.spawn("/bin/csh") + n = -1 when /^p/i - for i in 0..$n_shells - unless $shells[i].nil? + $shells.each_with_index do |s, i| + if s print i,"\n" end end @@ -79,14 +75,18 @@ while true n = $1.to_i if $shells[n].nil? print "\##{i} doesn't exist\n" - else - $r_pty,$w_pty = $shells[n] - $reader.run - if writer == 'Exit' then - $shells[n] = nil - end + n = nil end when /^q/i exit end + if n + $r_pty, $w_pty, pid = $shells[n] + $reader.run + if writer == 'Exit' then + Process.wait(pid) + $shells[n] = nil + $shells.pop until $shells.empty? or $shells[-1] + end + end end |