23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/yap/shell/repl.rb', line 23
def on_input(&blk)
@blk = blk
@world.editor.on_read_line do |event|
line_read = event[:payload][:line]
Treefell['shell'].puts "editor line read: #{line_read.inspect}"
line = line_read << "\n"
begin
@blk.call(line)
@world.editor.redraw_prompt
rescue Yap::Shell::Parser::Lexer::NonterminatedString,
Yap::Shell::Parser::Lexer::LineContinuationFound => ex
Treefell['shell'].puts "rescued #{ex}, asking user for more input"
more_input = read_another_line_of_input
if more_input
line << more_input
retry
end
rescue ::Yap::Shell::CommandUnknownError => ex
Treefell['shell'].puts "rescued #{ex}, telling user"
puts " CommandError: #{ex.message}"
rescue ::Yap::Shell::Parser::ParseError => ex
Treefell['shell'].puts "rescued #{ex}, telling user"
puts " Parse error: #{ex.message}"
ensure
@world.editor.reset_line
end
ensure_process_group_controls_the_tty
@world.refresh_prompt
end
end
|