2005-07-14 22:45:10 +00:00
|
|
|
require 'rex/ui'
|
2011-12-02 06:28:31 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
require 'windows_console_color_support'
|
|
|
|
rescue ::LoadError
|
|
|
|
end
|
2005-07-14 22:45:10 +00:00
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Ui
|
|
|
|
module Text
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This class implements output against standard out.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Output::Stdio < Rex::Ui::Text::Output
|
|
|
|
|
2009-11-10 03:27:48 +00:00
|
|
|
def supports_color?
|
2009-11-10 06:58:01 +00:00
|
|
|
case config[:color]
|
|
|
|
when true
|
|
|
|
return true
|
|
|
|
when false
|
|
|
|
return false
|
|
|
|
else # auto
|
2011-10-13 17:35:31 +00:00
|
|
|
if (Rex::Compat.is_windows)
|
|
|
|
return true
|
|
|
|
end
|
2009-11-10 06:58:01 +00:00
|
|
|
term = Rex::Compat.getenv('TERM')
|
|
|
|
return (term and term.match(/(?:vt10[03]|xterm(?:-color)?|linux|screen|rxvt)/i) != nil)
|
|
|
|
end
|
2009-11-10 03:27:48 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Prints the supplied message to standard output.
|
|
|
|
#
|
2009-11-10 03:27:48 +00:00
|
|
|
def print_raw(msg = '')
|
2011-10-13 17:35:31 +00:00
|
|
|
if (Rex::Compat.is_windows and supports_color?)
|
|
|
|
WindowsConsoleColorSupport.new($stdout).write(msg)
|
|
|
|
else
|
|
|
|
$stdout.print(msg)
|
|
|
|
end
|
2005-07-18 04:07:56 +00:00
|
|
|
$stdout.flush
|
2005-10-02 03:21:26 +00:00
|
|
|
|
|
|
|
msg
|
2005-07-14 22:45:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
2009-11-10 03:27:48 +00:00
|
|
|
end
|
2010-03-11 18:58:20 +00:00
|
|
|
|