Module: Ripl::Rc::Multiline
- Includes:
- U
- Defined in:
- lib/ripl/rc/multiline.rb
Overview
Constant Summary
collapse
- ERROR_REGEXP =
test those:
ruby -e '"'
ruby -e '{'
ruby -e '['
ruby -e '('
ruby -e '/'
ruby -e 'class C'
ruby -e 'def f'
ruby -e 'begin'
Regexp.new(
[ "unterminated \\w+ meets end of file",
"syntax error, unexpected \\$end",
"expecting '.+'( or '.+')*",
"syntax error, unexpected end-of-file",
].join('|'))
Instance Method Summary
collapse
Methods included from U
included
#squeeze_history
#cwd, #home, #snip, #strip_backtrace
#short_inspect
Methods included from Color::Imp
#black, #blue, #color, #colors, #cyan, #find_color, #green, #magenta, #red, #reset, #white, #yellow
Instance Method Details
#before_loop ⇒ Object
28
29
30
31
32
|
# File 'lib/ripl/rc/multiline.rb', line 28
def before_loop
return super if Multiline.disabled?
@rc_multiline_buffer = []
super
end
|
#handle_interrupt ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/ripl/rc/multiline.rb', line 71
def handle_interrupt
return super if Multiline.disabled?
if @rc_multiline_buffer.empty?
super
else
line = @rc_multiline_buffer.pop
print "[removed this line: #{line}]"
super
throw :rc_multiline_cont
end
end
|
#loop_eval(input) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/ripl/rc/multiline.rb', line 61
def loop_eval(input)
return super if Multiline.disabled?
if @rc_multiline_buffer.empty?
super
else
@rc_multiline_buffer << input
super @rc_multiline_buffer.join("\n")
end
end
|
#loop_once ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/ripl/rc/multiline.rb', line 43
def loop_once
return super if Multiline.disabled?
catch(:rc_multiline_cont) do
super
@rc_multiline_buffer.clear
end
end
|
#print_eval_error(e) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/ripl/rc/multiline.rb', line 51
def print_eval_error(e)
return super if Multiline.disabled?
if e.is_a?(SyntaxError) && e.message =~ ERROR_REGEXP
@rc_multiline_buffer << @input if @rc_multiline_buffer.empty?
throw :rc_multiline_cont
else
super
end
end
|
#prompt ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/ripl/rc/multiline.rb', line 34
def prompt
return super if Multiline.disabled?
if @rc_multiline_buffer.empty?
super
else
"#{' '*(@prompt.size-2)}| "
end
end
|