From d0d84b418bc42a14db83babac582ed927250d29f Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Tue, 20 Dec 2016 23:50:43 -0600 Subject: [PATCH 1/2] disable async output until we have a better handle on new quirks --- lib/rex/ui/text/input/readline.rb | 25 ++++++++++++++++--------- lib/rex/ui/text/output/stdio.rb | 28 ++++++++++++++++------------ 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/lib/rex/ui/text/input/readline.rb b/lib/rex/ui/text/input/readline.rb index 6cce9bf129..ceb6a330ca 100644 --- a/lib/rex/ui/text/input/readline.rb +++ b/lib/rex/ui/text/input/readline.rb @@ -133,16 +133,23 @@ begin private def readline_with_output(prompt, add_history=false) - # rb-readlines's Readline.readline hardcodes the input and output to $stdin and $stdout, which means setting - # `Readline.input` or `Readline.ouput` has no effect when running `Readline.readline` with rb-readline, so need - # 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 - # prompt on Windows. + # rb-readlines's Readline.readline hardcodes the input and output to + # $stdin and $stdout, which means setting `Readline.input` or + # `Readline.ouput` has no effect when running `Readline.readline` with + # rb-readline, so need 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 prompt on Windows. + # self.prompt = prompt - reset_sequence = "\n\001\r\033[K\002" - if (/mingw/ =~ RUBY_PLATFORM) - reset_sequence = "" - end + + # TODO: there are unhandled quirks in async output buffering that + # we have not solved yet, for instance when loading meterpreter + # extensions, supporting Windows, printing output from commands, etc. + # Remove this guard when issues are resolved. + # reset_sequence = "\n\001\r\033[K\002" + reset_sequence = "" + if defined? RbReadline RbReadline.rl_instream = fd RbReadline.rl_outstream = output diff --git a/lib/rex/ui/text/output/stdio.rb b/lib/rex/ui/text/output/stdio.rb index 6e85363f13..61f17d09f3 100644 --- a/lib/rex/ui/text/output/stdio.rb +++ b/lib/rex/ui/text/output/stdio.rb @@ -58,18 +58,22 @@ class Output::Stdio < Rex::Ui::Text::Output # Use ANSI Control chars to reset prompt position for async output # SEE https://github.com/rapid7/metasploit-framework/pull/7570 def print_line(msg = '') - if (/mingw/ =~ RUBY_PLATFORM) - print(msg + "\n") - return - end - print("\033[s") # Save cursor position - print("\r\033[K" + msg + "\n") - if input and input.prompt - print("\r\033[K") - print(input.prompt.tr("\001\002", '')) - print(input.line_buffer.tr("\001\002", '')) - print("\033[u\033[B") # Restore cursor, move down one line - end + + # TODO: there are unhandled quirks in async output buffering that + # we have not solved yet, for instance when loading meterpreter + # extensions, supporting Windows, printing output from commands, etc. + # Remove this guard when issues are resolved. + # + # print("\033[s") # Save cursor position + # print("\r\033[K" + msg + "\n") + # if input and input.prompt + # print("\r\033[K") + # print(input.prompt.tr("\001\002", '')) + # print(input.line_buffer.tr("\001\002", '')) + # print("\033[u\033[B") # Restore cursor, move down one line + # end + + print(msg + "\n") end # From 4098c66efb5cd8d72ffbb2466f878b6214aff197 Mon Sep 17 00:00:00 2001 From: William Vu Date: Wed, 21 Dec 2016 00:38:08 -0600 Subject: [PATCH 2/2] Restore MinGW code and use =begin/=end for indent --- lib/rex/ui/text/input/readline.rb | 8 ++++++-- lib/rex/ui/text/output/stdio.rb | 24 ++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/rex/ui/text/input/readline.rb b/lib/rex/ui/text/input/readline.rb index ceb6a330ca..cf53a1e851 100644 --- a/lib/rex/ui/text/input/readline.rb +++ b/lib/rex/ui/text/input/readline.rb @@ -140,14 +140,18 @@ begin # []`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 prompt on Windows. - # self.prompt = prompt # TODO: there are unhandled quirks in async output buffering that # we have not solved yet, for instance when loading meterpreter # extensions, supporting Windows, printing output from commands, etc. # Remove this guard when issues are resolved. - # reset_sequence = "\n\001\r\033[K\002" +=begin + reset_sequence = "\n\001\r\033[K\002" + if (/mingw/ =~ RUBY_PLATFORM) + reset_sequence = "" + end +=end reset_sequence = "" if defined? RbReadline diff --git a/lib/rex/ui/text/output/stdio.rb b/lib/rex/ui/text/output/stdio.rb index 61f17d09f3..8ca76dd72c 100644 --- a/lib/rex/ui/text/output/stdio.rb +++ b/lib/rex/ui/text/output/stdio.rb @@ -58,20 +58,24 @@ class Output::Stdio < Rex::Ui::Text::Output # Use ANSI Control chars to reset prompt position for async output # SEE https://github.com/rapid7/metasploit-framework/pull/7570 def print_line(msg = '') - # TODO: there are unhandled quirks in async output buffering that # we have not solved yet, for instance when loading meterpreter # extensions, supporting Windows, printing output from commands, etc. # Remove this guard when issues are resolved. - # - # print("\033[s") # Save cursor position - # print("\r\033[K" + msg + "\n") - # if input and input.prompt - # print("\r\033[K") - # print(input.prompt.tr("\001\002", '')) - # print(input.line_buffer.tr("\001\002", '')) - # print("\033[u\033[B") # Restore cursor, move down one line - # end +=begin + if (/mingw/ =~ RUBY_PLATFORM) + print(msg + "\n") + return + end + print("\033[s") # Save cursor position + print("\r\033[K" + msg + "\n") + if input and input.prompt + print("\r\033[K") + print(input.prompt.tr("\001\002", '')) + print(input.line_buffer.tr("\001\002", '')) + print("\033[u\033[B") # Restore cursor, move down one line + end +=end print(msg + "\n") end