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.

Constant Summary

Constants included from Color

Color::AnsiAttributes

Instance Attribute Summary collapse

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

#config

Instance Method Summary collapse

Methods inherited from Rex::Ui::Text::Output

#auto_color, #disable_color, #enable_color, #print, #print_debug, #print_error, #print_good, #print_line, #print_status, #print_warning, #reset, #update_prompt

Methods included from Color

#ansi, #colorize, #do_colorize, #reset_color, #substitute_colors

Methods inherited from Output

#print, #print_debug, #print_error, #print_good, #print_line, #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):



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

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`



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

attr_writer :io

Instance Method Details

#flushObject

Methods



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

def flush
  io.flush
end

Prints the supplied message to standard output.



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rex/ui/text/output/stdio.rb', line 61

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

#puts(*args) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rex/ui/text/output/stdio.rb', line 74

def puts(*args)
  args.each do |argument|
    line = argument.to_s
    write(line)

    unless line.ends_with? "\n"
      # yes, this is output, but `IO#puts` uses `rb_default_rs`, which is
      # [`$/`](https://github.com/ruby/ruby/blob/3af8e150aded9d162bfd41426aaaae0279e5a653/io.c#L12168-L12172),
      # which is [`$INPUT_RECORD_SEPARATOR`](https://github.com/ruby/ruby/blob/3af8e150aded9d162bfd41426aaaae0279e5a653/lib/English.rb#L83)
      write($INPUT_RECORD_SEPARATOR)
    end
  end

  nil
end

#supports_color?Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rex/ui/text/output/stdio.rb', line 90

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