Class: Rex::Ui::Text::Output::Stdio

Inherits:
Rex::Ui::Text::Output show all
Defined in:
lib/rex/ui/text/output/stdio.rb

Overview

This class implements output against standard out.

Instance Attribute Summary collapse

Attributes inherited from Rex::Ui::Text::Output

#config, #input

Instance Method Summary collapse

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.

Parameters:

  • options (Hash{Symbol => IO}) (defaults to: {})

Options Hash (options):



34
35
36
37
38
39
40
# File 'lib/rex/ui/text/output/stdio.rb', line 34

def initialize(options={})
  options.assert_valid_keys(:io)

  super()

  self.io = options[:io]
end

Instance Attribute Details

#ioIO

IO to write to.

Returns:

  • (IO)

    Default to '$stdout`



26
# File 'lib/rex/ui/text/output/stdio.rb', line 26

attr_writer :io

Instance Method Details

#flushObject

Methods



46
47
48
# File 'lib/rex/ui/text/output/stdio.rb', line 46

def flush
  io.flush
end

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

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

Returns:

  • (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