Class: IRB::Driver::TTY
Constant Summary
- CLEAR_LAST_LINE =
move_one_line_up + move_to_begin_of_line + clear_to_end_of_line
Instance Attribute Summary (collapse)
-
- (Object) context_stack
readonly
Returns the value of attribute context_stack.
-
- (Object) input
readonly
Returns the value of attribute input.
-
- (Object) output
readonly
Returns the value of attribute output.
Instance Method Summary (collapse)
-
- (Object) consume
TODO make it take the current context instead of storing it.
- - (Object) context
-
- (TTY) initialize(input = $stdin, output = $stdout)
constructor
A new instance of TTY.
- - (Object) process_input(line)
- - (Object) readline
-
- (Object) run(context)
Feeds input into a given context.
- - (Object) update_last_line(prompt, reformatted_line)
Constructor Details
- (TTY) initialize(input = $stdin, output = $stdout)
A new instance of TTY
13 14 15 16 17 |
# File 'lib/irb/driver/tty.rb', line 13 def initialize(input = $stdin, output = $stdout) @input = input @output = output @context_stack = [] end |
Instance Attribute Details
- (Object) context_stack (readonly)
Returns the value of attribute context_stack
11 12 13 |
# File 'lib/irb/driver/tty.rb', line 11 def context_stack @context_stack end |
- (Object) input (readonly)
Returns the value of attribute input
11 12 13 |
# File 'lib/irb/driver/tty.rb', line 11 def input @input end |
- (Object) output (readonly)
Returns the value of attribute output
11 12 13 |
# File 'lib/irb/driver/tty.rb', line 11 def output @output end |
Instance Method Details
- (Object) consume
TODO make it take the current context instead of storing it
29 30 31 32 33 34 |
# File 'lib/irb/driver/tty.rb', line 29 def consume readline rescue Interrupt context.clear_buffer "" end |
- (Object) context
19 20 21 |
# File 'lib/irb/driver/tty.rb', line 19 def context @context_stack.last end |
- (Object) process_input(line)
41 42 43 44 45 |
# File 'lib/irb/driver/tty.rb', line 41 def process_input(line) context.process_line(line) do |prompt, updated_line| update_last_line(prompt, updated_line) end end |
- (Object) readline
23 24 25 26 |
# File 'lib/irb/driver/tty.rb', line 23 def readline @output.print(context.prompt) @input.gets end |
- (Object) run(context)
Feeds input into a given context.
Ensures that the standard output object is a OutputRedirector, or a subclass thereof.
51 52 53 54 55 56 57 58 59 |
# File 'lib/irb/driver/tty.rb', line 51 def run(context) @context_stack << context while line = consume continue = process_input(line) break unless continue end ensure @context_stack.pop end |
- (Object) update_last_line(prompt, reformatted_line)
36 37 38 39 |
# File 'lib/irb/driver/tty.rb', line 36 def update_last_line(prompt, reformatted_line) @output.print CLEAR_LAST_LINE @output.puts("#{prompt}#{reformatted_line}") end |