Class: IO

Inherits:
Object
  • Object
show all
Defined in:
lib/expect/io.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) _io_buf0



18
# File 'lib/expect/io.rb', line 18

def _io_buf0    ; @_buf0_                               ; end

- (Object) _io_buf1



19
# File 'lib/expect/io.rb', line 19

def _io_buf1    ; @_buf1_                               ; end

- (Boolean) _io_exit?



17
# File 'lib/expect/io.rb', line 17

def _io_exit?   ; _io_buf0.last.nil?                    ; end

- (Boolean) _io_more?



16
# File 'lib/expect/io.rb', line 16

def _io_more?   ; ! IO.select([self],nil,nil,0.20).nil? ; end

- (Object) _io_read_char



32
33
34
35
36
37
# File 'lib/expect/io.rb', line 32

def _io_read_char
  c = getc
  @_buf0_ << c.chr unless c.nil?
  exp_internal "buf0: [#{_io_string.gsub(/\n/,'\n').gsub(/\r/,'\r')}]"
  c
end

- (Object) _io_save(no_echo = false, match_string = nil, ch = nil)



8
9
10
11
12
13
14
15
# File 'lib/expect/io.rb', line 8

def _io_save(no_echo=false, match_string=nil, ch=nil)
  s = _io_string!
  exp_internal match_string
  exp_internal s
  s = s.chomp(ch) if ch
  _io_buf1 << s
  _io_buf1
end

- (Object) _io_string



20
# File 'lib/expect/io.rb', line 20

def _io_string  ; @_buf0_.join                          ; end

- (Object) _io_string!



21
22
23
24
25
# File 'lib/expect/io.rb', line 21

def _io_string!
  b = _io_string
  @_buf0_=[]
  b
end

- (Object) _io_sync



26
27
28
29
30
31
# File 'lib/expect/io.rb', line 26

def _io_sync
  @_buf0_ ||=[]
  while _io_more?
    break if _io_read_char.nil?
  end
end

- (Object) readbuf(ti = 10)



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/expect/io.rb', line 38

def readbuf(ti=10)
  @_buf0_, @_buf1_=[],[]
  loop do
    if IO.select([self],nil,nil,ti).nil?
      exp_internal "IO.select is NIL (TIMEOUT=#{ti})"
      @_buf0_ << nil
    else
      _io_read_char
    end
    yield(self)
  end
end