simple-ui 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/simple/ui.rb +30 -27
- data/test/simple_ui_test.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0731849a4852292bd46a46018693cc338d50fe8a
|
4
|
+
data.tar.gz: b5275714622eb5f9aa75b473ef2d864f2a35b85f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d06da4c7ccad3d89be306004e374284d739301547523675a408cf2aa1aa61b9251cb16ed2fcc9775c89621d63937578ff7e55cba7b71a9dc3bf0e194d663191f
|
7
|
+
data.tar.gz: 052582f194553a7c8cfa6aa39ea45c3608c5f15e2a4b68ec467469a0a0cccf2074410516b9439518f0295201fbed043250b751a0cd027040a7ca16bf07859e1c
|
data/README.md
CHANGED
@@ -4,16 +4,16 @@ A really simple UI helper, supporting
|
|
4
4
|
|
5
5
|
- logging severities (:debug, :info, :warn, :error, :success)
|
6
6
|
|
7
|
-
UI.warn "This is a warning"
|
7
|
+
Simple::UI.warn "This is a warning"
|
8
8
|
|
9
9
|
- ...with different colors...
|
10
10
|
|
11
|
-
UI.success "success is green"
|
12
|
-
UI.error "error is red"
|
11
|
+
Simple::UI.success "success is green"
|
12
|
+
Simple::UI.error "error is red"
|
13
13
|
|
14
14
|
- ...with inspect'ing arguments after the first
|
15
15
|
|
16
|
-
UI.warn "Some things", 1, "foo\nline", :bar
|
16
|
+
Simple::UI.warn "Some things", 1, "foo\nline", :bar
|
17
17
|
# =>
|
18
18
|
# Some things 1, "foo\nline", :bar
|
19
19
|
|
data/lib/simple/ui.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
-
module
|
1
|
+
module Simple
|
2
|
+
end
|
3
|
+
|
4
|
+
module Simple::UI
|
2
5
|
extend self
|
3
|
-
|
4
|
-
VERSION = "0.
|
5
|
-
|
6
|
+
|
7
|
+
VERSION = "0.3.0"
|
8
|
+
|
6
9
|
def self.verbosity
|
7
10
|
@verbosity ||= 1
|
8
11
|
end
|
9
|
-
|
12
|
+
|
10
13
|
def self.verbosity=(verbosity)
|
11
14
|
@verbosity = verbosity
|
12
15
|
end
|
13
|
-
|
16
|
+
|
14
17
|
COLORS = {
|
15
18
|
clear: "\e[0m", # Embed in a String to clear all previous ANSI sequences.
|
16
19
|
bold: "\e[1m", # The start of an ANSI bold sequence.
|
@@ -34,14 +37,14 @@ module UI
|
|
34
37
|
}
|
35
38
|
|
36
39
|
@@started_at = Time.now
|
37
|
-
|
40
|
+
|
38
41
|
MESSAGE_COLOR = {
|
39
42
|
:info => :cyan,
|
40
43
|
:warn => :yellow,
|
41
44
|
:error => :red,
|
42
45
|
:success => :green,
|
43
46
|
}
|
44
|
-
|
47
|
+
|
45
48
|
MIN_VERBOSITY = {
|
46
49
|
:debug => 3,
|
47
50
|
:info => 2,
|
@@ -51,23 +54,23 @@ module UI
|
|
51
54
|
}
|
52
55
|
|
53
56
|
def debug(msg, *args)
|
54
|
-
UI.log :debug, msg, *args
|
57
|
+
Simple::UI.log :debug, msg, *args
|
55
58
|
end
|
56
59
|
|
57
60
|
def info(msg, *args)
|
58
|
-
UI.log :info, msg, *args
|
61
|
+
Simple::UI.log :info, msg, *args
|
59
62
|
end
|
60
63
|
|
61
64
|
def warn(msg, *args)
|
62
|
-
UI.log :warn, msg, *args
|
65
|
+
Simple::UI.log :warn, msg, *args
|
63
66
|
end
|
64
67
|
|
65
68
|
def error(msg, *args)
|
66
|
-
UI.log :error, msg, *args
|
69
|
+
Simple::UI.log :error, msg, *args
|
67
70
|
end
|
68
71
|
|
69
72
|
def success(msg, *args)
|
70
|
-
UI.log :success, msg, *args
|
73
|
+
Simple::UI.log :success, msg, *args
|
71
74
|
end
|
72
75
|
|
73
76
|
def benchmark(msg, *args, &block)
|
@@ -75,38 +78,38 @@ module UI
|
|
75
78
|
if msg.is_a?(Symbol)
|
76
79
|
severity, msg = msg, args.shift
|
77
80
|
end
|
78
|
-
|
81
|
+
|
79
82
|
start = Time.now
|
80
83
|
r = yield
|
81
|
-
|
84
|
+
|
82
85
|
msg += ": #{(1000 * (Time.now - start)).to_i} msecs."
|
83
|
-
UI.log severity, msg, *args
|
84
|
-
|
86
|
+
Simple::UI.log severity, msg, *args
|
87
|
+
|
85
88
|
r
|
86
89
|
rescue StandardError
|
87
90
|
msg += "raises #{$!.class.name} after #{(1000 * (Time.now - start)).to_i} msecs."
|
88
|
-
UI.log severity, msg, *args
|
91
|
+
Simple::UI.log severity, msg, *args
|
89
92
|
raise $!
|
90
93
|
end
|
91
94
|
|
92
95
|
def self.colored=(colored)
|
93
96
|
@colored = colored
|
94
97
|
end
|
95
|
-
|
98
|
+
|
96
99
|
def self.colored?
|
97
100
|
if @colored.nil?
|
98
|
-
@colored = STDERR.tty?
|
101
|
+
@colored = STDERR.tty?
|
99
102
|
end
|
100
|
-
|
103
|
+
|
101
104
|
@colored != false
|
102
105
|
end
|
103
|
-
|
106
|
+
|
104
107
|
private
|
105
108
|
|
106
109
|
def self.log(sym, msg, *args)
|
107
110
|
rv = args.empty? ? msg : args.first
|
108
|
-
|
109
|
-
return rv unless verbosity >= MIN_VERBOSITY[sym]
|
111
|
+
|
112
|
+
return rv unless verbosity >= MIN_VERBOSITY[sym]
|
110
113
|
|
111
114
|
unless args.empty?
|
112
115
|
msg += ": " + args.map(&:inspect).join(", ")
|
@@ -115,16 +118,16 @@ module UI
|
|
115
118
|
if color = colored? && COLORS[MESSAGE_COLOR[sym]]
|
116
119
|
msg = "#{color}#{msg}#{COLORS[:clear]}"
|
117
120
|
end
|
118
|
-
|
121
|
+
|
119
122
|
if verbosity > 2
|
120
123
|
source = caller[1]
|
121
124
|
source.gsub!( Dir.getwd, "." )
|
122
125
|
source.gsub!( File.expand_path("~"), "~" )
|
123
126
|
msg = "%-90s from: %s" % [ msg, source ]
|
124
127
|
end
|
125
|
-
|
128
|
+
|
126
129
|
STDERR.puts msg
|
127
|
-
|
130
|
+
|
128
131
|
rv
|
129
132
|
end
|
130
133
|
end
|
data/test/simple_ui_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-ui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- radiospiel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple code for simple things in the console
|
14
14
|
email: eno@radiospiel.org
|
@@ -29,17 +29,17 @@ require_paths:
|
|
29
29
|
- lib
|
30
30
|
required_ruby_version: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
41
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.
|
42
|
+
rubygems_version: 2.5.1
|
43
43
|
signing_key:
|
44
44
|
specification_version: 4
|
45
45
|
summary: Simple code for simple things in the console
|