tty-prompt 0.18.1 → 0.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +95 -0
- data/README.md +598 -256
- data/lib/tty-prompt.rb +1 -2
- data/lib/tty/prompt.rb +192 -144
- data/lib/tty/prompt/answers_collector.rb +5 -5
- data/lib/tty/prompt/{enum_paginator.rb → block_paginator.rb} +20 -19
- data/lib/tty/prompt/choice.rb +9 -10
- data/lib/tty/prompt/choices.rb +30 -12
- data/lib/tty/prompt/confirm_question.rb +42 -16
- data/lib/tty/prompt/const.rb +17 -0
- data/lib/tty/prompt/converter_dsl.rb +6 -7
- data/lib/tty/prompt/converter_registry.rb +31 -26
- data/lib/tty/prompt/converters.rb +139 -32
- data/lib/tty/prompt/enum_list.rb +81 -26
- data/lib/tty/prompt/errors.rb +31 -0
- data/lib/tty/prompt/evaluator.rb +2 -2
- data/lib/tty/prompt/expander.rb +45 -15
- data/lib/tty/prompt/keypress.rb +33 -36
- data/lib/tty/prompt/list.rb +198 -63
- data/lib/tty/prompt/mask_question.rb +11 -8
- data/lib/tty/prompt/multi_list.rb +131 -28
- data/lib/tty/prompt/multiline.rb +9 -7
- data/lib/tty/prompt/paginator.rb +38 -26
- data/lib/tty/prompt/question.rb +92 -37
- data/lib/tty/prompt/question/checks.rb +20 -2
- data/lib/tty/prompt/question/modifier.rb +4 -2
- data/lib/tty/prompt/question/validation.rb +3 -3
- data/lib/tty/prompt/selected_choices.rb +77 -0
- data/lib/tty/prompt/slider.rb +125 -30
- data/lib/tty/prompt/statement.rb +3 -3
- data/lib/tty/prompt/suggestion.rb +7 -6
- data/lib/tty/prompt/symbols.rb +58 -34
- data/lib/tty/prompt/test.rb +36 -0
- data/lib/tty/prompt/timer.rb +75 -0
- data/lib/tty/prompt/utils.rb +1 -3
- data/lib/tty/prompt/version.rb +1 -1
- metadata +29 -227
- data/Rakefile +0 -8
- data/examples/ask.rb +0 -7
- data/examples/ask_valid.rb +0 -12
- data/examples/collect.rb +0 -21
- data/examples/echo.rb +0 -11
- data/examples/enum_select.rb +0 -7
- data/examples/enum_select_disabled.rb +0 -16
- data/examples/enum_select_paged.rb +0 -9
- data/examples/enum_select_wrapped.rb +0 -15
- data/examples/expand.rb +0 -29
- data/examples/in.rb +0 -9
- data/examples/inputs.rb +0 -10
- data/examples/key_events.rb +0 -15
- data/examples/keypress.rb +0 -9
- data/examples/mask.rb +0 -13
- data/examples/multi_select.rb +0 -8
- data/examples/multi_select_disabled.rb +0 -17
- data/examples/multi_select_paged.rb +0 -9
- data/examples/multi_select_wrapped.rb +0 -15
- data/examples/multiline.rb +0 -9
- data/examples/pause.rb +0 -9
- data/examples/select.rb +0 -24
- data/examples/select_disabled.rb +0 -18
- data/examples/select_enum.rb +0 -8
- data/examples/select_filtered.rb +0 -11
- data/examples/select_paginated.rb +0 -11
- data/examples/select_wrapped.rb +0 -15
- data/examples/slider.rb +0 -6
- data/examples/validation.rb +0 -9
- data/examples/yes_no.rb +0 -7
- data/lib/tty/prompt/messages.rb +0 -49
- data/lib/tty/prompt/timeout.rb +0 -78
- data/lib/tty/test_prompt.rb +0 -20
- data/spec/spec_helper.rb +0 -45
- data/spec/unit/ask_spec.rb +0 -132
- data/spec/unit/choice/eql_spec.rb +0 -22
- data/spec/unit/choice/from_spec.rb +0 -96
- data/spec/unit/choices/add_spec.rb +0 -12
- data/spec/unit/choices/each_spec.rb +0 -13
- data/spec/unit/choices/find_by_spec.rb +0 -10
- data/spec/unit/choices/new_spec.rb +0 -10
- data/spec/unit/choices/pluck_spec.rb +0 -9
- data/spec/unit/collect_spec.rb +0 -96
- data/spec/unit/converters/convert_bool_spec.rb +0 -58
- data/spec/unit/converters/convert_char_spec.rb +0 -11
- data/spec/unit/converters/convert_custom_spec.rb +0 -14
- data/spec/unit/converters/convert_date_spec.rb +0 -34
- data/spec/unit/converters/convert_file_spec.rb +0 -18
- data/spec/unit/converters/convert_number_spec.rb +0 -39
- data/spec/unit/converters/convert_path_spec.rb +0 -15
- data/spec/unit/converters/convert_range_spec.rb +0 -22
- data/spec/unit/converters/convert_regex_spec.rb +0 -12
- data/spec/unit/converters/convert_string_spec.rb +0 -21
- data/spec/unit/converters/on_error_spec.rb +0 -9
- data/spec/unit/distance/distance_spec.rb +0 -73
- data/spec/unit/enum_paginator_spec.rb +0 -75
- data/spec/unit/enum_select_spec.rb +0 -446
- data/spec/unit/error_spec.rb +0 -20
- data/spec/unit/evaluator_spec.rb +0 -67
- data/spec/unit/expand_spec.rb +0 -198
- data/spec/unit/keypress_spec.rb +0 -72
- data/spec/unit/mask_spec.rb +0 -132
- data/spec/unit/multi_select_spec.rb +0 -511
- data/spec/unit/multiline_spec.rb +0 -77
- data/spec/unit/new_spec.rb +0 -20
- data/spec/unit/ok_spec.rb +0 -10
- data/spec/unit/paginator_spec.rb +0 -73
- data/spec/unit/question/checks_spec.rb +0 -97
- data/spec/unit/question/default_spec.rb +0 -31
- data/spec/unit/question/echo_spec.rb +0 -38
- data/spec/unit/question/in_spec.rb +0 -115
- data/spec/unit/question/initialize_spec.rb +0 -12
- data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
- data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
- data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
- data/spec/unit/question/modify_spec.rb +0 -41
- data/spec/unit/question/required_spec.rb +0 -92
- data/spec/unit/question/validate_spec.rb +0 -115
- data/spec/unit/question/validation/call_spec.rb +0 -31
- data/spec/unit/question/validation/coerce_spec.rb +0 -30
- data/spec/unit/result_spec.rb +0 -40
- data/spec/unit/say_spec.rb +0 -67
- data/spec/unit/select_spec.rb +0 -660
- data/spec/unit/slider_spec.rb +0 -100
- data/spec/unit/statement/initialize_spec.rb +0 -15
- data/spec/unit/subscribe_spec.rb +0 -22
- data/spec/unit/suggest_spec.rb +0 -28
- data/spec/unit/warn_spec.rb +0 -21
- data/spec/unit/yes_no_spec.rb +0 -251
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-prompt.gemspec +0 -33
data/Rakefile
DELETED
data/examples/ask.rb
DELETED
data/examples/ask_valid.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
prompt.ask('Folder name?') do |q|
|
8
|
-
q.required(true)
|
9
|
-
q.validate ->(v) { return !Dir.exist?(v) }
|
10
|
-
q.messages[:valid?] = 'Folder already exists?'
|
11
|
-
q.messages[:required?] = 'Folder name must not be empty'
|
12
|
-
end
|
data/examples/collect.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
require_relative "../lib/tty-prompt"
|
6
|
-
|
7
|
-
prompt = TTY::Prompt.new(prefix: '[?] ')
|
8
|
-
|
9
|
-
result = prompt.collect do
|
10
|
-
key(:name).ask('Name?')
|
11
|
-
|
12
|
-
key(:age).ask('Age?', convert: :int)
|
13
|
-
|
14
|
-
key(:address) do
|
15
|
-
key(:street).ask('Street?', required: true)
|
16
|
-
key(:city).ask('City?')
|
17
|
-
key(:zip).ask('Zip?', validate: /\A\d{3}\Z/)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
puts JSON.pretty_generate(result)
|
data/examples/echo.rb
DELETED
data/examples/enum_select.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
choices = [
|
8
|
-
"Atom",
|
9
|
-
{name: "Emacs", disabled: '(not installed)'},
|
10
|
-
"GNU nano",
|
11
|
-
{name: "Notepad++", disabled: '(not installed)'},
|
12
|
-
"Sublime",
|
13
|
-
"Vim"
|
14
|
-
]
|
15
|
-
|
16
|
-
prompt.enum_select('Select an editor', choices)
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../lib/tty-prompt'
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
quotes = [
|
8
|
-
"There are certain queer times and occasions in this strange mixed affair we call life when a man takes this whole universe for a vast practical joke, though the wit thereof he but dimly discerns, and more than suspects that the joke is at nobody's expense but his own.",
|
9
|
-
"Talk not to me of blasphemy, man;\n I'd strike the sun if it insulted me.",
|
10
|
-
"There is a wisdom that is woe; but there is a woe that is madness. And there is a Catskill eagle in some souls that can alike dive down into the blackest gorges, and soar out of them again and become invisible in the sunny spaces. And even if he for ever flies within the gorge, that gorge is in the mountains; so that even in his lowest swoop the mountain eagle is still higher than other birds upon the plain, even though they soar."
|
11
|
-
]
|
12
|
-
|
13
|
-
answer = prompt.enum_select('Chose your quote?', quotes)
|
14
|
-
|
15
|
-
puts "Answer: #{answer}"
|
data/examples/expand.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
choices = [{
|
6
|
-
key: 'y',
|
7
|
-
name: 'overwrite this file',
|
8
|
-
value: :yes
|
9
|
-
}, {
|
10
|
-
key: 'n',
|
11
|
-
name: 'do not overwrite this file',
|
12
|
-
value: :no
|
13
|
-
}, {
|
14
|
-
key: 'a',
|
15
|
-
name: 'overwrite this file and all later files',
|
16
|
-
value: :all
|
17
|
-
}, {
|
18
|
-
key: 'd',
|
19
|
-
name: 'show diff',
|
20
|
-
value: :diff
|
21
|
-
}, {
|
22
|
-
key: 'q',
|
23
|
-
name: 'quit; do not overwrite this file ',
|
24
|
-
value: :quit
|
25
|
-
}]
|
26
|
-
|
27
|
-
prompt = TTY::Prompt.new
|
28
|
-
|
29
|
-
prompt.expand('Overwrite Gemfile?', choices, default: 3)
|
data/examples/in.rb
DELETED
data/examples/inputs.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
prompt.ask('What is your name?', default: ENV['USER'])
|
8
|
-
prompt.yes?('Do you like Ruby?')
|
9
|
-
prompt.mask("What is your secret?")
|
10
|
-
prompt.select("Choose your destiny?", %w(Scorpion Kano Jax))
|
data/examples/key_events.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt::new(interrupt: :exit)
|
6
|
-
|
7
|
-
prompt.on(:keypress) do |event|
|
8
|
-
puts "name: #{event.key.name}, value: #{event.value.dump}"
|
9
|
-
end
|
10
|
-
|
11
|
-
prompt.on(:keyescape) do |event|
|
12
|
-
exit
|
13
|
-
end
|
14
|
-
|
15
|
-
prompt.read_keypress
|
data/examples/keypress.rb
DELETED
data/examples/mask.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
require 'pastel'
|
5
|
-
|
6
|
-
prompt = TTY::Prompt.new
|
7
|
-
heart = prompt.decorate('❤ ', :magenta)
|
8
|
-
|
9
|
-
res = prompt.mask('What is your secret?', mask: heart) do |q|
|
10
|
-
q.validate(/[a-z\ ]{5,15}/)
|
11
|
-
end
|
12
|
-
|
13
|
-
puts "Secret: \"#{res}\""
|
data/examples/multi_select.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
drinks = [
|
8
|
-
'bourbon',
|
9
|
-
{name: 'sake', disabled: '(out of stock)'},
|
10
|
-
'vodka',
|
11
|
-
{name: 'beer', disabled: '(out of stock)'},
|
12
|
-
'wine',
|
13
|
-
'whisky'
|
14
|
-
]
|
15
|
-
answer = prompt.multi_select('Choose your favourite drink?', drinks)
|
16
|
-
|
17
|
-
puts answer.inspect
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../lib/tty-prompt'
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
quotes = [
|
8
|
-
"There are certain queer times and occasions in this strange mixed affair we call life when a man takes this whole universe for a vast practical joke, though the wit thereof he but dimly discerns, and more than suspects that the joke is at nobody's expense but his own.",
|
9
|
-
"Talk not to me of blasphemy, man; I'd strike the sun if it insulted me.",
|
10
|
-
"There is a wisdom that is woe; but there is a woe that is madness. And there is a Catskill eagle in some souls that can alike dive down into the blackest gorges, and soar out of them again and become invisible in the sunny spaces. And even if he for ever flies within the gorge, that gorge is in the mountains; so that even in his lowest swoop the mountain eagle is still higher than other birds upon the plain, even though they soar."
|
11
|
-
]
|
12
|
-
|
13
|
-
answer = prompt.multi_select('Choose your quote?', quotes, echo: false)
|
14
|
-
|
15
|
-
puts "Answer: #{answer}"
|
data/examples/multiline.rb
DELETED
data/examples/pause.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt::new
|
6
|
-
|
7
|
-
answer = prompt.keypress("Press space or enter to continue, continuing automatically in :countdown ...", keys: [:space, :return], timeout: 3)
|
8
|
-
|
9
|
-
puts "Answer: #{answer.inspect}"
|
data/examples/select.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
warriors = %i(Scorpion Kano Jax Kitana Raiden)
|
8
|
-
|
9
|
-
prompt.on(:keypress) do |event|
|
10
|
-
if event.value == 'j'
|
11
|
-
prompt.trigger(:keydown)
|
12
|
-
end
|
13
|
-
if event.value == 'k'
|
14
|
-
prompt.trigger(:keyup)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
prompt.on(:keyescape) do |event|
|
19
|
-
exit(1)
|
20
|
-
end
|
21
|
-
|
22
|
-
answer = prompt.select('Choose your destiny?', warriors)
|
23
|
-
|
24
|
-
puts answer.inspect
|
data/examples/select_disabled.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
warriors = [
|
8
|
-
'Scorpion',
|
9
|
-
'Kano',
|
10
|
-
{ name: 'Goro', disabled: '(injury)' },
|
11
|
-
'Jax',
|
12
|
-
'Kitana',
|
13
|
-
'Raiden'
|
14
|
-
]
|
15
|
-
|
16
|
-
answer = prompt.select('Choose your destiny?', warriors, enum: ')')
|
17
|
-
|
18
|
-
puts answer.inspect
|
data/examples/select_enum.rb
DELETED
data/examples/select_filtered.rb
DELETED
data/examples/select_wrapped.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../lib/tty-prompt'
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
quotes = [
|
8
|
-
"There are certain queer times and occasions in this strange mixed affair we call life when a man takes this whole universe for a vast practical joke, though the wit thereof he but dimly discerns, and more than suspects that the joke is at nobody's expense but his own.",
|
9
|
-
"Talk not to me of blasphemy, man;\n I'd strike the sun if it insulted me.",
|
10
|
-
"There is a wisdom that is woe; but there is a woe that is madness. And there is a Catskill eagle in some souls that can alike dive down into the blackest gorges, and soar out of them again and become invisible in the sunny spaces. And even if he for ever flies within the gorge, that gorge is in the mountains; so that even in his lowest swoop the mountain eagle is still higher than other birds upon the plain, even though they soar."
|
11
|
-
]
|
12
|
-
|
13
|
-
answer = prompt.select('Chose your quote?', quotes)
|
14
|
-
|
15
|
-
puts "Answer: #{answer}"
|
data/examples/slider.rb
DELETED
data/examples/validation.rb
DELETED
data/examples/yes_no.rb
DELETED
data/lib/tty/prompt/messages.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
module TTY
|
2
|
-
class Prompt
|
3
|
-
class Messages
|
4
|
-
|
5
|
-
def setup_messages
|
6
|
-
@messages = {
|
7
|
-
range?: 'Value %{value} must be within the range %{in}',
|
8
|
-
valid?: 'Your answer is invalid (must match %{valid})',
|
9
|
-
required?: 'Value must be provided'
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize
|
14
|
-
setup_messages
|
15
|
-
end
|
16
|
-
|
17
|
-
# Stores all the error messages displayed to user
|
18
|
-
# The currently supported messages are:
|
19
|
-
# * :range?
|
20
|
-
# * :required?
|
21
|
-
# * :valid?
|
22
|
-
attr_reader :messages
|
23
|
-
|
24
|
-
def get(key)
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
# Retrieve message based on the key
|
29
|
-
#
|
30
|
-
# @param [Symbol] name
|
31
|
-
# the name of message key
|
32
|
-
#
|
33
|
-
# @param [Hash] tokens
|
34
|
-
# the tokens to evaluate
|
35
|
-
#
|
36
|
-
# @return [Array[String]]
|
37
|
-
#
|
38
|
-
# @api private
|
39
|
-
def message_for(name, tokens = nil)
|
40
|
-
template = @messages[name]
|
41
|
-
if !template.match(/\%\{/).nil?
|
42
|
-
[template % tokens]
|
43
|
-
else
|
44
|
-
[template]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|