downup 0.9.6 → 0.10.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +9 -0
- data/Rakefile +5 -0
- data/downup-0.9.6.gem +0 -0
- data/examples/basic.rb +10 -0
- data/lib/downup/options_printer.rb +26 -17
- data/lib/downup/version.rb +1 -1
- data/lib/downup.rb +65 -14
- metadata +3 -3
- data/downup-0.8.6.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: 50ea069f025c5ee5ccdd082820621d10885549b9
|
4
|
+
data.tar.gz: 7a985a5e14de1a7322681559149e73610c04f5c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 096cefcf1988f3cec67893fcbd73fa5069c8c9887bc04be862f3ba961f2e5ca811cf441a33c7bc6130f678d564c2a8fb294e460a9e358fe7a9b83d3e15968d97
|
7
|
+
data.tar.gz: 7e96431cae385f47bb5354621501221bcf88736a5f94f168607e2a84cb694a3f21c44e7e95b3490518f9383860494c8654ebf2f5b93d64c58e0c11a136e74ae5
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -100,6 +100,9 @@ puts Downup::Base.new(options: options).prompt
|
|
100
100
|
# You can also pass in the selector you would like
|
101
101
|
# if passing in a hash
|
102
102
|
puts Downup::Base.new(options: options, selector: "†").prompt
|
103
|
+
|
104
|
+
# You can also enable multi_select,
|
105
|
+
Downup::Base.new(options: options, type: :multi_select).prompt
|
103
106
|
```
|
104
107
|
|
105
108
|
## Inspired By
|
@@ -115,6 +118,12 @@ http://stackoverflow.com/questions/1489183/colorized-ruby-output
|
|
115
118
|
|
116
119
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
117
120
|
|
121
|
+
To run specs
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
rake test
|
125
|
+
```
|
126
|
+
|
118
127
|
## Contributing
|
119
128
|
|
120
129
|
1. Fork it ( https://github.com/[my-github-username]/downup/fork )
|
data/Rakefile
CHANGED
data/downup-0.9.6.gem
ADDED
Binary file
|
data/examples/basic.rb
CHANGED
@@ -57,3 +57,13 @@ options = {
|
|
57
57
|
}
|
58
58
|
|
59
59
|
puts Downup::Base.new(options: options).prompt
|
60
|
+
|
61
|
+
options = {
|
62
|
+
"a" => "Cat",
|
63
|
+
"b" => "Dog",
|
64
|
+
"c" => "Kangaroo",
|
65
|
+
"d" => "Snake",
|
66
|
+
"e" => "Eel"
|
67
|
+
}
|
68
|
+
|
69
|
+
Downup::Base.new(options: options, type: :multi_select).prompt
|
@@ -5,25 +5,25 @@ module Downup
|
|
5
5
|
using Colors
|
6
6
|
|
7
7
|
def initialize(options:,
|
8
|
-
selected_position
|
9
|
-
title: nil,
|
8
|
+
selected_position: 0,
|
10
9
|
default_color: :brown,
|
11
10
|
selected_color: :magenta,
|
12
11
|
selector: "‣",
|
12
|
+
multi_selected_positions: [],
|
13
|
+
type: :default,
|
13
14
|
stdin: $stdout,
|
14
|
-
stdout: $stdout
|
15
|
-
header_proc: Proc.new {})
|
15
|
+
stdout: $stdout)
|
16
16
|
|
17
|
-
@options
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@selector
|
23
|
-
@
|
24
|
-
@stdin
|
25
|
-
@stdout
|
26
|
-
@colonel
|
17
|
+
@options = options
|
18
|
+
@default_color = default_color
|
19
|
+
@selected_position = selected_position
|
20
|
+
@selected_color = selected_color
|
21
|
+
@multi_selected_positions = multi_selected_positions
|
22
|
+
@selector = selector
|
23
|
+
@type = type
|
24
|
+
@stdin = stdin
|
25
|
+
@stdout = stdout
|
26
|
+
@colonel = Kernel
|
27
27
|
end
|
28
28
|
|
29
29
|
def print_options
|
@@ -41,12 +41,12 @@ module Downup
|
|
41
41
|
private
|
42
42
|
|
43
43
|
attr_reader :options,
|
44
|
-
:title,
|
45
44
|
:selected_position,
|
46
|
-
:header_proc,
|
47
45
|
:selected_color,
|
48
46
|
:selector,
|
49
47
|
:default_color,
|
48
|
+
:multi_selected_positions,
|
49
|
+
:type,
|
50
50
|
:stdin,
|
51
51
|
:stdout,
|
52
52
|
:colonel
|
@@ -60,7 +60,9 @@ module Downup
|
|
60
60
|
eval("value_hash.fetch('display').#{selected_color}")
|
61
61
|
else
|
62
62
|
stdout.print "(#{eval("key.#{default_color}")}) "
|
63
|
-
stdout.print
|
63
|
+
stdout.print(
|
64
|
+
"#{eval("value_hash.fetch('display').#{default_color}")}\n"
|
65
|
+
)
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|
@@ -70,6 +72,9 @@ module Downup
|
|
70
72
|
if index == selected_position
|
71
73
|
stdout.puts "(#{eval("selector.#{selected_color}")}) " +
|
72
74
|
eval("option_array.last.#{selected_color}")
|
75
|
+
elsif multi_selected_positions.include?(index)
|
76
|
+
stdout.puts "(#{eval("multi_selector.#{selected_color}")}) " +
|
77
|
+
eval("option_array.last.#{selected_color}")
|
73
78
|
else
|
74
79
|
stdout.print "(#{eval("option_array.first.#{default_color}")}) "
|
75
80
|
stdout.print "#{eval("option_array.last.#{default_color}")}\n"
|
@@ -99,5 +104,9 @@ module Downup
|
|
99
104
|
option.is_a?(Hash) && option.has_key?("display")
|
100
105
|
}
|
101
106
|
end
|
107
|
+
|
108
|
+
def multi_selector
|
109
|
+
"•"
|
110
|
+
end
|
102
111
|
end
|
103
112
|
end
|
data/lib/downup/version.rb
CHANGED
data/lib/downup.rb
CHANGED
@@ -7,12 +7,15 @@ module Downup
|
|
7
7
|
using Colors
|
8
8
|
|
9
9
|
class Base
|
10
|
+
attr_reader :selected_position
|
11
|
+
|
10
12
|
def initialize(options:,
|
11
13
|
flash_message: nil,
|
12
14
|
flash_color: :green,
|
13
15
|
default_color: :brown,
|
14
16
|
selected_color: :magenta,
|
15
17
|
selector: "‣",
|
18
|
+
type: :default,
|
16
19
|
stdin: $stdin,
|
17
20
|
stdout: $stdout,
|
18
21
|
header_proc: Proc.new {})
|
@@ -23,10 +26,13 @@ module Downup
|
|
23
26
|
@default_color = default_color
|
24
27
|
@selected_color = selected_color
|
25
28
|
@selector = selector
|
29
|
+
@type = type
|
26
30
|
@header_proc = header_proc
|
27
31
|
@stdin = stdin
|
28
32
|
@stdout = stdout
|
29
33
|
@colonel = Kernel
|
34
|
+
|
35
|
+
@multi_selected_positions = []
|
30
36
|
end
|
31
37
|
|
32
38
|
def prompt(position = 0)
|
@@ -37,9 +43,12 @@ module Downup
|
|
37
43
|
Downup::OptionsPrinter.new(
|
38
44
|
options: options,
|
39
45
|
selected_position: @selected_position,
|
46
|
+
multi_selected_positions: @multi_selected_positions,
|
40
47
|
default_color: default_color,
|
41
48
|
selected_color: selected_color,
|
42
|
-
selector: selector
|
49
|
+
selector: selector,
|
50
|
+
stdin: stdin,
|
51
|
+
stdout: stdout,
|
43
52
|
).print_options
|
44
53
|
stdout.print "\n> "
|
45
54
|
input = read_char
|
@@ -48,17 +57,27 @@ module Downup
|
|
48
57
|
|
49
58
|
private
|
50
59
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def options
|
61
|
+
@_options ||=
|
62
|
+
begin
|
63
|
+
if multi_select?
|
64
|
+
@options.merge({"z" => "ENTER"})
|
65
|
+
else
|
66
|
+
@options
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
attr_reader :flash_message,
|
72
|
+
:flash_color,
|
73
|
+
:header_proc,
|
74
|
+
:selected_color,
|
75
|
+
:selector,
|
76
|
+
:type,
|
77
|
+
:default_color,
|
78
|
+
:stdin,
|
79
|
+
:stdout,
|
80
|
+
:colonel
|
62
81
|
|
63
82
|
def process_input(input)
|
64
83
|
case input
|
@@ -69,11 +88,37 @@ module Downup
|
|
69
88
|
when *option_keys
|
70
89
|
prompt(option_keys.index(input))
|
71
90
|
when "\r"
|
72
|
-
|
91
|
+
if multi_select?
|
92
|
+
manage_multi_select
|
93
|
+
if selected_value == "ENTER"
|
94
|
+
execute_selection(input)
|
95
|
+
else
|
96
|
+
prompt(selected_position)
|
97
|
+
end
|
98
|
+
else
|
99
|
+
execute_selection(input)
|
100
|
+
end
|
73
101
|
when "\u0003" then exit
|
74
102
|
else prompt(selected_position); end
|
75
103
|
end
|
76
104
|
|
105
|
+
def selected_value
|
106
|
+
options.values[selected_position]
|
107
|
+
end
|
108
|
+
|
109
|
+
def manage_multi_select
|
110
|
+
if @multi_selected_positions.include?(selected_position)
|
111
|
+
@multi_selected_positions.delete(selected_position)
|
112
|
+
else
|
113
|
+
return if selected_position == @options.length
|
114
|
+
@multi_selected_positions << selected_position
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def multi_select?
|
119
|
+
type == :multi_select
|
120
|
+
end
|
121
|
+
|
77
122
|
def execute_selection(input)
|
78
123
|
case options
|
79
124
|
when Array
|
@@ -82,7 +127,13 @@ module Downup
|
|
82
127
|
if options_has_value_and_display?
|
83
128
|
options.fetch(option_keys[selected_position]).fetch("value")
|
84
129
|
else
|
85
|
-
|
130
|
+
if multi_select?
|
131
|
+
@multi_selected_positions.map do |p|
|
132
|
+
options.fetch(option_keys[p])
|
133
|
+
end
|
134
|
+
else
|
135
|
+
options.fetch(option_keys[selected_position])
|
136
|
+
end
|
86
137
|
end
|
87
138
|
end
|
88
139
|
end
|
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.10.6
|
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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,7 +55,7 @@ files:
|
|
55
55
|
- Rakefile
|
56
56
|
- bin/console
|
57
57
|
- bin/setup
|
58
|
-
- downup-0.
|
58
|
+
- downup-0.9.6.gem
|
59
59
|
- downup.gemspec
|
60
60
|
- examples/basic.rb
|
61
61
|
- lib/downup.rb
|
data/downup-0.8.6.gem
DELETED
Binary file
|