downup 0.11.6 → 0.11.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63d7f26b086ddbde4f3a21cb2ec9c81303669b04
4
- data.tar.gz: af8cb68e73047c496b68980eacfe67e1f778bbf8
3
+ metadata.gz: c5dcc699aa5f695e20cd7407d0ea1272bce09e34
4
+ data.tar.gz: 5df54c1da0dac4ac741a685102e183d002e0a095
5
5
  SHA512:
6
- metadata.gz: 9ac0ce0d0356e55f869e258902b864e065b62dae42bc570fd54ba4adde9fc9b71621beba1e7b28177a01ab343407e134f7e0b6a3ad30842edfe5b26f235fb42d
7
- data.tar.gz: 37220a831740dc68870a37ae1610c26403c35009a31b98a70ab677a895b8fa38508c7c2c7fffb1992f15e6fd6e4efbba92db4f3a1d737bccbf123d99aff0b90a
6
+ metadata.gz: fc083cbe7e1ed78dc8d665fb8de6fe1d25594b3380b1bf23004cdc35406f62edd5a85fb8028697ac54ba6e86a6b72a07b155c6d61172ef83de98a05ac7544ffe
7
+ data.tar.gz: f5b60fd68df24f004dfdf858d0cc8d8f45b0a9416c30291363c4d6b5c31ef7bb640c16c7c72455daa997a329d932641de2b1dffa75272fe5366d6297e0594940
@@ -0,0 +1,37 @@
1
+ # This is a sample .codeclimate.yml configured for Engine analysis on Code
2
+ # Climate Platform. For an overview of the Code Climate Platform, see here:
3
+ # http://docs.codeclimate.com/article/300-the-codeclimate-platform
4
+
5
+ # Under the engines key, you can configure which engines will analyze your repo.
6
+ # Each key is an engine name. For each value, you need to specify enabled: true
7
+ # to enable the engine as well as any other engines-specific configuration.
8
+
9
+ # For more details, see here:
10
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
11
+
12
+ # For a list of all available engines, see here:
13
+ # http://docs.codeclimate.com/article/296-engines-available-engines
14
+
15
+ engines:
16
+ # to turn on an engine, add it here and set enabled to `true`
17
+ # to turn off an engine, set enabled to `false` or remove it
18
+ rubocop:
19
+ enabled: true
20
+
21
+ # Engines can analyze files and report issues on them, but you can separately
22
+ # decide which files will receive ratings based on those issues. This is
23
+ # specified by path patterns under the ratings key.
24
+
25
+ # For more details see here:
26
+ # http://docs.codeclimate.com/article/289-configuring-your-repository-via-codeclimate-yml#platform
27
+
28
+ ratings:
29
+ paths:
30
+ - lib/**
31
+
32
+ # You can globally exclude files from being analyzed by any engine using the
33
+ # exclude_paths key.
34
+
35
+ #exclude_paths:
36
+ #- spec/**/*
37
+ #- vendor/**/*
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.3
4
+ addons:
5
+ code_climate:
6
+ repo_token: 11dbcc5ff92f8c6d6d1c9d0d5e5ec35c6025153ac02da45067841b60b431a6f7
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.11.7
4
+
5
+ * Moved all code into lib directory
6
+
7
+ * Added Gem Version, Build Status, Test Coverage, Code Climate, Dependency Status,
8
+ and Inline docs badges to README
9
+
10
+ * Started to Document Base class
data/Gemfile CHANGED
@@ -3,4 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in downup.gemspec
4
4
  gemspec
5
5
 
6
+ gem "minitest"
6
7
  gem "minitest-focus"
