Prevent the input prompt from being mangled by asynchronous prints.

bug/bundler_fix
Dylan Davis 2016-11-16 20:43:07 -07:00
parent c0af5b690d
commit 491a3a3162
3 changed files with 26 additions and 3 deletions

View File

@ -40,6 +40,20 @@ begin
::Readline.completion_proc = tab_complete_proc || @rl_saved_proc ::Readline.completion_proc = tab_complete_proc || @rl_saved_proc
end end
#
# Retrieve the line buffer
#
def line_buffer
if defined? RbReadline
RbReadline.rl_line_buffer
else
::Readline.line_buffer
end
end
attr_accessor :prompt
# #
# Whether or not the input medium supports readline. # Whether or not the input medium supports readline.
# #
@ -124,12 +138,13 @@ begin
# to reimplement []`Readline.readline`](https://github.com/luislavena/rb-readline/blob/ce4908dae45dbcae90a6e42e3710b8c3a1f2cd64/lib/readline.rb#L36-L58) # to reimplement []`Readline.readline`](https://github.com/luislavena/rb-readline/blob/ce4908dae45dbcae90a6e42e3710b8c3a1f2cd64/lib/readline.rb#L36-L58)
# for rb-readline to support setting input and output. Output needs to be set so that colorization works for the # for rb-readline to support setting input and output. Output needs to be set so that colorization works for the
# prompt on Windows. # prompt on Windows.
self.prompt = prompt
if defined? RbReadline if defined? RbReadline
RbReadline.rl_instream = fd RbReadline.rl_instream = fd
RbReadline.rl_outstream = output RbReadline.rl_outstream = output
begin begin
line = RbReadline.readline(prompt) line = RbReadline.readline("\001\r\033[K\002" + prompt)
rescue ::Exception => exception rescue ::Exception => exception
RbReadline.rl_cleanup_after_signal() RbReadline.rl_cleanup_after_signal()
RbReadline.rl_deprep_terminal() RbReadline.rl_deprep_terminal()
@ -143,7 +158,7 @@ begin
line.try(:dup) line.try(:dup)
else else
::Readline.readline(prompt, true) ::Readline.readline("\001\r\033[K\002" + prompt, true)
end end
end end

View File

@ -29,6 +29,7 @@ class Output < Rex::Ui::Output
super super
end end
attr_reader :config attr_reader :config
attr_accessor :input
def disable_color def disable_color
@config[:color] = false @config[:color] = false
@ -60,7 +61,12 @@ class Output < Rex::Ui::Output
end end
def print_line(msg = '') def print_line(msg = '')
print(msg + "\n") print("\r\033[K" + msg + "\n")
if input and input.prompt
print("\r\033[K")
print(input.prompt)
print(input.line_buffer)
end
end end
def print_warning(msg = '') def print_warning(msg = '')

View File

@ -184,7 +184,9 @@ module Shell
self.init_prompt = input.prompt self.init_prompt = input.prompt
end end
output.input = input
line = input.pgets() line = input.pgets()
output.input = nil
log_output(input.prompt) log_output(input.prompt)
# If a block was passed in, pass the line to it. If it returns true, # If a block was passed in, pass the line to it. If it returns true,