Skip to content

Commit

Permalink
buffer kept in an array instead of string + ctrl_c to remove last line
Browse files Browse the repository at this point in the history
  • Loading branch information
janlelis committed Dec 2, 2010
1 parent eecc215 commit fe1e3bd
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions lib/ripl/multi_line.rb
Expand Up @@ -22,15 +22,37 @@ def loop_once

def print_eval_error(e)
if e.is_a?(SyntaxError) && e.message =~ /unexpected \$end|unterminated string meets end of file/
(@buffer ||= '') << @input+"\n"
@buffer ||= []
@buffer << @input
throw :multiline
else
super
end
end

def loop_eval(input)
if @buffer
super @buffer*"\n" + "\n" + input
else
super input
end
end

def eval_input(input)
super(@buffer ? @buffer + input : input)
# remove last line from buffer
# TODO: nicer interface (rewriting?)
def handle_interrupt
if @buffer
@buffer.pop
if @buffer.empty?
@buffer = nil
return super
else
puts "[previous line removed]"
throw :multiline
end
else
super
end
end
end
end
Expand Down

0 comments on commit fe1e3bd

Please sign in to comment.