Class: IRB::Driver::TTY
- Inherits:
-
Object
- Object
- IRB::Driver::TTY
- Defined in:
- lib/irb/driver/tty.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context_stack ⇒ Object
readonly
Returns the value of attribute context_stack.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#consume ⇒ Object
TODO make it take the current context instead of storing it.
- #context ⇒ Object
-
#initialize(input = $stdin, output = $stdout) ⇒ TTY
constructor
A new instance of TTY.
- #readline ⇒ Object
-
#run(context) ⇒ Object
Feeds input into a given context.
Constructor Details
#initialize(input = $stdin, output = $stdout) ⇒ TTY
Returns a new instance of TTY.
8 9 10 11 12 |
# File 'lib/irb/driver/tty.rb', line 8 def initialize(input = $stdin, output = $stdout) @input = input @output = output @context_stack = [] end |
Instance Attribute Details
#context_stack ⇒ Object (readonly)
Returns the value of attribute context_stack.
6 7 8 |
# File 'lib/irb/driver/tty.rb', line 6 def context_stack @context_stack end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/irb/driver/tty.rb', line 6 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
6 7 8 |
# File 'lib/irb/driver/tty.rb', line 6 def output @output end |
Instance Method Details
#consume ⇒ Object
TODO make it take the current context instead of storing it
24 25 26 27 28 29 |
# File 'lib/irb/driver/tty.rb', line 24 def consume readline rescue Interrupt context.clear_buffer "" end |
#context ⇒ Object
14 15 16 |
# File 'lib/irb/driver/tty.rb', line 14 def context @context_stack.last end |
#readline ⇒ Object
18 19 20 21 |
# File 'lib/irb/driver/tty.rb', line 18 def readline @output.print(context.prompt) @input.gets end |
#run(context) ⇒ Object
Feeds input into a given context.
Ensures that the standard output object is a OutputRedirector, or a subclass thereof.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/irb/driver/tty.rb', line 35 def run(context) @context_stack << context before, $stdout = $stdout, OutputRedirector.new unless $stdout.is_a?(OutputRedirector) while line = consume break unless context.process_line(line) end ensure @context_stack.pop $stdout = before if before end |