summaryrefslogtreecommitdiff
path: root/ext/pty/lib/expect.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pty/lib/expect.rb')
-rw-r--r--ext/pty/lib/expect.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/ext/pty/lib/expect.rb b/ext/pty/lib/expect.rb
index 52396d90bd..54cf709ee2 100644
--- a/ext/pty/lib/expect.rb
+++ b/ext/pty/lib/expect.rb
@@ -17,12 +17,17 @@ class IO
else
raise TypeError, "unsupported pattern class: #{pattern.class}"
end
+ @unusedBuf ||= ''
while true
- if !IO.select([self],nil,nil,timeout) or eof? then
+ if not @unusedBuf.empty?
+ c = @unusedBuf.slice!(0).chr
+ elsif !IO.select([self],nil,nil,timeout) or eof? then
result = nil
+ @unusedBuf = buf
break
+ else
+ c = getc.chr
end
- c = getc.chr
buf << c
if $expect_verbose
STDOUT.print c