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/subscriber.rb
Views: 11780
1
# -*- coding: binary -*-
2
module Rex
3
module Ui
4
5
###
6
#
7
# This module provides a subscriber interface to input/output.
8
#
9
###
10
module Subscriber
11
12
##
13
#
14
# Subscribes to the output half of the user interface.
15
#
16
##
17
module Output
18
19
#
20
# Wraps user_output.print_line
21
#
22
def print_line(msg='')
23
if (user_output)
24
print_blank_line if user_output.prompting?
25
user_output.print_line(msg)
26
end
27
end
28
29
#
30
# Wraps user_output.print_status
31
#
32
def print_status(msg='')
33
if (user_output)
34
print_blank_line if user_output.prompting?
35
user_output.print_status(msg)
36
end
37
end
38
39
#
40
# Wraps user_output.print_error
41
#
42
def print_error(msg='')
43
if (user_output)
44
print_blank_line if user_output.prompting?
45
user_output.print_error(msg)
46
end
47
end
48
49
alias_method :print_bad, :print_error
50
51
#
52
# Wraps user_output.print_good
53
#
54
def print_good(msg='')
55
if (user_output)
56
print_blank_line if user_output.prompting?
57
user_output.print_good(msg)
58
end
59
end
60
61
#
62
# Wraps user_output.print_warning
63
#
64
def print_warning(msg='')
65
if (user_output)
66
print_blank_line if user_output.prompting?
67
user_output.print_warning(msg)
68
end
69
end
70
71
#
72
# Wraps user_output.print
73
#
74
def print(msg='')
75
user_output.print(msg) if (user_output)
76
end
77
78
#
79
# Wraps user_output.flush
80
#
81
def flush
82
user_output.flush if (user_output)
83
end
84
85
#
86
# The user output handle.
87
#
88
attr_accessor :user_output
89
90
protected
91
92
#
93
# Prints a blank line. Used when the input is prompting.
94
#
95
def print_blank_line
96
user_output.prompting(false)
97
user_output.print_line
98
end
99
100
end
101
102
##
103
#
104
# Subscribes to the input half of the user interface.
105
#
106
##
107
module Input
108
109
#
110
# Gets a line of input from the user_input handle by calling gets.
111
#
112
def gets
113
user_input.gets if (user_input)
114
end
115
116
#
117
# The user input handle.
118
#
119
attr_accessor :user_input
120
121
end
122
123
include Output
124
include Input
125
126
#
127
# Sets the input and output handles.
128
#
129
def init_ui(input = nil, output = nil)
130
self.user_input = input
131
self.user_output = output
132
end
133
134
#
135
# Disables input/output
136
#
137
def reset_ui
138
self.user_input = nil
139
self.user_output = nil
140
end
141
142
#
143
# Copy the user input and output handles from the supplied subscriber.
144
#
145
def copy_ui(subscriber)
146
init_ui(subscriber.user_input, subscriber.user_output)
147
end
148
149
end
150
151
end
152
end
153
154