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
# File 'lib/yap/shell/repl.rb', line 12

def initialize(world:nil)
  @world = world
  @editor= world.editor
  install_default_keybindings
  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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/yap/shell/repl.rb', line 19

def on_input(&blk)
  @blk = blk

  @world.editor.on_read_line do |event|
    # editor.history = true?
    line = event[:payload][:line]
    begin
      @blk.call(line)
      @world.editor.redraw_prompt
    rescue ::Yap::Shell::CommandUnknownError => ex
      puts "  CommandError: #{ex.message}"
    ensure
      @world.editor.reset_line
    end

    ensure_process_group_controls_the_tty
    @world.refresh_prompt
  end
end