cli_miami 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cli_miami/say.rb +30 -23
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48662d5ea8d91aff8cb48d9e0fe7ed1358de0b8e
|
4
|
+
data.tar.gz: 338e8dee36d5ebd7bbecfb6f105ec2277279ff44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeba0dee1b30c80e8d36cb5b73c0cda1333bb0fa290b90137dfa956e2eaf220ee0f2b3e0e4d6d540af28c694d66f1bee62a3aaf1ac2051acd67f0ff8c5ed671d
|
7
|
+
data.tar.gz: a1023e81d0816d6961c8f932c5f33483b59ece1ef63521f95180644c9dda73576389a3c19cc6f373f9d5b3cf2b0ce8660389a12dff7ad8616c23bea9aec05d2f
|
data/lib/cli_miami/say.rb
CHANGED
@@ -38,60 +38,67 @@ class CliMiami::S
|
|
38
38
|
# newline: => [boolean] True if you want a newline after the output
|
39
39
|
# overwrite: => [boolean] True if you want the next line to overwrite the current line
|
40
40
|
#
|
41
|
-
def self.ay text = '', options
|
42
|
-
# get preset if symbol is passed
|
43
|
-
if options.is_a? Symbol
|
44
|
-
options = @@presets[options]
|
45
|
-
end
|
46
|
-
|
41
|
+
def self.ay text = '', options
|
47
42
|
# set default options
|
48
|
-
options = {
|
43
|
+
@options = {
|
49
44
|
:style => [],
|
50
45
|
:newline => true
|
51
|
-
}
|
46
|
+
}
|
47
|
+
|
48
|
+
# merge preset options
|
49
|
+
if options.is_a? Symbol
|
50
|
+
@options.merge! @@presets[options]
|
51
|
+
elsif preset = options.delete(:preset)
|
52
|
+
@options.merge! @@presets[preset]
|
53
|
+
end
|
54
|
+
|
55
|
+
# merge remaining options
|
56
|
+
if options.is_a? Hash
|
57
|
+
@options.merge! options || {}
|
58
|
+
end
|
52
59
|
|
53
60
|
# convert single style into an array for processing
|
54
|
-
if
|
55
|
-
options[:style] = [options[:style]]
|
61
|
+
if !@options[:style].is_a? Array
|
62
|
+
@options[:style] = [@options[:style]]
|
56
63
|
end
|
57
64
|
|
58
65
|
# Justify/Padding options
|
59
|
-
if options[:justify] && options[:padding]
|
60
|
-
text = text.send options[:justify], options[:padding]
|
66
|
+
if @options[:justify] && @options[:padding]
|
67
|
+
text = text.send @options[:justify], @options[:padding]
|
61
68
|
end
|
62
69
|
|
63
70
|
# Set foreground color
|
64
|
-
if options[:color]
|
71
|
+
if @options[:color]
|
65
72
|
# if bright style is passed, use the bright color variation
|
66
|
-
text = if options[:style].delete :bright
|
67
|
-
text.send("bright_#{options[:color]}")
|
73
|
+
text = if @options[:style].delete :bright
|
74
|
+
text.send("bright_#{@options[:color]}")
|
68
75
|
else
|
69
|
-
text.send(options[:color])
|
76
|
+
text.send(@options[:color])
|
70
77
|
end
|
71
78
|
end
|
72
79
|
|
73
80
|
# Set background color
|
74
|
-
if options[:bgcolor]
|
75
|
-
text = text.send("on_#{options[:bgcolor]}")
|
81
|
+
if @options[:bgcolor]
|
82
|
+
text = text.send("on_#{@options[:bgcolor]}")
|
76
83
|
end
|
77
84
|
|
78
85
|
# Apply all styles
|
79
|
-
options[:style].each do |style|
|
86
|
+
@options[:style].each do |style|
|
80
87
|
text = text.send(style)
|
81
88
|
end
|
82
89
|
|
83
90
|
# Indent
|
84
|
-
if options[:indent]
|
85
|
-
text = (' ' * options[:indent]) + text
|
91
|
+
if @options[:indent]
|
92
|
+
text = (' ' * @options[:indent]) + text
|
86
93
|
end
|
87
94
|
|
88
95
|
# Flag text to be overwritten by next text written
|
89
|
-
if options[:overwrite]
|
96
|
+
if @options[:overwrite]
|
90
97
|
text = "#{text}\r"
|
91
98
|
end
|
92
99
|
|
93
100
|
# Determine if a newline should be used
|
94
|
-
if
|
101
|
+
if !@options[:newline] || @options[:overwrite]
|
95
102
|
$stdout.print text
|
96
103
|
else
|
97
104
|
$stdout.puts text
|