cli_miami 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/cli_miami/ask.rb +34 -0
- data/lib/cli_miami/say.rb +111 -0
- data/lib/namespaced.rb +6 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f27ada6d252c35a283bccb8ad5fed5dfb7bf50a1
|
4
|
+
data.tar.gz: 521ac8de8dc309bd31637e778b45fa3ba06adc2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6add69a2ff9a694dd4e35b6b2c71a0cdfe349956402e5b486bb7b905b8b1779238193fa08eaf92b1c1de12bbb3fd829d2384c906788cbba21442f7aaaabf4a7
|
7
|
+
data.tar.gz: 4b68335b9b95a96a06a5fcb72a45c44a85087dcc68d4069628f6751ff871266d47dc3abe9600e3118e0e2fdc47d9ecccd1e2c9eaeac912b1bee9f7d45e22f1cd
|
data/.gitignore
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#
|
2
|
+
# class CliMiami::Ask
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'readline'
|
6
|
+
|
7
|
+
class CliMiami::A
|
8
|
+
@@prompt = '>>> '
|
9
|
+
|
10
|
+
# See documentation for CliMiami::S.ay
|
11
|
+
# The same options are accepted
|
12
|
+
#
|
13
|
+
def self.sk question, options = {}, &block
|
14
|
+
options = {
|
15
|
+
:readline => false,
|
16
|
+
}.merge(options)
|
17
|
+
|
18
|
+
CliMiami::S.ay question, options
|
19
|
+
|
20
|
+
output = if options[:readline]
|
21
|
+
Readline.readline(@@prompt).chomp('/')
|
22
|
+
else
|
23
|
+
CliMiami::S.ay @@prompt, :newline => false
|
24
|
+
$stdin.gets
|
25
|
+
end.rstrip
|
26
|
+
|
27
|
+
yield output if block
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.prompt; @@prompt; end
|
31
|
+
def self.prompt= prompt
|
32
|
+
@@prompt = prompt
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
#
|
2
|
+
# class CliMiami::Say
|
3
|
+
#
|
4
|
+
require 'term/ansicolor'
|
5
|
+
|
6
|
+
class String
|
7
|
+
include Term::ANSIColor
|
8
|
+
end
|
9
|
+
|
10
|
+
class CliMiami::S
|
11
|
+
|
12
|
+
# default presets
|
13
|
+
@@presets = {
|
14
|
+
:fail => {
|
15
|
+
:color => :red,
|
16
|
+
:style => :bold
|
17
|
+
},
|
18
|
+
:warn => {
|
19
|
+
:color => :yellow,
|
20
|
+
:style => :bold
|
21
|
+
},
|
22
|
+
:success => {
|
23
|
+
:color => :green,
|
24
|
+
:style => :bold
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
# By preset...
|
29
|
+
# [symbol] Uses defined preset
|
30
|
+
|
31
|
+
# By options...
|
32
|
+
# color: => [symbol] See README for ansi color codes
|
33
|
+
# bgcolor: => [symbol] See README for ansi color codes
|
34
|
+
# style: => [symbol] See README for ansi style codes
|
35
|
+
# justify: => [center|ljust|rjust] The type of justification to use
|
36
|
+
# padding: => [integer] The maximum string size to justify text in
|
37
|
+
# indent: => [integer] The number of characters to indent
|
38
|
+
# newline: => [boolean] True if you want a newline after the output
|
39
|
+
# overwrite: => [boolean] True if you want the next line to overwrite the current line
|
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
|
+
|
47
|
+
# set default options
|
48
|
+
options = {
|
49
|
+
:style => [],
|
50
|
+
:newline => true
|
51
|
+
}.merge options
|
52
|
+
|
53
|
+
# convert single style into an array for processing
|
54
|
+
if !options[:style].is_a? Array
|
55
|
+
options[:style] = [options[:style]]
|
56
|
+
end
|
57
|
+
|
58
|
+
# Justify/Padding options
|
59
|
+
if options[:justify] && options[:padding]
|
60
|
+
text = text.send options[:justify], options[:padding]
|
61
|
+
end
|
62
|
+
|
63
|
+
# Set foreground color
|
64
|
+
if options[:color]
|
65
|
+
# if bright style is passed, use the bright color variation
|
66
|
+
text = if options[:style].delete :bright
|
67
|
+
text.send("bright_#{options[:color]}")
|
68
|
+
else
|
69
|
+
text.send(options[:color])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Set background color
|
74
|
+
if options[:bgcolor]
|
75
|
+
text = text.send("on_#{options[:bgcolor]}")
|
76
|
+
end
|
77
|
+
|
78
|
+
# Apply all styles
|
79
|
+
options[:style].each do |style|
|
80
|
+
text = text.send(style)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Indent
|
84
|
+
if options[:indent]
|
85
|
+
text = (' ' * options[:indent]) + text
|
86
|
+
end
|
87
|
+
|
88
|
+
# Flag text to be overwritten by next text written
|
89
|
+
if options[:overwrite]
|
90
|
+
text = "#{text}\r"
|
91
|
+
end
|
92
|
+
|
93
|
+
# Determine if a newline should be used
|
94
|
+
if !options[:newline] || options[:overwrite]
|
95
|
+
$stdout.print text
|
96
|
+
else
|
97
|
+
$stdout.puts text
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Returns all presets
|
102
|
+
def self.presets
|
103
|
+
@@presets
|
104
|
+
end
|
105
|
+
|
106
|
+
# Create a new custom preset
|
107
|
+
def self.set_preset type, options
|
108
|
+
raise 'Preset must be a hash of options' unless options.is_a? Hash
|
109
|
+
@@presets[type] = options
|
110
|
+
end
|
111
|
+
end
|
data/lib/namespaced.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli_miami
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Brewster
|
@@ -94,6 +94,9 @@ files:
|
|
94
94
|
- Guardfile
|
95
95
|
- README.md
|
96
96
|
- lib/cli_miami.rb
|
97
|
+
- lib/cli_miami/ask.rb
|
98
|
+
- lib/cli_miami/say.rb
|
99
|
+
- lib/namespaced.rb
|
97
100
|
- yuyi_menu
|
98
101
|
homepage: https://github.com/brewster1134/cli_miami
|
99
102
|
licenses:
|