Module: CTF::IOWithEcho
- Included in:
- IO
- Defined in:
- lib/ctf/io_with_echo.rb
Instance Attribute Summary collapse
-
#echo ⇒ Object
Returns the value of attribute echo.
-
#echo_color ⇒ Object
Returns the value of attribute echo_color.
-
#echo_input ⇒ Object
Returns the value of attribute echo_input.
-
#echo_output ⇒ Object
Returns the value of attribute echo_output.
Instance Method Summary collapse
-
#expect(pattern, timeout = 9999999) ⇒ Object
TODO: Don’t ignore timeout.
- #getc ⇒ Object
- #gets ⇒ Object
- #interactive!(input = STDIN, output = STDOUT) ⇒ Object
- #read(length = nil, outbuf = nil) ⇒ Object
- #write(str) ⇒ Object
Instance Attribute Details
#echo ⇒ Object
Returns the value of attribute echo.
9 10 11 |
# File 'lib/ctf/io_with_echo.rb', line 9 def echo @echo end |
#echo_color ⇒ Object
Returns the value of attribute echo_color.
9 10 11 |
# File 'lib/ctf/io_with_echo.rb', line 9 def echo_color @echo_color end |
#echo_input ⇒ Object
Returns the value of attribute echo_input.
9 10 11 |
# File 'lib/ctf/io_with_echo.rb', line 9 def echo_input @echo_input end |
#echo_output ⇒ Object
Returns the value of attribute echo_output.
9 10 11 |
# File 'lib/ctf/io_with_echo.rb', line 9 def echo_output @echo_output end |
Instance Method Details
#expect(pattern, timeout = 9999999) ⇒ Object
TODO: Don’t ignore timeout
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ctf/io_with_echo.rb', line 45 def expect(pattern, timeout = 9999999) result = nil loop do if pattern.is_a?(Regexp) break if result && result.match(pattern) else break if result && result.end_with?(pattern) end data = getc break unless data if result result << data.chr else result = data.chr end end return result unless result if pattern.is_a?(Regexp) [result] + (result.match(pattern) || [nil]).to_a[1..-1] else [result] end end |
#getc ⇒ Object
40 41 42 |
# File 'lib/ctf/io_with_echo.rb', line 40 def getc super.tap {|result| echo_input_print(result || '') } end |
#gets ⇒ Object
36 37 38 |
# File 'lib/ctf/io_with_echo.rb', line 36 def gets super.tap {|result| echo_input_print(result || '') } end |
#interactive!(input = STDIN, output = STDOUT) ⇒ Object
31 32 33 34 |
# File 'lib/ctf/io_with_echo.rb', line 31 def interactive!(input = STDIN, output = STDOUT) @echo = false super input, output end |
#read(length = nil, outbuf = nil) ⇒ Object
27 28 29 |
# File 'lib/ctf/io_with_echo.rb', line 27 def read(length = nil, outbuf = nil) super(length, outbuf).tap {|result| echo_input_print(result || '') } end |
#write(str) ⇒ Object
22 23 24 25 |
# File 'lib/ctf/io_with_echo.rb', line 22 def write(str) echo_output_print str super str end |