From 881bee60d0781b2b4d842aaa3bc2c5a3b04c108f Mon Sep 17 00:00:00 2001 From: nagachika Date: Tue, 9 May 2017 14:11:14 +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_4@58620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sample/pty/shl.rb | 40 ++++++++++++++++++++-------------------- version.h | 2 +- 2 files changed, 21 insertions(+), 21 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 diff --git a/version.h b/version.h index faba56333a..fca385587a 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.4.2" #define RUBY_RELEASE_DATE "2017-05-09" -#define RUBY_PATCHLEVEL 115 +#define RUBY_PATCHLEVEL 116 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 5 -- cgit v1.2.3