Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/ui/text/output/tee.rb
19715 views
1
# -*- coding: binary -*-
2
3
module Rex
4
module Ui
5
module Text
6
7
###
8
#
9
# This class implements output against a file and stdout
10
#
11
###
12
class Output::Tee < Rex::Ui::Text::Output
13
14
attr_accessor :fd
15
16
def initialize(path)
17
self.fd = ::File.open(path, "ab")
18
super()
19
end
20
21
def supports_color?
22
case config[:color]
23
when true
24
return true
25
when false
26
return false
27
else # auto
28
term = Rex::Compat.getenv('TERM')
29
return (term and term.match(/(?:vt10[03]|xterm(?:-color)?|linux|screen|rxvt)/i) != nil)
30
end
31
end
32
33
#
34
# Prints the supplied message to file output.
35
#
36
def print_raw(msg = '')
37
$stdout.print(msg)
38
$stdout.flush
39
40
return if not self.fd
41
self.fd.write(msg)
42
self.fd.flush
43
msg
44
end
45
46
alias :write :print_raw
47
48
def close
49
self.fd.close if self.fd
50
self.fd = nil
51
end
52
end
53
54
end
55
end
56
end
57
58
59