CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/ui/text/output.rb
Views: 11655
1
# -*- coding: binary -*-
2
3
module Rex
4
module Ui
5
module Text
6
7
###
8
#
9
# This class implements text-based output but is not
10
# tied to an output medium.
11
#
12
###
13
class Output < Rex::Ui::Output
14
15
require 'rex/text/color'
16
17
include Rex::Text::Color
18
19
def initialize
20
@config = {
21
:color => :auto, # true, false, :auto
22
}
23
super
24
end
25
attr_reader :config
26
attr_accessor :input
27
28
def disable_color
29
@config[:color] = false
30
end
31
32
def enable_color
33
@config[:color] = true
34
end
35
36
def auto_color
37
@config[:color] = :auto
38
end
39
40
def update_prompt(prompt = nil)
41
return if prompt.nil?
42
substitute_colors(prompt, true)
43
end
44
45
def print_error(msg = '')
46
print_line("%bld%red[-]%clr #{msg}")
47
end
48
49
alias_method :print_bad, :print_error
50
51
def print_good(msg = '')
52
print_line("%bld%grn[+]%clr #{msg}")
53
end
54
55
def print_status(msg = '')
56
print_line("%bld%blu[*]%clr #{msg}")
57
end
58
59
def print_line(msg = '')
60
print(msg + "\n")
61
end
62
63
def print_warning(msg = '')
64
print_line("%bld%yel[!]%clr #{msg}")
65
end
66
67
def print(msg = '')
68
print_raw(substitute_colors(msg))
69
end
70
71
def reset
72
end
73
74
def puts(*args)
75
args.each do |argument|
76
line = argument.to_s
77
print_raw(line)
78
79
unless line.ends_with? "\n"
80
# yes, this is output, but `IO#puts` uses `rb_default_rs`, which is
81
# [`$/`](https://github.com/ruby/ruby/blob/3af8e150aded9d162bfd41426aaaae0279e5a653/io.c#L12168-L12172),
82
# which is [`$INPUT_RECORD_SEPARATOR`](https://github.com/ruby/ruby/blob/3af8e150aded9d162bfd41426aaaae0279e5a653/lib/English.rb#L83)
83
print_raw($INPUT_RECORD_SEPARATOR)
84
end
85
end
86
87
nil
88
end
89
end
90
91
end
92
end
93
end
94
95
96