From 657a806711577f275425853632f3af0252a43ae7 Mon Sep 17 00:00:00 2001 From: usa Date: Sun, 30 Apr 2017 13:40:08 +0000 Subject: 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_3@58516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sample/pty/shl.rb | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'sample') 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 -- cgit v1.2.3