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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +95 -0
  3. data/README.md +598 -256
  4. data/lib/tty-prompt.rb +1 -2
  5. data/lib/tty/prompt.rb +192 -144
  6. data/lib/tty/prompt/answers_collector.rb +5 -5
  7. data/lib/tty/prompt/{enum_paginator.rb → block_paginator.rb} +20 -19
  8. data/lib/tty/prompt/choice.rb +9 -10
  9. data/lib/tty/prompt/choices.rb +30 -12
  10. data/lib/tty/prompt/confirm_question.rb +42 -16
  11. data/lib/tty/prompt/const.rb +17 -0
  12. data/lib/tty/prompt/converter_dsl.rb +6 -7
  13. data/lib/tty/prompt/converter_registry.rb +31 -26
  14. data/lib/tty/prompt/converters.rb +139 -32
  15. data/lib/tty/prompt/enum_list.rb +81 -26
  16. data/lib/tty/prompt/errors.rb +31 -0
  17. data/lib/tty/prompt/evaluator.rb +2 -2
  18. data/lib/tty/prompt/expander.rb +45 -15
  19. data/lib/tty/prompt/keypress.rb +33 -36
  20. data/lib/tty/prompt/list.rb +198 -63
  21. data/lib/tty/prompt/mask_question.rb +11 -8
  22. data/lib/tty/prompt/multi_list.rb +131 -28
  23. data/lib/tty/prompt/multiline.rb +9 -7
  24. data/lib/tty/prompt/paginator.rb +38 -26
  25. data/lib/tty/prompt/question.rb +92 -37
  26. data/lib/tty/prompt/question/checks.rb +20 -2
  27. data/lib/tty/prompt/question/modifier.rb +4 -2
  28. data/lib/tty/prompt/question/validation.rb +3 -3
  29. data/lib/tty/prompt/selected_choices.rb +77 -0
  30. data/lib/tty/prompt/slider.rb +125 -30
  31. data/lib/tty/prompt/statement.rb +3 -3
  32. data/lib/tty/prompt/suggestion.rb +7 -6
  33. data/lib/tty/prompt/symbols.rb +58 -34
  34. data/lib/tty/prompt/test.rb +36 -0
  35. data/lib/tty/prompt/timer.rb +75 -0
  36. data/lib/tty/prompt/utils.rb +1 -3
  37. data/lib/tty/prompt/version.rb +1 -1
  38. metadata +29 -227
  39. data/Rakefile +0 -8
  40. data/examples/ask.rb +0 -7
  41. data/examples/ask_valid.rb +0 -12
  42. data/examples/collect.rb +0 -21
  43. data/examples/echo.rb +0 -11
  44. data/examples/enum_select.rb +0 -7
  45. data/examples/enum_select_disabled.rb +0 -16
  46. data/examples/enum_select_paged.rb +0 -9
  47. data/examples/enum_select_wrapped.rb +0 -15
  48. data/examples/expand.rb +0 -29
  49. data/examples/in.rb +0 -9
  50. data/examples/inputs.rb +0 -10
  51. data/examples/key_events.rb +0 -15
  52. data/examples/keypress.rb +0 -9
  53. data/examples/mask.rb +0 -13
  54. data/examples/multi_select.rb +0 -8
  55. data/examples/multi_select_disabled.rb +0 -17
  56. data/examples/multi_select_paged.rb +0 -9
  57. data/examples/multi_select_wrapped.rb +0 -15
  58. data/examples/multiline.rb +0 -9
  59. data/examples/pause.rb +0 -9
  60. data/examples/select.rb +0 -24
  61. data/examples/select_disabled.rb +0 -18
  62. data/examples/select_enum.rb +0 -8
  63. data/examples/select_filtered.rb +0 -11
  64. data/examples/select_paginated.rb +0 -11
  65. data/examples/select_wrapped.rb +0 -15
  66. data/examples/slider.rb +0 -6
  67. data/examples/validation.rb +0 -9
  68. data/examples/yes_no.rb +0 -7
  69. data/lib/tty/prompt/messages.rb +0 -49
  70. data/lib/tty/prompt/timeout.rb +0 -78
  71. data/lib/tty/test_prompt.rb +0 -20
  72. data/spec/spec_helper.rb +0 -45
  73. data/spec/unit/ask_spec.rb +0 -132
  74. data/spec/unit/choice/eql_spec.rb +0 -22
  75. data/spec/unit/choice/from_spec.rb +0 -96
  76. data/spec/unit/choices/add_spec.rb +0 -12
  77. data/spec/unit/choices/each_spec.rb +0 -13
  78. data/spec/unit/choices/find_by_spec.rb +0 -10
  79. data/spec/unit/choices/new_spec.rb +0 -10
  80. data/spec/unit/choices/pluck_spec.rb +0 -9
  81. data/spec/unit/collect_spec.rb +0 -96
  82. data/spec/unit/converters/convert_bool_spec.rb +0 -58
  83. data/spec/unit/converters/convert_char_spec.rb +0 -11
  84. data/spec/unit/converters/convert_custom_spec.rb +0 -14
  85. data/spec/unit/converters/convert_date_spec.rb +0 -34
  86. data/spec/unit/converters/convert_file_spec.rb +0 -18
  87. data/spec/unit/converters/convert_number_spec.rb +0 -39
  88. data/spec/unit/converters/convert_path_spec.rb +0 -15
  89. data/spec/unit/converters/convert_range_spec.rb +0 -22
  90. data/spec/unit/converters/convert_regex_spec.rb +0 -12
  91. data/spec/unit/converters/convert_string_spec.rb +0 -21
  92. data/spec/unit/converters/on_error_spec.rb +0 -9
  93. data/spec/unit/distance/distance_spec.rb +0 -73
  94. data/spec/unit/enum_paginator_spec.rb +0 -75
  95. data/spec/unit/enum_select_spec.rb +0 -446
  96. data/spec/unit/error_spec.rb +0 -20
  97. data/spec/unit/evaluator_spec.rb +0 -67
  98. data/spec/unit/expand_spec.rb +0 -198
  99. data/spec/unit/keypress_spec.rb +0 -72
  100. data/spec/unit/mask_spec.rb +0 -132
  101. data/spec/unit/multi_select_spec.rb +0 -511
  102. data/spec/unit/multiline_spec.rb +0 -77
  103. data/spec/unit/new_spec.rb +0 -20
  104. data/spec/unit/ok_spec.rb +0 -10
  105. data/spec/unit/paginator_spec.rb +0 -73
  106. data/spec/unit/question/checks_spec.rb +0 -97
  107. data/spec/unit/question/default_spec.rb +0 -31
  108. data/spec/unit/question/echo_spec.rb +0 -38
  109. data/spec/unit/question/in_spec.rb +0 -115
  110. data/spec/unit/question/initialize_spec.rb +0 -12
  111. data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
  112. data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
  113. data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
  114. data/spec/unit/question/modify_spec.rb +0 -41
  115. data/spec/unit/question/required_spec.rb +0 -92
  116. data/spec/unit/question/validate_spec.rb +0 -115
  117. data/spec/unit/question/validation/call_spec.rb +0 -31
  118. data/spec/unit/question/validation/coerce_spec.rb +0 -30
  119. data/spec/unit/result_spec.rb +0 -40
  120. data/spec/unit/say_spec.rb +0 -67
  121. data/spec/unit/select_spec.rb +0 -660
  122. data/spec/unit/slider_spec.rb +0 -100
  123. data/spec/unit/statement/initialize_spec.rb +0 -15
  124. data/spec/unit/subscribe_spec.rb +0 -22
  125. data/spec/unit/suggest_spec.rb +0 -28
  126. data/spec/unit/warn_spec.rb +0 -21
  127. data/spec/unit/yes_no_spec.rb +0 -251
  128. data/tasks/console.rake +0 -11
  129. data/tasks/coverage.rake +0 -11
  130. data/tasks/spec.rake +0 -29
  131. data/tty-prompt.gemspec +0 -33
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "bundler/gem_tasks"
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- desc 'Run all specs'
8
- task ci: %w[ spec ]
@@ -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,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
@@ -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)
@@ -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
- "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,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)
@@ -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}"
@@ -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,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
@@ -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
@@ -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}"
@@ -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}\""
@@ -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, help: '(Use arrow keys and Enter to finish)')
@@ -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,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: 5)
@@ -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}"
@@ -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}"
@@ -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,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: ')')
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
-
7
- warriors = %w(Scorpion Kano Jax Kitana Raiden)
8
-
9
- answer = prompt.select('Choose your destiny?', warriors, filter: true)
10
-
11
- puts answer.inspect
@@ -1,11 +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
- answer = prompt.select('Which letter?', alfabet, per_page: 8)
10
-
11
- 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;\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}"
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-prompt"
4
-
5
- prompt = TTY::Prompt.new
6
- prompt.slider("Volume", max: 100, step: 5, default: 75, format: "|:slider| %d%%")
@@ -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('What is your username?') do |q|
8
- q.validate(/^[^\.]+\.[^\.]+/)
9
- end
@@ -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.yes?('Do you like Ruby?')
@@ -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