Module: Ripl::Johnson::MultiLine

Defined in:
lib/ripl/johnson/multi_line.rb

Instance Method Summary collapse

Instance Method Details

#before_loopObject



2
3
4
5
# File 'lib/ripl/johnson/multi_line.rb', line 2

def before_loop
  super
  @buffer = @unterminated_string = nil
end

#handle_interruptObject



38
39
40
41
# File 'lib/ripl/johnson/multi_line.rb', line 38

def handle_interrupt
  @buffer = @unterminated_string = nil
  super
end

#loop_eval(input) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/ripl/johnson/multi_line.rb', line 29

def loop_eval(input)
  if @buffer
    join = @unterminated_string ? "" : "\n"
    super @buffer* join + join + input
  else
    super input
  end
end

#loop_onceObject



11
12
13
14
15
16
# File 'lib/ripl/johnson/multi_line.rb', line 11

def loop_once
  catch(:multiline) do
    super
    @buffer = nil
  end
end


18
19
20
21
22
23
24
25
26
27
# File 'lib/ripl/johnson/multi_line.rb', line 18

def print_eval_error(e)
  if e.is_a?(::Johnson::Error) && e.original_exception.to_s[/^SyntaxError/]
    @unterminated_string = e.to_s[/unterminated string literal/]
    @buffer ||= []
    @buffer << @input
    throw :multiline
  else
    super
  end
end

#promptObject



7
8
9
# File 'lib/ripl/johnson/multi_line.rb', line 7

def prompt
  @buffer ? config[:johnson_multi_line_prompt] : super
end