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.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/README.md +29 -4
  4. data/lib/tty/prompt.rb +3 -3
  5. data/lib/tty/prompt/multi_list.rb +33 -10
  6. data/lib/tty/prompt/version.rb +1 -1
  7. metadata +11 -175
  8. data/Rakefile +0 -8
  9. data/examples/ask.rb +0 -7
  10. data/examples/ask_blank.rb +0 -9
  11. data/examples/ask_multiline.rb +0 -7
  12. data/examples/ask_valid.rb +0 -12
  13. data/examples/collect.rb +0 -21
  14. data/examples/echo.rb +0 -11
  15. data/examples/enum_select.rb +0 -7
  16. data/examples/enum_select_disabled.rb +0 -16
  17. data/examples/enum_select_paged.rb +0 -9
  18. data/examples/enum_select_wrapped.rb +0 -15
  19. data/examples/expand.rb +0 -29
  20. data/examples/expand_auto.rb +0 -29
  21. data/examples/in.rb +0 -9
  22. data/examples/inputs.rb +0 -10
  23. data/examples/key_events.rb +0 -15
  24. data/examples/keypress.rb +0 -9
  25. data/examples/mask.rb +0 -13
  26. data/examples/multi_select.rb +0 -8
  27. data/examples/multi_select_disabled.rb +0 -17
  28. data/examples/multi_select_disabled_paged.rb +0 -22
  29. data/examples/multi_select_paged.rb +0 -9
  30. data/examples/multi_select_wrapped.rb +0 -15
  31. data/examples/multiline.rb +0 -9
  32. data/examples/pause.rb +0 -9
  33. data/examples/select.rb +0 -24
  34. data/examples/select_disabled.rb +0 -18
  35. data/examples/select_disabled_paged.rb +0 -22
  36. data/examples/select_enum.rb +0 -8
  37. data/examples/select_filtered.rb +0 -11
  38. data/examples/select_paginated.rb +0 -11
  39. data/examples/select_wrapped.rb +0 -15
  40. data/examples/slider.rb +0 -6
  41. data/examples/validation.rb +0 -9
  42. data/examples/yes_no.rb +0 -7
  43. data/spec/spec_helper.rb +0 -61
  44. data/spec/unit/ask_spec.rb +0 -173
  45. data/spec/unit/block_paginator_spec.rb +0 -84
  46. data/spec/unit/choice/eql_spec.rb +0 -22
  47. data/spec/unit/choice/from_spec.rb +0 -130
  48. data/spec/unit/choices/add_spec.rb +0 -12
  49. data/spec/unit/choices/each_spec.rb +0 -13
  50. data/spec/unit/choices/find_by_spec.rb +0 -10
  51. data/spec/unit/choices/new_spec.rb +0 -10
  52. data/spec/unit/choices/pluck_spec.rb +0 -9
  53. data/spec/unit/collect_spec.rb +0 -96
  54. data/spec/unit/converters/convert_bool_spec.rb +0 -58
  55. data/spec/unit/converters/convert_char_spec.rb +0 -11
  56. data/spec/unit/converters/convert_custom_spec.rb +0 -14
  57. data/spec/unit/converters/convert_date_spec.rb +0 -34
  58. data/spec/unit/converters/convert_file_spec.rb +0 -18
  59. data/spec/unit/converters/convert_number_spec.rb +0 -39
  60. data/spec/unit/converters/convert_path_spec.rb +0 -15
  61. data/spec/unit/converters/convert_range_spec.rb +0 -22
  62. data/spec/unit/converters/convert_regex_spec.rb +0 -12
  63. data/spec/unit/converters/convert_string_spec.rb +0 -21
  64. data/spec/unit/converters/on_error_spec.rb +0 -9
  65. data/spec/unit/distance/distance_spec.rb +0 -73
  66. data/spec/unit/enum_select_spec.rb +0 -518
  67. data/spec/unit/error_spec.rb +0 -20
  68. data/spec/unit/evaluator_spec.rb +0 -67
  69. data/spec/unit/expand_spec.rb +0 -290
  70. data/spec/unit/keypress_spec.rb +0 -66
  71. data/spec/unit/mask_spec.rb +0 -140
  72. data/spec/unit/multi_select_spec.rb +0 -741
  73. data/spec/unit/multiline_spec.rb +0 -77
  74. data/spec/unit/new_spec.rb +0 -20
  75. data/spec/unit/ok_spec.rb +0 -10
  76. data/spec/unit/paginator_spec.rb +0 -92
  77. data/spec/unit/question/checks_spec.rb +0 -97
  78. data/spec/unit/question/default_spec.rb +0 -31
  79. data/spec/unit/question/echo_spec.rb +0 -38
  80. data/spec/unit/question/in_spec.rb +0 -115
  81. data/spec/unit/question/initialize_spec.rb +0 -12
  82. data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
  83. data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
  84. data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
  85. data/spec/unit/question/modify_spec.rb +0 -41
  86. data/spec/unit/question/required_spec.rb +0 -92
  87. data/spec/unit/question/validate_spec.rb +0 -115
  88. data/spec/unit/question/validation/call_spec.rb +0 -31
  89. data/spec/unit/question/validation/coerce_spec.rb +0 -30
  90. data/spec/unit/result_spec.rb +0 -40
  91. data/spec/unit/say_spec.rb +0 -67
  92. data/spec/unit/select_spec.rb +0 -942
  93. data/spec/unit/slider_spec.rb +0 -142
  94. data/spec/unit/statement/initialize_spec.rb +0 -15
  95. data/spec/unit/subscribe_spec.rb +0 -22
  96. data/spec/unit/suggest_spec.rb +0 -28
  97. data/spec/unit/timer_spec.rb +0 -29
  98. data/spec/unit/warn_spec.rb +0 -21
  99. data/spec/unit/yes_no_spec.rb +0 -285
  100. data/tasks/console.rake +0 -11
  101. data/tasks/coverage.rake +0 -11
  102. data/tasks/spec.rake +0 -29
  103. data/tty-prompt.gemspec +0 -40
@@ -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,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\nis your\nname?", 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
- {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}"
@@ -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)
@@ -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(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}"
@@ -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,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: ')')
@@ -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