8
+ gem "minitest-reporters"
9
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Downup
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/downup.svg)](http://badge.fury.io/rb/downup) [![Build Status](https://travis-ci.org/presidentJFK/downup.svg?branch=master)](https://travis-ci.org/presidentJFK/downup) [![Test Coverage](https://codeclimate.com/github/presidentJFK/downup/badges/coverage.svg)](https://codeclimate.com/github/presidentJFK/downup/coverage) [![Code Climate](https://codeclimate.com/github/presidentJFK/downup/badges/gpa.svg)](https://codeclimate.com/github/presidentJFK/downup) [![Dependency Status](https://gemnasium.com/presidentJFK/downup.svg)](https://gemnasium.com/presidentJFK/downup) [![Inline docs](http://inch-ci.org/github/presidentJFK/downup.svg?branch=master)](http://inch-ci.org/github/presidentJFK/downup)
4
+
5
+ ### \*\*WARNING THIS GEM IS PRE 1.0 AND STILL UNSTABLE\*\*
6
+
3
7
  A simple gem for creating command line menus you can use the arrows
4
8
  to move through.
5
9
 
@@ -115,17 +119,12 @@ Downup::Base.new(
115
119
 
116
120
  ## Inspired By
117
121
 
118
- This gist
122
+ This Gist
119
123
  https://gist.github.com/acook/4190379
120
124
 
121
- and this SO article
125
+ and this Stack Overflow article
122
126
  http://stackoverflow.com/questions/1489183/colorized-ruby-output
123
127
 
124
-
125
- ## Development
126
-
127
- 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).
128
-
129
128
  To run specs
130
129
 
131
130
  ```ruby
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
 
3
+ task :default => "test"
4
+
3
5
  task :test do
4
6
  Dir.glob("test/test*").map do |file|
5
7
  require_relative file
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.8"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  end
@@ -1,184 +1,2 @@
1
1
  require_relative "downup/version"
2
- require_relative "downup/options_printer"
3
- require_relative "downup/colors"
4
- require "io/console"
5
-
6
- module Downup
7
- using Colors
8
-
9
- class Base
10
- attr_reader :selected_position
11
-
12
- def initialize(options:,
13
- flash_message: nil,
14
- flash_color: :green,
15
- default_color: :brown,
16
- selected_color: :magenta,
17
- multi_select_selector: "√",
18
- selector: "‣",
19
- type: :default,
20
- stdin: $stdin,
21
- stdout: $stdout,
22
- header_proc: Proc.new {})
23
-
24
- @options = options
25
- @flash_color = flash_color
26
- @flash_message = flash_message
27
- @default_color = default_color
28
- @selected_color = selected_color
29
- @selector = selector
30
- @type = type
31
- @header_proc = header_proc
32
- @stdin = stdin
33
- @stdout = stdout
34
- @colonel = Kernel
35
- @multi_select_selector = multi_select_selector
36
-
37
- @multi_selected_positions = []
38
- end
39
-
40
- def prompt(position = 0)
41
- @selected_position = position_selector(position)
42
- colonel.system("clear")
43
- header_proc.call
44
- print_flash
45
- Downup::OptionsPrinter.new(
46
- options: options,
47
- selected_position: @selected_position,
48
- multi_selected_positions: @multi_selected_positions,
49
- multi_select_selector: multi_select_selector,
50
- default_color: default_color,
51
- selected_color: selected_color,
52
- selector: selector,
53
- stdin: stdin,
54
- stdout: stdout,
55
- ).print_options
56
- stdout.print "\n> "
57
- input = read_char
58
- process_input input
59
- end
60
-
61
- private
62
-
63
- def options
64
- @_options ||=
65
- begin
66
- if multi_select?
67
- @options.merge({"z" => "ENTER"})
68
- else
69
- @options
70
- end
71
- end
72
- end
73
-
74
- attr_reader :flash_message,
75
- :flash_color,
76
- :header_proc,
77
- :selected_color,
78
- :selector,
79
- :type,
80
- :default_color,
81
- :stdin,
82
- :stdout,
83
- :multi_select_selector,
84
- :colonel
85
-
86
- def process_input(input)
87
- case input
88
- when "\e[A", "k"
89
- prompt(selected_position - 1)
90
- when "\e[B", "j"
91
- prompt(selected_position + 1)
92
- when *option_keys
93
- prompt(option_keys.index(input))
94
- when "\r"
95
- if multi_select?
96
- manage_multi_select
97
- if selected_value == "ENTER"
98
- execute_selection(input)
99
- else
100
- prompt(selected_position)
101
- end
102
- else
103
- execute_selection(input)
104
- end
105
- when "\u0003" then exit
106
- else prompt(selected_position); end
107
- end
108
-
109
- def selected_value
110
- options.values[selected_position]
111
- end
112
-
113
- def manage_multi_select
114
- if @multi_selected_positions.include?(selected_position)
115
- @multi_selected_positions.delete(selected_position)
116
- else
117
- return if selected_position == @options.length
118
- @multi_selected_positions << selected_position
119
- end
120
- end
121
-
122
- def multi_select?
123
- type == :multi_select
124
- end
125
-
126
- def execute_selection(input)
127
- case options
128
- when Array
129
- options[selected_position]
130
- when Hash
131
- if options_has_value_and_display?
132
- options.fetch(option_keys[selected_position]).fetch("value")
133
- else
134
- if multi_select?
135
- @multi_selected_positions.map do |p|
136
- options.fetch(option_keys[p])
137
- end
138
- else
139
- options.fetch(option_keys[selected_position])
140
- end
141
- end
142
- end
143
- end
144
-
145
- def options_has_value_and_display?
146
- options.values.all? { |option|
147
- option.is_a?(Hash) && option.has_key?("value")
148
- } && options.values.all? { |option|
149
- option.is_a?(Hash) && option.has_key?("display")
150
- }
151
- end
152
-
153
- def option_keys
154
- options.is_a?(Array) ? [] : options.keys
155
- end
156
-
157
- def position_selector(position)
158
- case position
159
- when -1 then options.count - 1
160
- when options.count then 0
161
- else position; end
162
- end
163
-
164
- def print_flash
165
- return if flash_message.nil?
166
- colored_flash = "\"#{flash_message}\".#{flash_color}"
167
- stdout.puts eval(colored_flash)
168
- end
169
-
170
- def read_char
171
- stdin.echo = false
172
- stdin.raw!
173
- input = stdin.getc.chr
174
- if input == "\e" then
175
- input << stdin.read_nonblock(3) rescue nil
176
- input << stdin.read_nonblock(2) rescue nil
177
- end
178
- ensure
179
- stdin.echo = true
180
- stdin.cooked!
181
- return input
182
- end
183
- end
184
- end
2
+ require_relative "downup/base"
@@ -0,0 +1,213 @@
1
+ require_relative "version"
2
+ require_relative "options_printer"
3
+ require_relative "colors"
4
+ require "io/console"
5
+
6
+ module Downup
7
+ using Colors
8
+
9
+ ##
10
+ # The main interface to use Downup
11
+ #
12
+ # initialize a Downup::Base object with all your desired options
13
+ # and call +#prompt+ to retrieve the user selection.
14
+ class Base
15
+ attr_reader :selected_position
16
+
17
+ # @param options [Hash|Array] collection of options to choose from
18
+ # @param flash_message [String] A message to be displayed above the downup menu
19
+ # @param flash_color [Symbol] color of flash message
20
+ # @param default_color [Symbol] The color an unchoosen item
21
+ # @param selected_color [Symbol] The color a choosen item
22
+ # @param multi_select_selector [String] The charactor for selected items in multi mode
23
+ # @param selector [String] The charactor for the moving selector in non-multi mode
24
+ # @param type [Symbol] single select/default or multi select mode, `:default` or `:multi_select`
25
+ # @param header_proc [Proc] a proc that will called before each render of option selection
26
+ #
27
+ # @example array of options
28
+ # Downup::Base.new(options: ["option 1", "option 2"])
29
+ #
30
+ # @example hash of options
31
+ # Downup::Base.new(options: {"a" => "option 1", "b" => "option 2"})
32
+ #
33
+ # @example hash with "value" and "display" keys
34
+ # Downup::Base.new(options: {"a" => {"value" => "option 1", "display" => "Option 1"}})
35
+ #
36
+ # @example header_proc example
37
+ # Downup::Base.new(options: [], header_proc: Proc.new {puts "Hello"})
38
+ def initialize(options:,
39
+ flash_message: nil,
40
+ flash_color: :green,
41
+ default_color: :brown,
42
+ selected_color: :magenta,
43
+ multi_select_selector: "√",
44
+ selector: "‣",
45
+ type: :default,
46
+ stdin: $stdin,
47
+ stdout: $stdout,
48
+ header_proc: Proc.new{})
49
+
50
+ @options = options
51
+ @flash_color = flash_color
52
+ @flash_message = flash_message
53
+ @default_color = default_color
54
+ @selected_color = selected_color
55
+ @selector = selector
56
+ @type = type
57
+ @header_proc = header_proc
58
+ @stdin = stdin
59
+ @stdout = stdout
60
+ @colonel = Kernel
61
+ @multi_select_selector = multi_select_selector
62
+ @multi_selected_positions = []
63
+ end
64
+
65
+ # Prompts the user to make selection from the options
66
+ # the object with initialized with.
67
+ # @param position [Integer] where the selector will start at
68
+ # @return [String] a string of the user's selection
69
+ def prompt(position = 0)
70
+ @selected_position = position_selector(position)
71
+ colonel.system("clear")
72
+ header_proc.call
73
+ print_flash
74
+ Downup::OptionsPrinter.new(
75
+ options: options,
76
+ selected_position: @selected_position,
77
+ multi_selected_positions: @multi_selected_positions,
78
+ multi_select_selector: multi_select_selector,
79
+ default_color: default_color,
80
+ selected_color: selected_color,
81
+ selector: selector,
82
+ stdin: stdin,
83
+ stdout: stdout,
84
+ ).print_options
85
+ stdout.print "\n> "
86
+ input = read_char
87
+ process_input input
88
+ end
89
+
90
+ private
91
+
92
+ def options
93
+ @_options ||=
94
+ begin
95
+ if multi_select?
96
+ @options.merge({"z" => "ENTER"})
97
+ else
98
+ @options
99
+ end
100
+ end
101
+ end
102
+
103
+ attr_reader :flash_message,
104
+ :flash_color,
105
+ :header_proc,
106
+ :selected_color,
107
+ :selector,
108
+ :type,
109
+ :default_color,
110
+ :stdin,
111
+ :stdout,
112
+ :multi_select_selector,
113
+ :colonel
114
+
115
+ def process_input(input)
116
+ case input
117
+ when "\e[A", "k"
118
+ prompt(selected_position - 1)
119
+ when "\e[B", "j"
120
+ prompt(selected_position + 1)
121
+ when *option_keys
122
+ prompt(option_keys.index(input))
123
+ when "\r"
124
+ if multi_select?
125
+ manage_multi_select
126
+ if selected_value == "ENTER"
127
+ execute_selection(input)
128
+ else
129
+ prompt(selected_position)
130
+ end
131
+ else
132
+ execute_selection(input)
133
+ end
134
+ when "\u0003" then exit
135
+ else prompt(selected_position); end
136
+ end
137
+
138
+ def selected_value
139
+ options.values[selected_position]
140
+ end
141
+
142
+ def manage_multi_select
143
+ if @multi_selected_positions.include?(selected_position)
144
+ @multi_selected_positions.delete(selected_position)
145
+ else
146
+ return if selected_position == @options.length
147
+ @multi_selected_positions << selected_position
148
+ end
149
+ end
150
+
151
+ def multi_select?
152
+ type == :multi_select
153
+ end
154
+
155
+ def execute_selection(input)
156
+ case options
157
+ when Array
158
+ options[selected_position]
159
+ when Hash
160
+ if options_has_value_and_display?
161
+ options.fetch(option_keys[selected_position]).fetch("value")
162
+ else
163
+ if multi_select?
164
+ @multi_selected_positions.map do |p|
165
+ options.fetch(option_keys[p])
166
+ end
167
+ else
168
+ options.fetch(option_keys[selected_position])
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ def options_has_value_and_display?
175
+ options.values.all? { |option|
176
+ option.is_a?(Hash) && option.has_key?("value")
177
+ } && options.values.all? { |option|
178
+ option.is_a?(Hash) && option.has_key?("display")
179
+ }
180
+ end
181
+
182
+ def option_keys
183
+ options.is_a?(Array) ? [] : options.keys
184
+ end
185
+
186
+ def position_selector(position)
187
+ case position
188
+ when -1 then options.count - 1
189
+ when options.count then 0
190
+ else position; end
191
+ end
192
+
193
+ def print_flash
194
+ return if flash_message.nil?
195
+ colored_flash = "\"#{flash_message}\".#{flash_color}"
196
+ stdout.puts eval(colored_flash)
197
+ end
198
+
199
+ def read_char
200
+ stdin.echo = false
201
+ stdin.raw!
202
+ input = stdin.getc.chr
203
+ if input == "\e" then
204
+ input << stdin.read_nonblock(3) rescue nil
205
+ input << stdin.read_nonblock(2) rescue nil
206
+ end
207
+ ensure
208
+ stdin.echo = true
209
+ stdin.cooked!
210
+ return input
211
+ end
212
+ end
213
+ end
@@ -1,3 +1,3 @@
1
1
  module Downup
2
- VERSION = "0.11.6"
2
+ VERSION = "0.11.7"
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: downup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.6
4
+ version: 0.11.7
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-29 00:00:00.000000000 Z
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,9 +45,11 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".codeclimate.yml"
48
49
  - ".gitignore"
49
50
  - ".ruby-version"
50
51
  - ".travis.yml"
52
+ - CHANGELOG.md
51
53
  - CODE_OF_CONDUCT.md
52
54
  - Gemfile
53
55
  - LICENSE.txt
@@ -58,6 +60,7 @@ files:
58
60
  - downup.gemspec
59
61
  - examples/basic.rb
60
62
  - lib/downup.rb
63
+ - lib/downup/base.rb
61
64
  - lib/downup/colors.rb
62
65
  - lib/downup/options_printer.rb
63
66
  - lib/downup/version.rb
@@ -81,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
84
  version: '0'
82
85
  requirements: []
83
86
  rubyforge_project:
84
- rubygems_version: 2.2.2
87
+ rubygems_version: 2.4.5
85
88
  signing_key:
86
89
  specification_version: 4
87
90
  summary: a Gem for creating menus that you can easily navigate through