module Ripl::MultiLine
# # # This multi-line implementation uses catches the syntax errors that are yielded by unfinsihed statements
works on: 2.0 1.9 1.8 jruby rbx analyze features: [:literal, :string] [:literal, :regexp] [:literal, :array] (mri only) [:literal, :hash] (mri only) [:statement] [:forced] notes: rbx support buggy (depends on rubinius error messages)
Constants
- VERSION
Attributes
engine[RW]
Public Instance Methods
before_loop()
click to toggle source
Calls superclass method
# File lib/ripl/multi_line.rb, line 10 def before_loop @buffer = @buffer_info = nil # include CamelCased implementation require File.join( 'ripl', 'multi_line', config[:multi_line_engine].to_s ) Ripl::MultiLine.engine = Ripl::MultiLine.const_get( config[:multi_line_engine].to_s.gsub(/(^|_)(\w)/){ $2.capitalize } ) Ripl::Shell.include Ripl::MultiLine.engine super end
handle_interrupt()
click to toggle source
remove last line from buffer MAYBE: terminal rewriting
Calls superclass method
# File lib/ripl/multi_line.rb, line 94 def handle_interrupt if @buffer @buffer.pop; @buffer_info.pop; history.pop if @buffer.empty? @buffer = @buffer_info = nil print '[buffer empty]' return super else puts "[previous line removed|#{@buffer.size}]" throw :multiline end else super end end
handle_multiline(type = [:statement])
click to toggle source
# File lib/ripl/multi_line.rb, line 76 def handle_multiline(type = [:statement]) # MAYBE: add second arg for specific information @buffer ||= [] @buffer_info ||= [] @buffer << @input @buffer_info << type throw :multiline end
loop_eval(input)
click to toggle source
Calls superclass method
# File lib/ripl/multi_line.rb, line 84 def loop_eval(input) eval_string = if @buffer then @buffer*"\n" + "\n" + input else input end if type = multiline?(eval_string) handle_multiline(type) end super eval_string end
loop_once()
click to toggle source
Calls superclass method
# File lib/ripl/multi_line.rb, line 34 def loop_once catch(:multiline) do super if config[:multi_line_history] && @buffer && @input (@buffer.size + 1).times{ history.pop } if config[:multi_line_history] == :compact history_entry = '' @buffer.zip(@buffer_info){ |str, type| history_entry << str history_entry << case when !type.is_a?(Array) "\n" # fallback to :block for unsure when type[0] == :statement '; ' when type[0] == :literal && ( type[1] == :string || type[1] == :regexp ) '\n' else '' end } history_entry << @input history << history_entry else # true or :block history << (@buffer << @input).join("\n") end end @buffer = @buffer_info = nil end end
multiline?(eval_string)
click to toggle source
This method is overwritten by a multi-line implementation in lib/multi_line/*.rb
It should return a true value for a string that is unfinished and a false one for complete expressions, which should get evaluated. It's also possible (and encouraged) to return an array of symbols describing what's the reason for continuing the expression (this is used in the :compact history and gets passed to the prompt proc.
# File lib/ripl/multi_line.rb, line 72 def multiline?(eval_string) false end
prompt()
click to toggle source
Calls superclass method
# File lib/ripl/multi_line.rb, line 21 def prompt if @buffer config[:multi_line_prompt].respond_to?(:call) ? config[:multi_line_prompt].call( *@buffer_info[-1] ) : config[:multi_line_prompt] else super end rescue StandardError, SyntaxError warn "ripl: Error while creating prompt:\n"+ format_error($!) Ripl::Shell::OPTIONS[:prompt] end