Class: Rex::Ui::Text::Output::Stdio
- Inherits:
-
Rex::Ui::Text::Output
- Object
- Output
- Rex::Ui::Text::Output
- Rex::Ui::Text::Output::Stdio
- Defined in:
- lib/rex/ui/text/output/stdio.rb
Overview
This class implements output against standard out.
Instance Attribute Summary collapse
-
#io ⇒ IO
IO to write to.
Attributes inherited from Rex::Ui::Text::Output
Instance Method Summary collapse
-
#flush ⇒ Object
Methods.
-
#initialize(options = {}) ⇒ Stdio
constructor
A new instance of Stdio.
-
#print_line(msg = '') ⇒ Object
Use ANSI Control chars to reset prompt position for async output SEE github.com/rapid7/metasploit-framework/pull/7570.
-
#print_raw(msg = '') ⇒ Object
(also: #write)
Prints the supplied message to standard output.
- #supports_color? ⇒ Boolean
Methods inherited from Rex::Ui::Text::Output
#auto_color, #disable_color, #enable_color, #print, #print_error, #print_good, #print_status, #print_warning, #puts, #reset, #update_prompt
Methods inherited from Output
#print, #print_error, #print_good, #print_status, #print_warning, #prompting, #prompting?
Constructor Details
#initialize(options = {}) ⇒ Stdio
Returns a new instance of Stdio.
34 35 36 37 38 39 40 |
# File 'lib/rex/ui/text/output/stdio.rb', line 34 def initialize(={}) .assert_valid_keys(:io) super() self.io = [:io] end |
Instance Attribute Details
Instance Method Details
#flush ⇒ Object
Methods
46 47 48 |
# File 'lib/rex/ui/text/output/stdio.rb', line 46 def flush io.flush end |
#print_line(msg = '') ⇒ Object
Use ANSI Control chars to reset prompt position for async output SEE github.com/rapid7/metasploit-framework/pull/7570
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rex/ui/text/output/stdio.rb', line 59 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. =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 |
#print_raw(msg = '') ⇒ Object Also known as: write
Prints the supplied message to standard output.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rex/ui/text/output/stdio.rb', line 85 def print_raw(msg = '') if (Rex::Compat.is_windows and supports_color?) WindowsConsoleColorSupport.new(io).write(msg) else io.print(msg) end io.flush msg end |
#supports_color? ⇒ Boolean
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rex/ui/text/output/stdio.rb', line 98 def supports_color? case config[:color] when true return true when false return false else # auto if (Rex::Compat.is_windows) return true end term = Rex::Compat.getenv('TERM') return (term and term.match(/(?:vt10[03]|xterm(?:-color)?|linux|screen|rxvt)/i) != nil) end end |