Skip to content
This repository was archived by the owner on Mar 12, 2023. It is now read-only.

Refactor REPL manager #78

Merged
merged 13 commits into from
Dec 1, 2020
Prev Previous commit
Next Next commit
Tweak the order of manager steps
  • Loading branch information
0x2c7 committed Nov 30, 2020
commit f982e10a06abce2cfada959fa044a556965a8d35
6 changes: 4 additions & 2 deletions lib/ruby_jard/pry_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ def handle_line(line, *args)
exec_hook :after_handle_line, *args, self
end

def repl(target = nil)
def start(target = nil)
::Readline.input = @redirected_input
::Readline.output = @redirected_output
PryReplProxy.new(self, target: target).start
ensure
end

def stop
::Readline.input = @original_input
::Readline.output = @original_output
end
Expand Down
14 changes: 8 additions & 6 deletions lib/ruby_jard/repl_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@ def repl(current_binding)

@state.ready!
@state.clear_pager!
@interceptor.start

set_console_raw!

@interceptor.start
unless @interceptor.interceptable?
@console.output.puts '*Warning*: One of Jard\'s depedencies (PTY or Readline) is not available or '\
'patched by another gem. Key bindings are disabled. There may be other side effects.'
end

pry_proxy.repl(current_binding)
@pry_proxy = create_pry_proxy
@pry_proxy.start(current_binding)
ensure
set_console_cooked!
@state.exiting!
@interceptor.stop
@pry_proxy.stop
set_console_cooked!
end

private

def pry_proxy
@pry_proxy = PryProxy.new(
def create_pry_proxy
PryProxy.new(
original_input: @interceptor.original_input,
original_output: @interceptor.original_output,
redirected_input: @interceptor.redirected_input,
Expand Down