tty-prompt 0.19.0 → 0.23.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +81 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +485 -233
  5. data/lib/tty-prompt.rb +1 -2
  6. data/lib/tty/prompt.rb +159 -147
  7. data/lib/tty/prompt/answers_collector.rb +5 -5
  8. data/lib/tty/prompt/block_paginator.rb +1 -1
  9. data/lib/tty/prompt/choice.rb +31 -13
  10. data/lib/tty/prompt/choices.rb +30 -12
  11. data/lib/tty/prompt/confirm_question.rb +42 -16
  12. data/lib/tty/prompt/const.rb +17 -0
  13. data/lib/tty/prompt/converter_dsl.rb +6 -7
  14. data/lib/tty/prompt/converter_registry.rb +31 -26
  15. data/lib/tty/prompt/converters.rb +139 -32
  16. data/lib/tty/prompt/enum_list.rb +58 -25
  17. data/lib/tty/prompt/errors.rb +31 -0
  18. data/lib/tty/prompt/evaluator.rb +2 -2
  19. data/lib/tty/prompt/expander.rb +27 -15
  20. data/lib/tty/prompt/keypress.rb +5 -3
  21. data/lib/tty/prompt/list.rb +101 -38
  22. data/lib/tty/prompt/mask_question.rb +9 -5
  23. data/lib/tty/prompt/multi_list.rb +108 -29
  24. data/lib/tty/prompt/multiline.rb +9 -7
  25. data/lib/tty/prompt/paginator.rb +1 -1
  26. data/lib/tty/prompt/question.rb +67 -36
  27. data/lib/tty/prompt/question/checks.rb +20 -2
  28. data/lib/tty/prompt/question/modifier.rb +4 -2
  29. data/lib/tty/prompt/question/validation.rb +3 -3
  30. data/lib/tty/prompt/selected_choices.rb +77 -0
  31. data/lib/tty/prompt/slider.rb +110 -23
  32. data/lib/tty/prompt/statement.rb +3 -3
  33. data/lib/tty/prompt/suggestion.rb +7 -6
  34. data/lib/tty/prompt/symbols.rb +58 -58
  35. data/lib/tty/prompt/test.rb +36 -0
  36. data/lib/tty/prompt/utils.rb +1 -3
  37. data/lib/tty/prompt/version.rb +1 -1
  38. metadata +27 -196
  39. data/Rakefile +0 -8
  40. data/examples/ask.rb +0 -7
  41. data/examples/ask_blank.rb +0 -9
  42. data/examples/ask_valid.rb +0 -12
  43. data/examples/collect.rb +0 -21
  44. data/examples/echo.rb +0 -11
  45. data/examples/enum_select.rb +0 -7
  46. data/examples/enum_select_disabled.rb +0 -16
  47. data/examples/enum_select_paged.rb +0 -9
  48. data/examples/enum_select_wrapped.rb +0 -15
  49. data/examples/expand.rb +0 -29
  50. data/examples/expand_auto.rb +0 -29
  51. data/examples/in.rb +0 -9
  52. data/examples/inputs.rb +0 -10
  53. data/examples/key_events.rb +0 -15
  54. data/examples/keypress.rb +0 -9
  55. data/examples/mask.rb +0 -13
  56. data/examples/multi_select.rb +0 -8
  57. data/examples/multi_select_disabled.rb +0 -17
  58. data/examples/multi_select_disabled_paged.rb +0 -22
  59. data/examples/multi_select_paged.rb +0 -9
  60. data/examples/multi_select_wrapped.rb +0 -15
  61. data/examples/multiline.rb +0 -9
  62. data/examples/pause.rb +0 -9
  63. data/examples/select.rb +0 -24
  64. data/examples/select_disabled.rb +0 -18
  65. data/examples/select_disabled_paged.rb +0 -22
  66. data/examples/select_enum.rb +0 -8
  67. data/examples/select_filtered.rb +0 -11
  68. data/examples/select_paginated.rb +0 -11
  69. data/examples/select_wrapped.rb +0 -15
  70. data/examples/slider.rb +0 -6
  71. data/examples/validation.rb +0 -9
  72. data/examples/yes_no.rb +0 -7
  73. data/lib/tty/prompt/messages.rb +0 -49
  74. data/lib/tty/test_prompt.rb +0 -20
  75. data/spec/spec_helper.rb +0 -61
  76. data/spec/unit/ask_spec.rb +0 -173
  77. data/spec/unit/block_paginator_spec.rb +0 -84
  78. data/spec/unit/choice/eql_spec.rb +0 -22
  79. data/spec/unit/choice/from_spec.rb +0 -112
  80. data/spec/unit/choices/add_spec.rb +0 -12
  81. data/spec/unit/choices/each_spec.rb +0 -13
  82. data/spec/unit/choices/find_by_spec.rb +0 -10
  83. data/spec/unit/choices/new_spec.rb +0 -10
  84. data/spec/unit/choices/pluck_spec.rb +0 -9
  85. data/spec/unit/collect_spec.rb +0 -96
  86. data/spec/unit/converters/convert_bool_spec.rb +0 -58
  87. data/spec/unit/converters/convert_char_spec.rb +0 -11
  88. data/spec/unit/converters/convert_custom_spec.rb +0 -14
  89. data/spec/unit/converters/convert_date_spec.rb +0 -34
  90. data/spec/unit/converters/convert_file_spec.rb +0 -18
  91. data/spec/unit/converters/convert_number_spec.rb +0 -39
  92. data/spec/unit/converters/convert_path_spec.rb +0 -15
  93. data/spec/unit/converters/convert_range_spec.rb +0 -22
  94. data/spec/unit/converters/convert_regex_spec.rb +0 -12
  95. data/spec/unit/converters/convert_string_spec.rb +0 -21
  96. data/spec/unit/converters/on_error_spec.rb +0 -9
  97. data/spec/unit/distance/distance_spec.rb +0 -73
  98. data/spec/unit/enum_select_spec.rb +0 -518
  99. data/spec/unit/error_spec.rb +0 -20
  100. data/spec/unit/evaluator_spec.rb +0 -67
  101. data/spec/unit/expand_spec.rb +0 -290
  102. data/spec/unit/keypress_spec.rb +0 -66
  103. data/spec/unit/mask_spec.rb +0 -140
  104. data/spec/unit/multi_select_spec.rb +0 -741
  105. data/spec/unit/multiline_spec.rb +0 -77
  106. data/spec/unit/new_spec.rb +0 -20
  107. data/spec/unit/ok_spec.rb +0 -10
  108. data/spec/unit/paginator_spec.rb +0 -92
  109. data/spec/unit/question/checks_spec.rb +0 -97
  110. data/spec/unit/question/default_spec.rb +0 -31
  111. data/spec/unit/question/echo_spec.rb +0 -38
  112. data/spec/unit/question/in_spec.rb +0 -115
  113. data/spec/unit/question/initialize_spec.rb +0 -12
  114. data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
  115. data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
  116. data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
  117. data/spec/unit/question/modify_spec.rb +0 -41
  118. data/spec/unit/question/required_spec.rb +0 -92
  119. data/spec/unit/question/validate_spec.rb +0 -115
  120. data/spec/unit/question/validation/call_spec.rb +0 -31
  121. data/spec/unit/question/validation/coerce_spec.rb +0 -30
  122. data/spec/unit/result_spec.rb +0 -40
  123. data/spec/unit/say_spec.rb +0 -67
  124. data/spec/unit/select_spec.rb +0 -942
  125. data/spec/unit/slider_spec.rb +0 -142
  126. data/spec/unit/statement/initialize_spec.rb +0 -15
  127. data/spec/unit/subscribe_spec.rb +0 -22
  128. data/spec/unit/suggest_spec.rb +0 -28
  129. data/spec/unit/timer_spec.rb +0 -29
  130. data/spec/unit/warn_spec.rb +0 -21
  131. data/spec/unit/yes_no_spec.rb +0 -251
  132. data/tasks/console.rake +0 -11
  133. data/tasks/coverage.rake +0 -11
  134. data/tasks/spec.rake +0 -29
  135. data/tty-prompt.gemspec +0 -31
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- FileList['tasks/**/*.rake'].each(&method(:import))
4
-
5
- desc 'Run all specs'
6
- task ci: %w[ spec ]
7
-
8
- task default: :spec
data/examples/ask.rb DELETED
@@ -1,7 +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'])
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new(prefix: ">")
6
-
7
- answer= prompt.ask
8
-
9
- puts "Answer: \"#{answer}\""
@@ -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
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- answer = prompt.ask('Password?', echo: false) do |q|
8
- q.validate(/^[^\.]+\.[^\.]+/)
9
- end
10
-
11
- puts "Password: #{answer}"
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
- choices = %i(/bin/nano /usr/bin/vim.basic /usr/bin/vim.tiny)
7
- prompt.enum_select('Select an editor', choices, default: 2)
@@ -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,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- alfabet = ('A'..'Z').to_a
8
-
9
- prompt.enum_select('Which letter?', alfabet, per_page: 4, cycle: true, default: 2)
@@ -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)
@@ -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
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- prompt.ask('How do you like it on scale 1 - 10?', in: '1-10') do |q|
8
- q.messages[:range?] = "Sorry wrong one!"
9
- end
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))
@@ -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
@@ -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 any key to continue")
8
-
9
- puts "Answer: #{answer.inspect}"
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}\""
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- drinks = %w(vodka beer wine whisky bourbon)
8
- prompt.multi_select('Choose your favourite drink?', drinks)
@@ -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,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- alfabet = ('A'..'Z').to_a
8
-
9
- prompt.multi_select('Which letter?', alfabet, per_page: 7, max: 3)
@@ -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}"
@@ -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.multiline("Description:")
8
-
9
- puts "Answer: #{answer.inspect}"
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
@@ -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
@@ -1,8 +0,0 @@
1
- # frozen_string_litreal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- warriors = %w(Scorpion Kano Jax)
8
- prompt.select('Choose your destiny?', warriors, enum: ')')