tty-prompt 0.20.0 → 0.21.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 +11 -0
- data/README.md +29 -4
- data/lib/tty/prompt.rb +3 -3
- data/lib/tty/prompt/multi_list.rb +33 -10
- data/lib/tty/prompt/version.rb +1 -1
- metadata +11 -175
- data/Rakefile +0 -8
- data/examples/ask.rb +0 -7
- data/examples/ask_blank.rb +0 -9
- data/examples/ask_multiline.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/expand_auto.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_disabled_paged.rb +0 -22
- 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_disabled_paged.rb +0 -22
- 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/spec/spec_helper.rb +0 -61
- data/spec/unit/ask_spec.rb +0 -173
- data/spec/unit/block_paginator_spec.rb +0 -84
- data/spec/unit/choice/eql_spec.rb +0 -22
- data/spec/unit/choice/from_spec.rb +0 -130
- 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_select_spec.rb +0 -518
- data/spec/unit/error_spec.rb +0 -20
- data/spec/unit/evaluator_spec.rb +0 -67
- data/spec/unit/expand_spec.rb +0 -290
- data/spec/unit/keypress_spec.rb +0 -66
- data/spec/unit/mask_spec.rb +0 -140
- data/spec/unit/multi_select_spec.rb +0 -741
- 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 -92
- 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 -942
- data/spec/unit/slider_spec.rb +0 -142
- 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/timer_spec.rb +0 -29
- data/spec/unit/warn_spec.rb +0 -21
- data/spec/unit/yes_no_spec.rb +0 -285
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-prompt.gemspec +0 -40
data/examples/ask.rb
DELETED
data/examples/ask_blank.rb
DELETED
data/examples/ask_multiline.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
|
-
{name: "Emacs", disabled: '(not installed)'},
|
9
|
-
"Atom",
|
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/expand_auto.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, auto_hint: true)
|
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(prompt.symbols[:heart] + ' ', :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,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
numbers = [
|
8
|
-
{name: '1', disabled: 'out'},
|
9
|
-
'2',
|
10
|
-
{name: '3', disabled: 'out'},
|
11
|
-
'4',
|
12
|
-
'5',
|
13
|
-
{name: '6', disabled: 'out'},
|
14
|
-
'7',
|
15
|
-
'8',
|
16
|
-
'9',
|
17
|
-
{name: '10', disabled: 'out'}
|
18
|
-
]
|
19
|
-
|
20
|
-
answer = prompt.multi_select('Which letter?', numbers, per_page: 4, cycle: true)
|
21
|
-
|
22
|
-
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
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../lib/tty-prompt"
|
4
|
-
|
5
|
-
prompt = TTY::Prompt.new
|
6
|
-
|
7
|
-
numbers = [
|
8
|
-
{name: '1', disabled: 'out'},
|
9
|
-
'2',
|
10
|
-
{name: '3', disabled: 'out'},
|
11
|
-
'4',
|
12
|
-
'5',
|
13
|
-
{name: '6', disabled: 'out'},
|
14
|
-
'7',
|
15
|
-
'8',
|
16
|
-
'9',
|
17
|
-
{name: '10', disabled: 'out'}
|
18
|
-
]
|
19
|
-
|
20
|
-
answer = prompt.select('Which letter?', numbers, per_page: 4, cycle: true)
|
21
|
-
|
22
|
-
puts answer.inspect
|
data/examples/select_enum.rb
DELETED
data/examples/select_filtered.rb
DELETED