verboss 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/format.rb +52 -0
- data/lib/verboss.rb +52 -61
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3c450310e2fbcb5355c2b75965b3dd962bdeacb
|
4
|
+
data.tar.gz: 6118b719dea1a7707b359bfdd2e424df09bd78aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcb37d7378b8e81f240d21783b6d2e37a151a7a9552f3b692751b53c426951ca16667ce2fccb16e0e1e118e12f3368ba358ee182d73b6356c7783a32766f9f7f
|
7
|
+
data.tar.gz: 5dd91533793897f0e57adc726073c2b215439948237fc988ba184bd2d8cabc13d9a9e4df250c81b603c9188099c9ec1cfa16b6f7b1b21c3a6844be27dcbcadeb
|
data/lib/format.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
class String
|
2
|
+
def fixed_width(width = 64)
|
3
|
+
return self + (" " * (width - self.size)) if self.size < width
|
4
|
+
|
5
|
+
self[0, width - 3].chomp + "..."
|
6
|
+
end
|
7
|
+
|
8
|
+
def red
|
9
|
+
return "\e[31m" + self + "\e[39m"
|
10
|
+
end
|
11
|
+
|
12
|
+
def green
|
13
|
+
return "\e[32m" + self + "\e[39m"
|
14
|
+
end
|
15
|
+
|
16
|
+
def blue
|
17
|
+
return "\e[34m" + self + "\e[39m"
|
18
|
+
end
|
19
|
+
|
20
|
+
def magenta
|
21
|
+
return "\e[35m" + self + "\e[39m"
|
22
|
+
end
|
23
|
+
|
24
|
+
def cyan
|
25
|
+
return "\e[36m" + self + "\e[39m"
|
26
|
+
end
|
27
|
+
|
28
|
+
def white
|
29
|
+
return "\e[37m" + self + "\e[39m"
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def bg_black
|
34
|
+
return "\e[40m" + self + "\e[49m"
|
35
|
+
end
|
36
|
+
|
37
|
+
def bg_yellow
|
38
|
+
return "\e[43m" + self + "\e[49m"
|
39
|
+
end
|
40
|
+
|
41
|
+
def bold
|
42
|
+
return "\e[1m" + self + "\e[0m"
|
43
|
+
end
|
44
|
+
|
45
|
+
def underline
|
46
|
+
return "\e[4m" + self + "\e[0m"
|
47
|
+
end
|
48
|
+
|
49
|
+
def blink
|
50
|
+
return "\e[5m" + self + "\e[0m"
|
51
|
+
end
|
52
|
+
end
|
data/lib/verboss.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
#####
|
1
|
+
##### Verboss Module####
|
2
2
|
# allows concise method calls to organize and standardize terminal output
|
3
|
-
#
|
4
|
-
#
|
3
|
+
# Verboss.doing organizes all output that occurs during its block
|
4
|
+
# Verboss.quiet allows for all output to be silenced, displaying only the passed argument (if given)
|
5
5
|
#
|
6
6
|
# The last few methods: say, mention, yell, scream
|
7
7
|
# These are intended to standardize the format of certain kinds of output by
|
8
8
|
# level of importance
|
9
|
-
# say -> general information -> normal
|
10
|
-
# mention -> important information -> blue
|
11
|
-
# cheer -> success was reached -> green
|
12
|
-
# yell -> problem was discovered -> red
|
13
|
-
# scream ->
|
9
|
+
# say -> general information -> normal
|
10
|
+
# mention -> important information -> blue
|
11
|
+
# cheer -> success was reached -> green
|
12
|
+
# yell -> problem was discovered -> red
|
13
|
+
# scream -> the heavens must know -> disgusting
|
14
14
|
#
|
15
|
-
require '
|
15
|
+
require 'format'
|
16
16
|
module Verboss
|
17
|
-
|
18
|
-
@@
|
17
|
+
WIDTH = 64
|
18
|
+
@@err_indent = "$ ".magenta
|
19
|
+
@@out_indent = "| ".magenta
|
19
20
|
@@root_stderr = $stderr
|
20
21
|
@@root_stdout = $stdout
|
21
22
|
|
@@ -24,7 +25,6 @@ module Verboss
|
|
24
25
|
no_logging: false
|
25
26
|
}
|
26
27
|
|
27
|
-
|
28
28
|
@@spinner = {
|
29
29
|
on: false,
|
30
30
|
chars: %w[| / - \\],
|
@@ -35,24 +35,15 @@ module Verboss
|
|
35
35
|
while @@spinner[:thread]
|
36
36
|
Thread.stop unless @@spinner[:on]
|
37
37
|
sleep @@spinner[:delay]
|
38
|
-
c = (@@spinner[:chars][ @@spinner[:index] = (@@spinner[:index] + 1) % @@spinner[:chars].length ] + "\b").
|
38
|
+
c = (@@spinner[:chars][ @@spinner[:index] = (@@spinner[:index] + 1) % @@spinner[:chars].length ] + "\b").white.bg_black.bold
|
39
39
|
@@root_stdout.print c
|
40
40
|
end
|
41
41
|
}
|
42
42
|
}
|
43
43
|
|
44
|
-
## FLAG METHODS
|
45
|
-
def self.migrations? # helper used to determine if ActiveRecord::Migration.verbose should be true
|
46
|
-
ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : false
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.trace? # helper used to determine if stack traces should be displayed or not
|
50
|
-
ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : false
|
51
|
-
end
|
52
|
-
|
53
44
|
def self.level arg = 1
|
54
|
-
case ENV["
|
55
|
-
when Numeric then arg <= ENV["
|
45
|
+
case ENV["Verboss"]
|
46
|
+
when Numeric then arg <= ENV["Verboss"]
|
56
47
|
when nil then false
|
57
48
|
else
|
58
49
|
true
|
@@ -72,9 +63,9 @@ module Verboss
|
|
72
63
|
def self.wait_spinner options = {}
|
73
64
|
@@spinner[:delay] = options[:fps] * 60 if options[:fps]
|
74
65
|
@@spinner[:delay] = options[:delay] if options[:delay]
|
75
|
-
|
66
|
+
Verboss.start_spinner
|
76
67
|
yield
|
77
|
-
|
68
|
+
Verboss.stop_spinner
|
78
69
|
end
|
79
70
|
|
80
71
|
|
@@ -85,23 +76,23 @@ module Verboss
|
|
85
76
|
end
|
86
77
|
|
87
78
|
def self.mention *args
|
88
|
-
args.each { |a| $stdout.puts "#{a.to_s.
|
79
|
+
args.each { |a| $stdout.puts "#{a.to_s.blue}" }
|
89
80
|
end
|
90
81
|
|
91
82
|
def self.cheer *args
|
92
|
-
args.each { |a| $stdout.puts "#{a.to_s.
|
83
|
+
args.each { |a| $stdout.puts "#{a.to_s.green}" }
|
93
84
|
end
|
94
85
|
|
95
86
|
def self.yell *args
|
96
|
-
args.each { |a| $stderr.puts "\n#{a.to_s.
|
87
|
+
args.each { |a| $stderr.puts "\n#{a.to_s.red}" }
|
97
88
|
end
|
98
89
|
|
99
90
|
def self.scream *args
|
100
|
-
args.each { |a| $stderr.puts "\n#{a.to_s.
|
91
|
+
args.each { |a| $stderr.puts "\n#{a.to_s.red.bg_yellow.underline.bold.blink}" }
|
101
92
|
end
|
102
93
|
|
103
94
|
|
104
|
-
## IO CAPTURING/FORMATTING METHODS ## allow method invocations such as
|
95
|
+
## IO CAPTURING/FORMATTING METHODS ## allow method invocations such as Verboss.quiet.no_logging to work as expected
|
105
96
|
|
106
97
|
def self.option keyword=false
|
107
98
|
case keyword
|
@@ -116,17 +107,17 @@ module Verboss
|
|
116
107
|
end
|
117
108
|
|
118
109
|
def self.quietly description=nil # allows chaining unless a block is given
|
119
|
-
return
|
110
|
+
return Verboss.option :quiet unless block_given? # if no block set 'quiet: true'
|
120
111
|
|
121
|
-
if
|
112
|
+
if Verboss.option[:no_logging] # if no logging, then turn if off
|
122
113
|
old_logger = ActiveRecord::Base.logger
|
123
114
|
ActiveRecord::Base.logger = nil
|
124
115
|
|
125
|
-
ret =
|
116
|
+
ret = Verboss.quiet! description, &Proc.new
|
126
117
|
|
127
118
|
ActiveRecord::Base.logger = old_logger
|
128
119
|
else
|
129
|
-
ret =
|
120
|
+
ret = Verboss.quiet! description, &Proc.new # if logging is ok, log away
|
130
121
|
end
|
131
122
|
|
132
123
|
@@temporary_options = {}
|
@@ -135,17 +126,17 @@ module Verboss
|
|
135
126
|
end
|
136
127
|
|
137
128
|
def self.loudly description=nil
|
138
|
-
return
|
129
|
+
return Verboss.option :loud unless block_given?
|
139
130
|
|
140
|
-
if
|
131
|
+
if Verboss.option[:no_logging] # if no logging, then turn if off
|
141
132
|
old_logger = ActiveRecord::Base.logger
|
142
133
|
ActiveRecord::Base.logger = nil
|
143
134
|
|
144
|
-
ret =
|
135
|
+
ret = Verboss.loud! description, &Proc.new
|
145
136
|
|
146
137
|
ActiveRecord::Base.logger = old_logger
|
147
138
|
else
|
148
|
-
ret =
|
139
|
+
ret = Verboss.loud! description, &Proc.new # if logging is ok, log away
|
149
140
|
end
|
150
141
|
|
151
142
|
@@temporary_options = {}
|
@@ -153,12 +144,12 @@ module Verboss
|
|
153
144
|
end
|
154
145
|
|
155
146
|
def self.logging description=nil
|
156
|
-
return
|
147
|
+
return Verboss.option :logging unless block_given?
|
157
148
|
|
158
|
-
if
|
159
|
-
ret =
|
149
|
+
if Verboss.option[:quiet]
|
150
|
+
ret = Verboss.quiet! description, &Proc.new
|
160
151
|
else
|
161
|
-
ret =
|
152
|
+
ret = Verboss.loud! description, &Proc.new
|
162
153
|
end
|
163
154
|
|
164
155
|
@@temporary_options = {}
|
@@ -166,15 +157,15 @@ module Verboss
|
|
166
157
|
end
|
167
158
|
|
168
159
|
def self.no_logging description=nil
|
169
|
-
return
|
160
|
+
return Verboss.option :no_logging unless block_given?
|
170
161
|
|
171
162
|
old_logger = ActiveRecord::Base.logger
|
172
163
|
ActiveRecord::Base.logger = nil
|
173
164
|
|
174
|
-
if
|
175
|
-
ret =
|
165
|
+
if Verboss.option[:quiet]
|
166
|
+
ret = Verboss.quiet! description, &Proc.new
|
176
167
|
else
|
177
|
-
ret =
|
168
|
+
ret = Verboss.loud! description, &Proc.new
|
178
169
|
end
|
179
170
|
ActiveRecord::Base.logger = old_logger
|
180
171
|
@@temporary_options = {}
|
@@ -189,9 +180,9 @@ module Verboss
|
|
189
180
|
# save a reference to the two IO's
|
190
181
|
out = $stdout
|
191
182
|
err = $stderr
|
192
|
-
out.puts "/ #{description.to_s.
|
183
|
+
out.puts "/ #{description.to_s.fixed_width(WIDTH-4).bold} ".magenta + "\\"
|
193
184
|
begin # IO and Thread stuffs
|
194
|
-
|
185
|
+
Verboss.start_spinner
|
195
186
|
read_out, write_out = IO.pipe
|
196
187
|
read_err, write_err = IO.pipe
|
197
188
|
$stderr = write_err
|
@@ -200,16 +191,16 @@ module Verboss
|
|
200
191
|
err_thread = Thread.new { err.print @@err_indent + read_err.gets("\n") until read_err.eof? }
|
201
192
|
ret = yield
|
202
193
|
rescue Exception => msg
|
203
|
-
err.puts "# #{description.to_s.
|
194
|
+
err.puts "# #{description.to_s.fixed_width(WIDTH-4)} FAIL ".bold.red
|
204
195
|
raise msg
|
205
196
|
ensure # whether or not the block fails close the pipes
|
206
197
|
write_out.close
|
207
198
|
write_err.close
|
208
199
|
out_thread.join
|
209
200
|
err_thread.join
|
210
|
-
|
201
|
+
Verboss.stop_spinner
|
211
202
|
end
|
212
|
-
out.puts "\\ #{"_ " * 14}".
|
203
|
+
out.puts "\\ #{"_ " * 14}".magenta + "DONE".green.bold + " in #{Time.now - start_time}s".fixed_width(14).cyan + " _ _ _ _ _ _ _ /".magenta
|
213
204
|
return ret
|
214
205
|
ensure # both IO's go back the way they were found
|
215
206
|
$stderr = err
|
@@ -221,29 +212,29 @@ module Verboss
|
|
221
212
|
# save a reference to the two IO's
|
222
213
|
out = $stdout
|
223
214
|
err = $stderr
|
224
|
-
out.puts description.to_s.
|
215
|
+
out.puts description.to_s.fixed_width(WIDTH-10).bold.magenta + " ... ".bold.blue if description
|
225
216
|
begin # IO and Thread stuffs
|
226
|
-
|
217
|
+
Verboss.start_spinner
|
227
218
|
$stderr = StringIO.new
|
228
219
|
$stdout = StringIO.new
|
229
220
|
ret = yield
|
230
221
|
rescue Exception => msg
|
231
|
-
|
232
|
-
|
222
|
+
if description
|
223
|
+
err.print "\e[1A"
|
224
|
+
err.print "# #{description.to_s.fixed_width(WIDTH-6)}".red
|
225
|
+
end
|
226
|
+
err.puts "FAIL".bold.red
|
233
227
|
raise msg
|
234
228
|
ensure
|
235
|
-
|
229
|
+
Verboss.stop_spinner
|
236
230
|
end
|
237
231
|
if description
|
238
232
|
out.print "\e[1A"
|
239
|
-
out.puts description.to_s.
|
233
|
+
out.puts description.to_s.fixed_width(WIDTH-8).bold.magenta + "DONE".green.bold + " in #{Time.now - start_time}s".fixed_width(14).cyan
|
240
234
|
end
|
241
235
|
return ret
|
242
236
|
ensure # both IO's go back the way they were found
|
243
237
|
$stderr = err
|
244
238
|
$stdout = out
|
245
239
|
end
|
246
|
-
|
247
|
-
|
248
240
|
end
|
249
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verboss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Behar
|
@@ -9,21 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-06-23 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rainbow
|
15
|
-
version_requirements: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
requirement: !ruby/object:Gem::Requirement
|
21
|
-
requirements:
|
22
|
-
- - '>='
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: '0'
|
25
|
-
prerelease: false
|
26
|
-
type: :runtime
|
12
|
+
dependencies: []
|
27
13
|
description: lightweight and simple terminal formatting
|
28
14
|
email: lazymunky94@gmail.com
|
29
15
|
executables: []
|
@@ -31,6 +17,7 @@ extensions: []
|
|
31
17
|
extra_rdoc_files: []
|
32
18
|
files:
|
33
19
|
- lib/verboss.rb
|
20
|
+
- lib/format.rb
|
34
21
|
homepage: https://github.com/Ben-Behar/verboss
|
35
22
|
licenses:
|
36
23
|
- MIT
|