downup 0.7.4 → 0.8.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/examples/basic.rb +8 -0
- data/lib/downup/options_printer.rb +103 -0
- data/lib/downup/version.rb +1 -1
- data/lib/downup.rb +35 -47
- metadata +3 -3
- data/downup-0.6.4.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ad502934bddada6b88d84915f3f5cff02d5edf7
|
4
|
+
data.tar.gz: e193c0f2b5243b0a4a7089ac1558ed02948bb5f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f927774429e6bc921e37d6376a6a6aa6683ce7e09f1d735ea80abb304b6babaf99fe7f04c1b44439a65a41c8595bb020d50dadaa6276a04da23ee0004923174
|
7
|
+
data.tar.gz: 75192244af7c98c91729a96b8db5432e8ec71eef23dc54dc78fdf571acd6c838f61f8d5aba77e196f7a8f7bb9e4cd7d50ab7d5f8ccc7582f42e990aa2dbc56bc
|
data/README.md
CHANGED
@@ -88,6 +88,15 @@ options = {
|
|
88
88
|
|
89
89
|
puts Downup::Base.new(options: options).prompt
|
90
90
|
|
91
|
+
# You can also specifiy a different value from display
|
92
|
+
options = {
|
93
|
+
"a" => {"value" => "cat_1", "display" => "Cat"},
|
94
|
+
"b" => {"value" => "kangaroo_1", "display" => "Kangaroo"},
|
95
|
+
"c" => {"value" => "dog_1", "display" => "Dog"}
|
96
|
+
}
|
97
|
+
|
98
|
+
puts Downup::Base.new(options: options).prompt
|
99
|
+
|
91
100
|
# You can also pass in the selector you would like
|
92
101
|
# if passing in a hash
|
93
102
|
puts Downup::Base.new(options: options, selector: "†").prompt
|
data/examples/basic.rb
CHANGED
@@ -43,3 +43,11 @@ options = {
|
|
43
43
|
puts Downup::Base.new(options: options).prompt
|
44
44
|
|
45
45
|
puts Downup::Base.new(options: options, selector: "†").prompt
|
46
|
+
|
47
|
+
options = {
|
48
|
+
"a" => {"value" => "cat_1", "display" => "Cat"},
|
49
|
+
"b" => {"value" => "kangaroo_1", "display" => "Kangaroo"},
|
50
|
+
"c" => {"value" => "dog_1", "display" => "Dog"}
|
51
|
+
}
|
52
|
+
|
53
|
+
puts Downup::Base.new(options: options).prompt
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative "colors"
|
2
|
+
|
3
|
+
module Downup
|
4
|
+
class OptionsPrinter
|
5
|
+
using Colors
|
6
|
+
|
7
|
+
def initialize(options:,
|
8
|
+
selected_position:,
|
9
|
+
title: nil,
|
10
|
+
default_color: :brown,
|
11
|
+
selected_color: :magenta,
|
12
|
+
selector: "‣",
|
13
|
+
stdin: $stdout,
|
14
|
+
stdout: $stdout,
|
15
|
+
header_proc: Proc.new {})
|
16
|
+
|
17
|
+
@options = options
|
18
|
+
@title = title
|
19
|
+
@default_color = default_color
|
20
|
+
@selected_position = selected_position
|
21
|
+
@selected_color = selected_color
|
22
|
+
@selector = selector
|
23
|
+
@header_proc = header_proc
|
24
|
+
@stdin = stdin
|
25
|
+
@stdout = stdout
|
26
|
+
@colonel = Kernel
|
27
|
+
end
|
28
|
+
|
29
|
+
def print_options
|
30
|
+
case options
|
31
|
+
when Array then print_array_options
|
32
|
+
when Hash
|
33
|
+
if options_has_value_and_display?
|
34
|
+
print_complex_hash_options
|
35
|
+
else
|
36
|
+
print_simple_hash_options
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :options,
|
44
|
+
:title,
|
45
|
+
:selected_position,
|
46
|
+
:header_proc,
|
47
|
+
:selected_color,
|
48
|
+
:selector,
|
49
|
+
:default_color,
|
50
|
+
:stdin,
|
51
|
+
:stdout,
|
52
|
+
:colonel
|
53
|
+
|
54
|
+
def print_complex_hash_options
|
55
|
+
options.each_with_index do |option_array, index|
|
56
|
+
key = option_array.first
|
57
|
+
value_hash = option_array.last
|
58
|
+
if index == selected_position
|
59
|
+
stdout.puts "(#{eval("selector.#{selected_color}")}) " +
|
60
|
+
eval("value_hash.fetch('display').#{selected_color}")
|
61
|
+
else
|
62
|
+
stdout.print "(#{eval("key.#{default_color}")}) "
|
63
|
+
stdout.print "#{eval("value_hash.fetch('display').#{default_color}")}\n"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def print_simple_hash_options
|
69
|
+
options.each_with_index do |option_array, index|
|
70
|
+
if index == selected_position
|
71
|
+
stdout.puts "(#{eval("selector.#{selected_color}")}) " +
|
72
|
+
eval("option_array.last.#{selected_color}")
|
73
|
+
else
|
74
|
+
stdout.print "(#{eval("option_array.first.#{default_color}")}) "
|
75
|
+
stdout.print "#{eval("option_array.last.#{default_color}")}\n"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def print_array_options
|
81
|
+
options.each_with_index do |option, index|
|
82
|
+
stdout.puts colorize_option(option, index)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def colorize_option(option, index)
|
87
|
+
if index == selected_position
|
88
|
+
eval("option.#{selected_color}")
|
89
|
+
else
|
90
|
+
eval("option.#{default_color}")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Duplicated in Base, maybe move onto Hash and String with contrainsts
|
95
|
+
def options_has_value_and_display?
|
96
|
+
options.values.all? { |option|
|
97
|
+
option.is_a?(Hash) && option.has_key?("value")
|
98
|
+
} && options.values.all? { |option|
|
99
|
+
option.is_a?(Hash) && option.has_key?("display")
|
100
|
+
}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/downup/version.rb
CHANGED
data/lib/downup.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "downup/version"
|
2
|
+
require "downup/options_printer"
|
2
3
|
require "downup/colors"
|
3
4
|
require "io/console"
|
4
5
|
|
@@ -11,6 +12,8 @@ module Downup
|
|
11
12
|
default_color: :brown,
|
12
13
|
selected_color: :magenta,
|
13
14
|
selector: "‣",
|
15
|
+
stdin: $stdin,
|
16
|
+
stdout: $stdout,
|
14
17
|
header_proc: Proc.new {})
|
15
18
|
|
16
19
|
@options = options
|
@@ -19,31 +22,37 @@ module Downup
|
|
19
22
|
@selected_color = selected_color
|
20
23
|
@selector = selector
|
21
24
|
@header_proc = header_proc
|
22
|
-
@stdin =
|
23
|
-
@stdout =
|
25
|
+
@stdin = stdin
|
26
|
+
@stdout = stdout
|
27
|
+
@colonel = Kernel
|
24
28
|
end
|
25
29
|
|
26
30
|
def prompt(position = 0)
|
27
31
|
@selected_position = position_selector(position)
|
28
|
-
system("clear")
|
32
|
+
colonel.system("clear")
|
29
33
|
header_proc.call
|
30
34
|
print_title
|
31
|
-
|
35
|
+
Downup::OptionsPrinter.new(
|
36
|
+
options: options,
|
37
|
+
selected_position: @selected_position
|
38
|
+
).print_options
|
32
39
|
stdout.print "\n> "
|
33
|
-
|
40
|
+
input = read_char
|
41
|
+
process_input input
|
34
42
|
end
|
35
43
|
|
36
44
|
private
|
37
45
|
|
38
46
|
attr_reader :options,
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
:title,
|
48
|
+
:selected_position,
|
49
|
+
:header_proc,
|
50
|
+
:selected_color,
|
51
|
+
:selector,
|
52
|
+
:default_color,
|
53
|
+
:stdin,
|
54
|
+
:stdout,
|
55
|
+
:colonel
|
47
56
|
|
48
57
|
def process_input(input)
|
49
58
|
case input
|
@@ -64,10 +73,22 @@ module Downup
|
|
64
73
|
when Array
|
65
74
|
options[selected_position]
|
66
75
|
when Hash
|
67
|
-
|
76
|
+
if options_has_value_and_display?
|
77
|
+
options.fetch(option_keys[selected_position]).fetch("value")
|
78
|
+
else
|
79
|
+
options.fetch(option_keys[selected_position])
|
80
|
+
end
|
68
81
|
end
|
69
82
|
end
|
70
83
|
|
84
|
+
def options_has_value_and_display?
|
85
|
+
options.values.all? { |option|
|
86
|
+
option.is_a?(Hash) && option.has_key?("value")
|
87
|
+
} && options.values.all? { |option|
|
88
|
+
option.is_a?(Hash) && option.has_key?("display")
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
71
92
|
def option_keys
|
72
93
|
options.is_a?(Array) ? [] : options.keys
|
73
94
|
end
|
@@ -79,39 +100,6 @@ module Downup
|
|
79
100
|
else position; end
|
80
101
|
end
|
81
102
|
|
82
|
-
def print_options
|
83
|
-
case options
|
84
|
-
when Array then print_array_options
|
85
|
-
when Hash then print_hash_options
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def print_hash_options
|
90
|
-
options.each_with_index do |option_array, index|
|
91
|
-
if index == selected_position
|
92
|
-
stdout.puts "(#{eval("selector.#{selected_color}")}) " +
|
93
|
-
eval("option_array.last.#{selected_color}")
|
94
|
-
else
|
95
|
-
stdout.print "(#{eval("option_array.first.#{default_color}")}) "
|
96
|
-
stdout.print "#{eval("option_array.last.#{default_color}")}\n"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def print_array_options
|
102
|
-
options.each_with_index do |option, index|
|
103
|
-
stdout.puts colorize_option(option, index)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def colorize_option(option, index)
|
108
|
-
if index == selected_position
|
109
|
-
eval("option.#{selected_color}")
|
110
|
-
else
|
111
|
-
eval("option.#{default_color}")
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
103
|
def print_title
|
116
104
|
return if title.nil?
|
117
105
|
stdout.puts "#{title}".red
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: downup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Begin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,11 +55,11 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- bin/console
|
57
57
|
- bin/setup
|
58
|
-
- downup-0.6.4.gem
|
59
58
|
- downup.gemspec
|
60
59
|
- examples/basic.rb
|
61
60
|
- lib/downup.rb
|
62
61
|
- lib/downup/colors.rb
|
62
|
+
- lib/downup/options_printer.rb
|
63
63
|
- lib/downup/version.rb
|
64
64
|
homepage: https://github.com/presidentJFK/downup
|
65
65
|
licenses:
|
data/downup-0.6.4.gem
DELETED
Binary file
|