inquirer.rb 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,26 @@
1
1
  # encoding: utf-8
2
- require 'term/ansicolor'
2
+ require 'rainbow'
3
3
 
4
4
  module Inquirer
5
5
  class Style
6
6
 
7
- @@color = Term::ANSIColor
8
-
9
- @@question_prefix = @@color.green('?') + ' '
7
+ @@question_prefix = Rainbow('?').green + ' '
10
8
  @@seperator = '--------'
11
9
 
12
10
  @@question = '%s '
13
- @@response = @@color.cyan('%s')
11
+ @@response = Rainbow('%s').cyan
14
12
 
15
- @@selector = @@color.cyan('‣')
16
- @@checkbox_on = @@color.green('◉')
13
+ @@selector = Rainbow('‣').cyan
14
+ @@checkbox_on = Rainbow('◉').green
17
15
  @@checkbox_off = '◯'
18
16
 
19
17
  @@pagiator_text = '(Move up and down to reveal more choices)'
20
18
 
21
- @@error_message = @@color.red('>>') + ' %s'
19
+ @@error_message = Rainbow('>>').red + ' %s'
22
20
  @@error_message_invalid_value = 'The entered value is not valid'
23
21
 
24
- @@endless_repeat = @@color.yellow('#%s')
25
- @@limited_repeat = @@color.yellow('#%s of %s')
22
+ @@endless_repeat = Rainbow('#%s').yellow
23
+ @@limited_repeat = Rainbow('#%s of %s').yellow
26
24
 
27
25
  # http://blog.marc-seeger.de/2011/04/06/attr_reader-for-class-variables-in-ruby/
28
26
  def self.activate_getter_setter
@@ -0,0 +1,14 @@
1
+ require 'inquirer/utils/iochar'
2
+ require 'inquirer/style'
3
+
4
+ module Inquirer
5
+ class Style
6
+ class CheckboxFilterable < Inquirer::Style::Checkbox
7
+
8
+ @@filter = '%s'
9
+ @@filter_prefix = Rainbow('>').cyan + ' '
10
+
11
+ self.activate_getter_setter
12
+ end
13
+ end
14
+ end
@@ -6,7 +6,7 @@ module Inquirer
6
6
  class List < Inquirer::Style
7
7
 
8
8
  @@item = "%s#{IOChar.newline}"
9
- @@selected_item = @@color.cyan('%s') + IOChar.newline
9
+ @@selected_item = Rainbow('%s').cyan + IOChar.newline
10
10
 
11
11
  @@selection_help = '(Use arrow keys)'
12
12
 
@@ -0,0 +1,14 @@
1
+ require 'inquirer/utils/iochar'
2
+ require 'inquirer/style'
3
+
4
+ module Inquirer
5
+ class Style
6
+ class ListFilterable < Inquirer::Style::List
7
+
8
+ @@filter = '%s'
9
+ @@filter_prefix = Rainbow('>').cyan + ' '
10
+
11
+ self.activate_getter_setter
12
+ end
13
+ end
14
+ end
@@ -18,10 +18,14 @@ module IOChar
18
18
  "\004" => 'ctrl-d',
19
19
  }
20
20
 
21
- def char_to_key char
21
+ def char_to_key(char)
22
22
  KEYS.fetch char, char
23
23
  end
24
24
 
25
+ def key_to_char(key)
26
+ KEYS.invert.fetch key, key
27
+ end
28
+
25
29
  def newline; "\n" end
26
30
  def carriage_return; "\r" end
27
31
  def cursor_up; "\e[A" end
@@ -54,20 +54,11 @@ module IOHelper
54
54
  end
55
55
 
56
56
  # render a text to the prompt
57
- def render prompt, bottomline = nil
57
+ def render(prompt, bottomline = nil)
58
58
  @rendered = wrap(prompt)
59
59
  @bottomline = bottomline
60
60
 
61
- # determine how many lines to move up
62
- lines = @rendered.scan(/\n/).size + 1
63
-
64
- if @bottomline
65
- print IOChar.newline * lines + @bottomline + IOChar.cursor_left * @bottomline.size + IOChar.cursor_up * lines
66
- end
67
- print @rendered
68
-
69
- plain_last_line = plain_chars(@rendered.lines.last)
70
- print IOChar.newline + IOChar.cursor_up + IOChar.cursor_right * plain_last_line.length
61
+ print rendered_output
71
62
  end
72
63
 
73
64
  # clear the console based on the last text rendered
@@ -87,7 +78,7 @@ module IOHelper
87
78
  print IOChar.cursor_down + IOChar.carriage_return + IOChar.clear_line + IOChar.cursor_up + IOChar.clear_line + IOChar.carriage_return + ( IOChar.cursor_up + IOChar.clear_line ) * lines + IOChar.clear_line
