Class: Yap::Shell::Repl

Inherits:
Object
  • Object
show all
Defined in:
lib/yap/shell/repl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(world: nil) ⇒ Repl

Returns a new instance of Repl.



12
13
14
15
16
17
18
19
20
21
# File 'lib/yap/shell/repl.rb', line 12

def initialize(world:nil)
  @world = world
  @editor= world.editor

  Treefell['shell'].puts "installing default keybindings"
  install_default_keybindings

  Treefell['shell'].puts "installing default tab completion"
  install_default_tab_completion_proc
end

Instance Attribute Details

#editorObject (readonly)

Returns the value of attribute editor.



10
11
12
# File 'lib/yap/shell/repl.rb', line 10

def editor
  @editor
end

Instance Method Details

#on_input(&blk) ⇒ Object



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
# 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}"
    # editor.history = true?
    line = line_read << "\n"
    begin
      @blk.call(line)
    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::Parser::ParseError => ex
      Treefell['shell'].puts "rescued #{ex}, telling user"
      puts "  Parse error: #{ex.message}"
    end

    ensure_process_group_controls_the_tty
    @world.refresh_prompt
  end
end