ronin-support 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/ChangeLog.md +42 -1
- data/README.md +4 -1
- data/gemspec.yml +2 -1
- data/lib/ronin/extensions.rb +2 -0
- data/lib/ronin/extensions/enumerable.rb +54 -0
- data/lib/ronin/extensions/file.rb +70 -2
- data/lib/ronin/extensions/ip_addr.rb +45 -45
- data/lib/ronin/extensions/regexp.rb +45 -0
- data/lib/ronin/extensions/resolv.rb +80 -0
- data/lib/ronin/extensions/string.rb +35 -32
- data/lib/ronin/formatting/extensions/binary/integer.rb +12 -5
- data/lib/ronin/formatting/extensions/binary/string.rb +44 -16
- data/lib/ronin/formatting/extensions/html/integer.rb +51 -31
- data/lib/ronin/formatting/extensions/html/string.rb +50 -31
- data/lib/ronin/formatting/extensions/http/integer.rb +10 -2
- data/lib/ronin/formatting/extensions/sql.rb +20 -0
- data/lib/ronin/formatting/extensions/sql/string.rb +98 -0
- data/lib/ronin/formatting/extensions/text/array.rb +11 -9
- data/lib/ronin/formatting/extensions/text/string.rb +213 -29
- data/lib/ronin/formatting/sql.rb +20 -0
- data/lib/ronin/network/extensions/http.rb +1 -0
- data/lib/ronin/network/extensions/http/net.rb +2 -2
- data/lib/ronin/network/extensions/http/uri/http.rb +226 -0
- data/lib/ronin/network/extensions/imap/net.rb +1 -1
- data/lib/ronin/network/extensions/ssl/net.rb +7 -1
- data/lib/ronin/network/http/proxy.rb +20 -21
- data/lib/ronin/network/mixins.rb +27 -0
- data/lib/ronin/network/mixins/esmtp.rb +165 -0
- data/lib/ronin/network/mixins/http.rb +723 -0
- data/lib/ronin/network/mixins/imap.rb +151 -0
- data/lib/ronin/network/mixins/pop3.rb +141 -0
- data/lib/ronin/network/mixins/smtp.rb +159 -0
- data/lib/ronin/network/mixins/tcp.rb +331 -0
- data/lib/ronin/network/mixins/telnet.rb +199 -0
- data/lib/ronin/network/mixins/udp.rb +227 -0
- data/lib/ronin/network/ssl.rb +17 -11
- data/lib/ronin/path.rb +3 -3
- data/lib/ronin/spec/ui/output.rb +28 -0
- data/lib/ronin/support.rb +3 -0
- data/lib/ronin/support/version.rb +1 -1
- data/lib/ronin/ui/output.rb +21 -0
- data/lib/ronin/ui/output/helpers.rb +248 -0
- data/lib/ronin/ui/output/output.rb +146 -0
- data/lib/ronin/ui/output/terminal.rb +21 -0
- data/lib/ronin/ui/output/terminal/color.rb +118 -0
- data/lib/ronin/ui/output/terminal/raw.rb +103 -0
- data/lib/ronin/ui/shell.rb +219 -0
- data/ronin-support.gemspec +1 -1
- data/spec/extensions/enumerable_spec.rb +24 -0
- data/spec/extensions/file_spec.rb +39 -0
- data/spec/extensions/ip_addr_spec.rb +6 -0
- data/spec/extensions/resolv_spec.rb +18 -0
- data/spec/formatting/html/integer_spec.rb +2 -2
- data/spec/formatting/html/string_spec.rb +1 -1
- data/spec/formatting/sql/string_spec.rb +55 -0
- data/spec/formatting/text/string_spec.rb +110 -0
- data/spec/network/ssl_spec.rb +10 -4
- data/spec/ui/classes/test_shell.rb +22 -0
- data/spec/ui/output_spec.rb +32 -0
- data/spec/ui/shell_spec.rb +79 -0
- metadata +132 -90
@@ -0,0 +1,227 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
3
|
+
#
|
4
|
+
# This file is part of Ronin Support.
|
5
|
+
#
|
6
|
+
# Ronin Support is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Ronin Support is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'ronin/network/udp'
|
21
|
+
require 'ronin/ui/output/helpers'
|
22
|
+
require 'ronin/mixin'
|
23
|
+
|
24
|
+
require 'parameters'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Network
|
28
|
+
module Mixins
|
29
|
+
#
|
30
|
+
# Adds UDP convenience methods and connection parameters to a class.
|
31
|
+
#
|
32
|
+
# Defines the following parameters:
|
33
|
+
#
|
34
|
+
# * `host` (`String`) - UDP host.
|
35
|
+
# * `port` (`Integer`) - UDP port.
|
36
|
+
# * `local_host` (`String`) - UDP local host.
|
37
|
+
# * `local_port` (`Integer`) - UDP local port.
|
38
|
+
# * `server_host` (`String`) - UDP server host.
|
39
|
+
# * `server_port` (`Integer`) - UDP server port.
|
40
|
+
#
|
41
|
+
module UDP
|
42
|
+
include Mixin
|
43
|
+
|
44
|
+
mixin UI::Output::Helpers, Parameters
|
45
|
+
|
46
|
+
mixin do
|
47
|
+
# UDP host
|
48
|
+
parameter :host, :type => String,
|
49
|
+
:description => 'UDP host'
|
50
|
+
|
51
|
+
# UDP port
|
52
|
+
parameter :port, :type => Integer,
|
53
|
+
:description => 'UDP port'
|
54
|
+
|
55
|
+
# UDP local host
|
56
|
+
parameter :local_host, :type => String,
|
57
|
+
:description => 'UDP local host'
|
58
|
+
|
59
|
+
# UDP local port
|
60
|
+
parameter :local_port, :type => Integer,
|
61
|
+
:description => 'UDP local port'
|
62
|
+
|
63
|
+
# UDP server host
|
64
|
+
parameter :server_host, :type => String,
|
65
|
+
:description => 'UDP server host'
|
66
|
+
|
67
|
+
# UDP server port
|
68
|
+
parameter :server_port, :type => Integer,
|
69
|
+
:description => 'UDP server port'
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
|
74
|
+
#
|
75
|
+
# Opens a UDP connection to the host and port specified by the
|
76
|
+
# `host` and `port` parameters. If the `local_host` and
|
77
|
+
# `local_port` parameters are set, they will be used for
|
78
|
+
# the local host and port of the UDP connection.
|
79
|
+
#
|
80
|
+
# @yield [socket]
|
81
|
+
# If a block is given, it will be passed the newly created socket.
|
82
|
+
#
|
83
|
+
# @yieldparam [UDPsocket] socket
|
84
|
+
# The newly created UDPSocket object.
|
85
|
+
#
|
86
|
+
# @return [UDPSocket]
|
87
|
+
# The newly created UDPSocket object.
|
88
|
+
#
|
89
|
+
# @example
|
90
|
+
# udp_connect
|
91
|
+
# # => UDPSocket
|
92
|
+
#
|
93
|
+
# @example
|
94
|
+
# udp_connect do |sock|
|
95
|
+
# puts sock.readlines
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# @api public
|
99
|
+
#
|
100
|
+
def udp_connect(&block)
|
101
|
+
print_info "Connecting to #{self.host}:#{self.port} ..."
|
102
|
+
|
103
|
+
return ::Net.udp_connect(self.host,self.port,self.local_host,self.local_port,&block)
|
104
|
+
end
|
105
|
+
|
106
|
+
#
|
107
|
+
# Connects to the host and port specified by the `host` and `port`
|
108
|
+
# parameters, then sends the given data. If the `local_host` and
|
109
|
+
# `local_port` instance methods are set, they will be used for the
|
110
|
+
# local host and port of the UDP connection.
|
111
|
+
#
|
112
|
+
# @param [String] data
|
113
|
+
# The data to send through the connection.
|
114
|
+
#
|
115
|
+
# @yield [socket]
|
116
|
+
# If a block is given, it will be passed the newly created socket.
|
117
|
+
#
|
118
|
+
# @yieldparam [UDPsocket] socket
|
119
|
+
# The newly created UDPSocket object.
|
120
|
+
#
|
121
|
+
# @return [UDPSocket]
|
122
|
+
# The newly created UDPSocket object.
|
123
|
+
#
|
124
|
+
# @api public
|
125
|
+
#
|
126
|
+
def udp_connect_and_send(data,&block)
|
127
|
+
print_info "Connecting to #{self.host}:#{self.port} ..."
|
128
|
+
print_debug "Sending data: #{data.inspect}"
|
129
|
+
|
130
|
+
return ::Net.udp_connect_and_send(data,self.host,self.port,self.local_host,self.local_port,&block)
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# Creates a UDP session to the host and port specified by the
|
135
|
+
# `host` and `port` parameters. If the `local_host` and `local_port`
|
136
|
+
# parameters are set, they will be used for the local host and port
|
137
|
+
# of the UDP connection.
|
138
|
+
#
|
139
|
+
# @yield [socket]
|
140
|
+
# If a block is given, it will be passed the newly created socket.
|
141
|
+
# After the block has returned, the socket will then be closed.
|
142
|
+
#
|
143
|
+
# @yieldparam [UDPsocket] socket
|
144
|
+
# The newly created UDPSocket object.
|
145
|
+
#
|
146
|
+
# @return [nil]
|
147
|
+
#
|
148
|
+
# @api public
|
149
|
+
#
|
150
|
+
def udp_session(&block)
|
151
|
+
print_info "Connecting to #{self.host}:#{self.port} ..."
|
152
|
+
|
153
|
+
::Net.udp_session(self.host,self.port,self.local_host,self.local_port,&block)
|
154
|
+
|
155
|
+
print_info "Disconnected from #{self.host}:#{self.port}"
|
156
|
+
return nil
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# Creates a new UDPServer object listening on `server_host` and
|
161
|
+
# `server_port` parameters.
|
162
|
+
#
|
163
|
+
# @yield [server]
|
164
|
+
# The given block will be passed the newly created server.
|
165
|
+
#
|
166
|
+
# @yieldparam [UDPServer] server
|
167
|
+
# The newly created server.
|
168
|
+
#
|
169
|
+
# @return [UDPServer]
|
170
|
+
# The newly created server.
|
171
|
+
#
|
172
|
+
# @example
|
173
|
+
# udp_server
|
174
|
+
#
|
175
|
+
# @api public
|
176
|
+
#
|
177
|
+
def udp_server(&block)
|
178
|
+
if self.server_host
|
179
|
+
print_info "Listening on #{self.server_host}:#{self.server_port} ..."
|
180
|
+
else
|
181
|
+
print_info "Listening on #{self.server_port} ..."
|
182
|
+
end
|
183
|
+
|
184
|
+
return ::Net.udp_server(self.server_port,self.server_host,&block)
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# Creates a new temporary UDPServer object listening on the
|
189
|
+
# `server_host` and `server_port` parameters.
|
190
|
+
#
|
191
|
+
# @yield [server]
|
192
|
+
# The given block will be passed the newly created server.
|
193
|
+
# When the block has finished, the server will be closed.
|
194
|
+
#
|
195
|
+
# @yieldparam [UDPServer] server
|
196
|
+
# The newly created server.
|
197
|
+
#
|
198
|
+
# @return [nil]
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
# udp_server_session do |server|
|
202
|
+
# data, sender = server.recvfrom(1024)
|
203
|
+
# end
|
204
|
+
#
|
205
|
+
# @api public
|
206
|
+
#
|
207
|
+
def udp_server_session(&block)
|
208
|
+
if self.server_host
|
209
|
+
print_info "Listening on #{self.server_host}:#{self.server_port} ..."
|
210
|
+
else
|
211
|
+
print_info "Listening on #{self.server_port} ..."
|
212
|
+
end
|
213
|
+
|
214
|
+
::Net.udp_server_session(&block)
|
215
|
+
|
216
|
+
if self.server_host
|
217
|
+
print_info "Closed #{self.server_host}:#{self.server_port}"
|
218
|
+
else
|
219
|
+
print_info "Closed #{self.server_port}"
|
220
|
+
end
|
221
|
+
|
222
|
+
return nil
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
data/lib/ronin/network/ssl.rb
CHANGED
@@ -19,31 +19,37 @@
|
|
19
19
|
|
20
20
|
require 'ronin/network/extensions/ssl'
|
21
21
|
|
22
|
+
begin
|
23
|
+
require 'openssl'
|
24
|
+
rescue ::LoadError
|
25
|
+
end
|
26
|
+
|
22
27
|
module Ronin
|
23
28
|
module Network
|
24
29
|
#
|
25
30
|
# SSL helper methods.
|
26
31
|
#
|
27
32
|
module SSL
|
33
|
+
# Maps SSL verify modes to `OpenSSL::SSL::VERIFY_*` constants.
|
28
34
|
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# @param [Symbol, String] mode
|
32
|
-
# The name of the verify mode.
|
35
|
+
# @return [Hash{Symbol => Integer}]
|
33
36
|
#
|
34
|
-
# @
|
35
|
-
# The verify mode number used by OpenSSL.
|
37
|
+
# @since 1.3.0
|
36
38
|
#
|
37
39
|
# @api private
|
38
40
|
#
|
39
|
-
|
40
|
-
|
41
|
+
VERIFY = Hash.new do |hash,key|
|
42
|
+
verify_const = if key
|
43
|
+
"VERIFY_#{key.to_s.upcase}"
|
44
|
+
else
|
45
|
+
'VERIFY_NONE'
|
46
|
+
end
|
41
47
|
|
42
|
-
unless OpenSSL::SSL.const_defined?(
|
43
|
-
raise(RuntimeError,"unknown verify mode #{
|
48
|
+
unless OpenSSL::SSL.const_defined?(verify_const)
|
49
|
+
raise(RuntimeError,"unknown verify mode #{key}")
|
44
50
|
end
|
45
51
|
|
46
|
-
|
52
|
+
hash[key] = OpenSSL::SSL.const_get(verify_const)
|
47
53
|
end
|
48
54
|
end
|
49
55
|
end
|
data/lib/ronin/path.rb
CHANGED
@@ -82,14 +82,14 @@ module Ronin
|
|
82
82
|
raise(ArgumentError,"negative argument")
|
83
83
|
end
|
84
84
|
|
85
|
-
path =
|
85
|
+
path = new('..')
|
86
86
|
path.separator = separator
|
87
87
|
|
88
88
|
dirs = (['..'] * (n-1))
|
89
89
|
|
90
90
|
return Path.new(path.join(*dirs))
|
91
91
|
when Enumerable
|
92
|
-
return n.map { |i|
|
92
|
+
return n.map { |i| up(i) }
|
93
93
|
else
|
94
94
|
raise(ArgumentError,"The first argument of Path.up must be either an Integer or Enumerable")
|
95
95
|
end
|
@@ -120,7 +120,7 @@ module Ronin
|
|
120
120
|
# join the path
|
121
121
|
sub_path = names.join(@separator)
|
122
122
|
|
123
|
-
path = if
|
123
|
+
path = if root?
|
124
124
|
# prefix the root dir
|
125
125
|
self.to_s + sub_path
|
126
126
|
else
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
3
|
+
#
|
4
|
+
# This file is part of Ronin Support.
|
5
|
+
#
|
6
|
+
# Ronin Support is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Ronin Support is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'ronin/ui/output'
|
21
|
+
|
22
|
+
require 'rspec'
|
23
|
+
|
24
|
+
RSpec.configure do |spec|
|
25
|
+
spec.before(:suite) do
|
26
|
+
Ronin::UI::Output.silent! unless ENV['DEBUG']
|
27
|
+
end
|
28
|
+
end
|
data/lib/ronin/support.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
3
|
+
#
|
4
|
+
# This file is part of Ronin Support.
|
5
|
+
#
|
6
|
+
# Ronin Support is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Ronin Support is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'ronin/ui/output/output'
|
21
|
+
require 'ronin/ui/output/helpers'
|
@@ -0,0 +1,248 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
|
3
|
+
#
|
4
|
+
# This file is part of Ronin Support.
|
5
|
+
#
|
6
|
+
# Ronin Support is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU Lesser General Public License as published
|
8
|
+
# by the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Ronin Support is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU Lesser General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU Lesser General Public License
|
17
|
+
# along with Ronin Support. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'ronin/ui/output/output'
|
21
|
+
|
22
|
+
module Ronin
|
23
|
+
module UI
|
24
|
+
module Output
|
25
|
+
#
|
26
|
+
# Helper methods for printing output.
|
27
|
+
#
|
28
|
+
module Helpers
|
29
|
+
#
|
30
|
+
# Writes data unless output has been silenced.
|
31
|
+
#
|
32
|
+
# @param [String, Object] data
|
33
|
+
# The data to write.
|
34
|
+
#
|
35
|
+
# @return [Integer, nil]
|
36
|
+
# The number of bytes written.
|
37
|
+
#
|
38
|
+
# @since 1.0.0
|
39
|
+
#
|
40
|
+
# @api public
|
41
|
+
#
|
42
|
+
def write(data)
|
43
|
+
unless Output.silent?
|
44
|
+
data = data.to_s
|
45
|
+
|
46
|
+
Output.handler.write(data)
|
47
|
+
return data.length
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Prints a character.
|
53
|
+
#
|
54
|
+
# @param [String, Integer] data
|
55
|
+
# The character or byte to print.
|
56
|
+
#
|
57
|
+
# @return [String, Integer]
|
58
|
+
# The byte or character.
|
59
|
+
#
|
60
|
+
# @since 1.0.0
|
61
|
+
#
|
62
|
+
# @api public
|
63
|
+
#
|
64
|
+
def putc(data)
|
65
|
+
char = data.chr if data.kind_of?(Integer)
|
66
|
+
|
67
|
+
write(data)
|
68
|
+
return data
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Prints one or more messages.
|
73
|
+
#
|
74
|
+
# @param [Array] messages
|
75
|
+
# The messages to print.
|
76
|
+
#
|
77
|
+
# @example
|
78
|
+
# puts 'some data'
|
79
|
+
#
|
80
|
+
# @since 0.3.0
|
81
|
+
#
|
82
|
+
# @api public
|
83
|
+
#
|
84
|
+
def puts(*messages)
|
85
|
+
unless messages.empty?
|
86
|
+
messages.each { |message| write("#{message}#{$/}") }
|
87
|
+
else
|
88
|
+
write($/)
|
89
|
+
end
|
90
|
+
|
91
|
+
return nil
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Prints formatted data.
|
96
|
+
#
|
97
|
+
# @param [String] format
|
98
|
+
# The format string.
|
99
|
+
#
|
100
|
+
# @param [Array] data
|
101
|
+
# The data to format.
|
102
|
+
#
|
103
|
+
# @return [nil]
|
104
|
+
#
|
105
|
+
# @since 1.0.0
|
106
|
+
#
|
107
|
+
# @api public
|
108
|
+
#
|
109
|
+
def printf(format,*data)
|
110
|
+
write(format % data)
|
111
|
+
return nil
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Prints an `info` message.
|
116
|
+
#
|
117
|
+
# @param [Array] message
|
118
|
+
# The message to print.
|
119
|
+
#
|
120
|
+
# @return [Boolean]
|
121
|
+
# Specifies whether the messages were successfully printed.
|
122
|
+
#
|
123
|
+
# @example
|
124
|
+
# print_info "Connecting ..."
|
125
|
+
#
|
126
|
+
# @example Print a formatted message.
|
127
|
+
# print_info "Connected to %s", host
|
128
|
+
#
|
129
|
+
# @since 0.3.0
|
130
|
+
#
|
131
|
+
# @api public
|
132
|
+
#
|
133
|
+
def print_info(*message)
|
134
|
+
unless Output.silent?
|
135
|
+
Output.handler.print_info(format_message(message))
|
136
|
+
return true
|
137
|
+
end
|
138
|
+
|
139
|
+
return false
|
140
|
+
end
|
141
|
+
|
142
|
+
#
|
143
|
+
# Prints a `debug` message.
|
144
|
+
#
|
145
|
+
# @param [Array, String] message
|
146
|
+
# The message to print.
|
147
|
+
#
|
148
|
+
# @return [Boolean]
|
149
|
+
# Specifies whether the messages were successfully printed.
|
150
|
+
#
|
151
|
+
# @example Print a formatted message.
|
152
|
+
# print_debug "vars: %p %p", vars[0], vars[1]
|
153
|
+
#
|
154
|
+
# @since 0.3.0
|
155
|
+
#
|
156
|
+
# @api public
|
157
|
+
#
|
158
|
+
def print_debug(*message)
|
159
|
+
if (Output.verbose? && !(Output.silent?))
|
160
|
+
Output.handler.print_debug(format_message(message))
|
161
|
+
return true
|
162
|
+
end
|
163
|
+
|
164
|
+
return false
|
165
|
+
end
|
166
|
+
|
167
|
+
#
|
168
|
+
# Prints a `warning` message.
|
169
|
+
#
|
170
|
+
# @param [Array, String] message
|
171
|
+
# The message to print.
|
172
|
+
#
|
173
|
+
# @return [Boolean]
|
174
|
+
# Specifies whether the messages were successfully printed.
|
175
|
+
#
|
176
|
+
# @example
|
177
|
+
# print_warning "Detecting a restricted character in the buffer"
|
178
|
+
#
|
179
|
+
# @example Print a formatted message.
|
180
|
+
# print_warning "Malformed input detected: %p", user_input
|
181
|
+
#
|
182
|
+
# @since 0.3.0
|
183
|
+
#
|
184
|
+
# @api public
|
185
|
+
#
|
186
|
+
def print_warning(*message)
|
187
|
+
if (Output.verbose? && !(Output.silent?))
|
188
|
+
Output.handler.print_warning(format_message(message))
|
189
|
+
return true
|
190
|
+
end
|
191
|
+
|
192
|
+
return false
|
193
|
+
end
|
194
|
+
|
195
|
+
#
|
196
|
+
# Prints an `error` message.
|
197
|
+
#
|
198
|
+
# @param [Array, String] message
|
199
|
+
# The message to print.
|
200
|
+
#
|
201
|
+
# @return [Boolean]
|
202
|
+
# Specifies whether the messages were successfully printed.
|
203
|
+
#
|
204
|
+
# @example
|
205
|
+
# print_error "Could not connect!"
|
206
|
+
#
|
207
|
+
# @example Print a formatted message.
|
208
|
+
# print_error "%p: %s", error.class, error.message
|
209
|
+
#
|
210
|
+
# @since 0.3.0
|
211
|
+
#
|
212
|
+
# @api public
|
213
|
+
#
|
214
|
+
def print_error(*message)
|
215
|
+
unless Output.silent?
|
216
|
+
Output.handler.print_error(format_message(message))
|
217
|
+
return true
|
218
|
+
end
|
219
|
+
|
220
|
+
return false
|
221
|
+
end
|
222
|
+
|
223
|
+
protected
|
224
|
+
|
225
|
+
#
|
226
|
+
# Formats a message to be printed.
|
227
|
+
#
|
228
|
+
# @param [Array] message
|
229
|
+
# The message and additional Objects to format.
|
230
|
+
#
|
231
|
+
# @return [String]
|
232
|
+
# The formatted message.
|
233
|
+
#
|
234
|
+
# @since 1.0.0
|
235
|
+
#
|
236
|
+
# @api private
|
237
|
+
#
|
238
|
+
def format_message(message)
|
239
|
+
if message.length == 1
|
240
|
+
message[0]
|
241
|
+
else
|
242
|
+
message[0] % message[1..-1]
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|