88
79
  end
89
80
 
90
- # hides the cursor and ensure the curso be visible at the end
81
+ # hides the cursor and ensure the cursor be visible at the end
91
82
  def without_cursor
92
83
  # tell the terminal to hide the cursor
93
84
  print `tput civis`
@@ -131,4 +122,23 @@ module IOHelper
131
122
  def plain_chars(string)
132
123
  string.gsub(/\e\[([;\dA-Z]+)?m?/, '')
133
124
  end
125
+
126
+ private
127
+
128
+ def rendered_output
129
+
130
+ output = ''
131
+
132
+ if @bottomline
133
+ # determine how many lines to move up
134
+ lines = @rendered.scan(/\n/).size + 1
135
+ output += IOChar.newline * lines + @bottomline + IOChar.cursor_left * @bottomline.size + IOChar.cursor_up * lines
136
+ end
137
+ output += @rendered
138
+
139
+ plain_last_line = plain_chars(@rendered.lines.last)
140
+ output += IOChar.newline + IOChar.cursor_up + IOChar.cursor_right * plain_last_line.length
141
+
142
+ output
143
+ end
134
144
  end
@@ -1,3 +1,3 @@
1
1
  module Inquirer
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inquirer.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thorsten Eckel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-20 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '1.12'
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.11'
26
+ version: '1.12'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,61 +39,61 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: term-ansicolor
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
46
53
  - !ruby/object:Gem::Version
47
- version: '1.3'
48
- type: :runtime
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rainbow
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.3'
68
+ version: '2.1'
55
69
  description: A collection of common interactive command line user interfaces. A (not
56
- yet compleded) clone of the great Inquirer.js (https://github.com/SBoudrias/Inquirer.js)
70
+ yet completed) clone of the great Inquirer.js (https://github.com/SBoudrias/Inquirer.js)
57
71
  and strongly inspired by the similar inquirer.rb (https://github.com/arlimus/inquirer.rb).
58
- email:
59
- - te@znuny.com
72
+ email:
60
73
  executables: []
61
74
  extensions: []
62
75
  extra_rdoc_files: []
63
76
  files:
64
- - ".gitignore"
65
- - CODE_OF_CONDUCT.md
66
- - Gemfile
67
- - LICENSE.txt
68
- - README.md
69
- - Rakefile
70
- - examples/checkbox.rb
71
- - examples/confirm.rb
72
- - examples/input.rb
73
- - examples/list.rb
74
- - examples/password.rb
75
- - inquirer.gemspec
76
77
  - lib/inquirer.rb
77
78
  - lib/inquirer/prompts/checkbox.rb
79
+ - lib/inquirer/prompts/checkbox_filterable.rb
78
80
  - lib/inquirer/prompts/confirm.rb
79
81
  - lib/inquirer/prompts/input.rb
80
82
  - lib/inquirer/prompts/list.rb
83
+ - lib/inquirer/prompts/list_filterable.rb
81
84
  - lib/inquirer/prompts/password.rb
82
85
  - lib/inquirer/style.rb
83
86
  - lib/inquirer/style/checkbox.rb
87
+ - lib/inquirer/style/checkbox_filterable.rb
84
88
  - lib/inquirer/style/confirm.rb
85
89
  - lib/inquirer/style/input.rb
86
90
  - lib/inquirer/style/list.rb
91
+ - lib/inquirer/style/list_filterable.rb
87
92
  - lib/inquirer/style/password.rb
88
93
  - lib/inquirer/utils/iochar.rb
89
94
  - lib/inquirer/utils/iohelper.rb
90
95
  - lib/inquirer/utils/paginator.rb
91
96
  - lib/inquirer/version.rb
92
- - screenshots/checkbox.png
93
- - screenshots/confirm.png
94
- - screenshots/input.png
95
- - screenshots/list.png
96
- - screenshots/password.png
97
97
  homepage: https://github.com/thorsteneckel/inquirer
98
98
  licenses:
99
99
  - MIT
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
@@ -1,49 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, and in the interest of
4
- fostering an open and welcoming community, we pledge to respect all people who
5
- contribute through reporting issues, posting feature requests, updating
6
- documentation, submitting pull requests or patches, and other activities.
7
-
8
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
12
-
13
- Examples of unacceptable behavior by participants include:
14
-
15
- * The use of sexualized language or imagery
16
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
18
- * Public or private harassment
19
- * Publishing other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct
22
-
23
- Project maintainers have the right and responsibility to remove, edit, or
24
- reject comments, commits, code, wiki edits, issues, and other contributions
25
- that are not aligned to this Code of Conduct, or to ban temporarily or
26
- permanently any contributor for other behaviors that they deem inappropriate,
27
- threatening, offensive, or harmful.
28
-
29
- By adopting this Code of Conduct, project maintainers commit themselves to
30
- fairly and consistently applying these principles to every aspect of managing
31
- this project. Project maintainers who do not follow or enforce the Code of
32
- Conduct may be permanently removed from the project team.
33
-
34
- This code of conduct applies both within project spaces and in public spaces
35
- when an individual is representing the project or its community.
36
-
37
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
- reported by contacting a project maintainer at te@znuny.com. All
39
- complaints will be reviewed and investigated and will result in a response that
40
- is deemed necessary and appropriate to the circumstances. Maintainers are
41
- obligated to maintain confidentiality with regard to the reporter of an
42
- incident.
43
-
44
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
- version 1.3.0, available at
46
- [http://contributor-covenant.org/version/1/3/0/][version]
47
-
48
- [homepage]: http://contributor-covenant.org
49
- [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in inquirer.gemspec
4
- gemspec
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Thorsten Eckel
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,203 +0,0 @@
1
- # inquirer.rb
2
-
3
- A collection of common interactive command line user interfaces. A (not yet completed) clone of the great [Inquirer.js](https://github.com/SBoudrias/Inquirer.js) and strongly inspired by the similar [inquirer.rb](https://github.com/arlimus/inquirer.rb).
4
-
5
- Started as a fork of [inquirer.rb](https://github.com/arlimus/inquirer.rb) the changes become to fundamental to keep it that way.
6
-
7
- ## Goals
8
-
9
- - [Inquirer.js](https://github.com/SBoudrias/Inquirer.js) API conform as possible
10
- - Extended functionality API similar as possible
11
- - Slim dependencies
12
- - Easy integration
13
-
14
- ## Installation
15
-
16
- Add this line to your application's Gemfile:
17
-
18
- ```ruby
19
- gem 'inquirer.rb'
20
- ```
21
-
22
- And then execute:
23
-
24
- $ bundle
25
-
26
- Or install it yourself as:
27
-
28
- $ gem install inquirer.rb
29
-
30
- ## Usage
31
-
32
- ```ruby
33
- require 'inquirer'
34
-
35
- questions = [
36
- {
37
- name: :user_name,
38
- type: :input, # optional - default ':input', others see below
39
- message: 'What is your name?',
40
- }
41
- ]
42
-
43
- answers = Inquirer.prompt(questions)
44
-
45
- p answers[:user_name]
46
-
47
- # => Tyler
48
- ```
49
-
50
- See the `examples` folder for more examples.
51
-
52
- Basically it's:
53
- - `Inquirer.prompt` takes an Array as parameter, containing question Hashes
54
- - Each question Hash has to contain the parameters required for the given `:type` parameter
55
- - If no `:type` paramter is given `:input` is used as default
56
- - `Inquirer.prompt` returns a Hash with the question `:name` parameter as key and the user input as value
57
-
58
- ### Prompt types
59
-
60
- There parameters are valid for all prompt types:
61
-
62
- - `:message` (String) The question to print.
63
- - `:filter` (Proc) (optional) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the answers Hash.
64
- - `:when` (Proc|Boolean) (optional) Receive the current user answers Hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
65
-
66
- #### Input (`type: :input`)
67
-
68
- ![:input](screenshots/input.png ":input")
69
-
70
- - `:default` (String) (optional) Default value to use if nothing is entered.
71
- - `:validate` (Proc) (optional) Receive the user input and should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
72
-
73
- #### Password (`type: :password`)
74
-
75
- ![:password](screenshots/password.png ":password")
76
-
77
- - `:default` (String) (optional) Default value to use if nothing is entered.
78
- - `:validate` (Proc) (optional) Receive the user input and should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
79
-
80
- #### List (`type: :list`)
81
-
82
- ![:list](screenshots/list.png ":list")
83
-
84
- - `:choices` (Array) Has to contain Hashes with the following parameters:
85
- - `:name` (String) The display value
86
- - `:short` (String) (optional) To display after selection
87
- - `:value` (String|Symbol) To save in the answers Hash
88
- - `:when` (Proc|Boolean) (optional) Should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
89
- - `:default` (Integer|String|Symbol) (optional) Must be the choice index (Integer) in the Array or a choice `:value` parameters value (String|Symbol).
90
-
91
- #### Checkbox (`type: :checkbox`)
92
-
93
- ![:checkbox](screenshots/checkbox.png ":checkbox")
94
-
95
- - `:choices` (Array) Has to contain Hashes with the following parameters:
96
- - `:name` (String) The display value
97
- - `:short` (String) (optional) To display after selection
98
- - `:value` (String|Symbol) To save in the answers Hash
99
- - `:checked` (Boolean) (optional) True choices will be checked by default
100
- - `:when` (Proc|Boolean) (optional) Should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
101
- - `:default` (Array) (optional) An Array of choices `:value` parameters values (String|Symbol).
102
- - `:validate` (Proc) (optional) Receive the user input and should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
103
-
104
- #### Confirm (`type: :confirm`)
105
-
106
- ![:confirm](screenshots/confirm.png ":confirm")
107
-
108
- - `:default` (Boolean) (optional) Default value to use if nothing is entered is expected to be a boolean.
109
-
110
- ## Development
111
-
112
- ### General
113
-
114
- - [x] `:type` parameter (InquirerJS conform)
115
- - [x] no `:type` parameter provided results in `:input` (InquirerJS conform)
116
- - [x] `:name` parameter (InquirerJS conform)
117
- - [x] `:message` (String) parameter (InquirerJS conform)
118
- - [ ] `:message` (Proc) parameter (InquirerJS conform)
119
- - [x] `:default` (String) parameter (optional) (InquirerJS conform)
120
- - [ ] `:default` (Proc) parameter (optional) (InquirerJS conform)
121
- - [x] `:when` (Proc) parameter (optional) (InquirerJS conform)
122
- - [x] `:when` (Boolean) parameter (optional) (InquirerJS conform)
123
- - [x] `:filter` (Proc) parameter (optional)
124
- - [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
125
- - [x] colored formatting (InquirerJS conform)
126
- - [x] easy styling / formatting of all output components (question, result, items, password....)
127
-
128
- ### Input
129
-
130
- - [x] Backend
131
- - [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
132
- - [ ] Tests
133
-
134
- ### Password
135
-
136
- - [x] Backend
137
- - [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
138
- - [ ] Tests
139
-
140
- ### List
141
-
142
- - [x] Backend
143
- - [x] `:choices` (Array) parameter (InquirerJS conform)
144
- - [ ] `:choices` (Proc) parameter (InquirerJS conform)
145
- - [x] `:choices` `:name` parameter (InquirerJS conform)
146
- - [x] `:choices` `:value` parameter (InquirerJS conform)
147
- - [x] `:choices` `:short` parameter (InquirerJS conform)
148
- - [x] `:choices` `:when` (Proc) parameter
149
- - [x] `:choices` `:when` (Boolean) parameter
150
- - [x] `:validate` (Proc) parameter (optional) (InquirerJS conform)
151
- - [ ] Tests
152
-
153
- ### Checkbox
154
-
155
- - [x] Backend
156
- - [x] `:choices` (Array) parameter (InquirerJS conform)
157
- - [ ] `:choices` (Proc) parameter (InquirerJS conform)
158
- - [x] `:choices` `:name` parameter (InquirerJS conform)
159
- - [x] `:choices` `:value` parameter (InquirerJS conform)
160
- - [x] `:choices` `:checked` parameter (InquirerJS conform)
161
- - [x] `:choices` `:when` (Proc) parameter
162
- - [x] `:choices` `:when` (Boolean) parameter
163
- - [ ] `:choices` `:disabled` (String) parameter (InquirerJS conform)
164
- - [ ] `:choices` `:disabled` (Boolean) parameter (InquirerJS conform)
165
- - [ ] `:choices` `:disabled` (Proc) parameter (InquirerJS conform)
166
- - [x] `:choices` `:short` parameter
167
- - [ ] Tests
168
-
169
- ### Confirm
170
-
171
- - [x] Backend
172
- - [ ] Tests
173
-
174
- ### Raw List
175
-
176
- - [ ] Backend
177
- - [ ] `:choices` parameter (InquirerJS conform)
178
- - [ ] Tests
179
-
180
- ### Expand
181
-
182
- - [ ] Backend
183
- - [ ] `:choices` parameter (InquirerJS conform)
184
- - [ ] Tests
185
-
186
- ### Seperator
187
-
188
- - [ ] constructor takes a facultative String value that'll be use as the separator (InquirerJS conform)
189
- - [ ] default separator `--------` (InquirerJS conform)
190
- - [ ] Tests
191
-
192
- ### BottomBar
193
-
194
- - [ ] fixed text at the bottom of a free text zone (InquirerJS conform)
195
- - [ ] Tests
196
-
197
- ## Contributing
198
-
199
- Bug reports and pull requests are welcome on GitHub at https://github.com/thorsteneckel/inquirer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
200
-
201
- ## License
202
-
203
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).