tty-prompt 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#initialize' do
4
-
5
- subject(:question) { described_class.new(TTY::TestPrompt.new)}
6
-
7
- it { expect(question.echo).to eq(true) }
8
-
9
- it { expect(question.modifier).to eq([]) }
10
-
11
- it { expect(question.validation).to eq(TTY::Prompt::Question::UndefinedSetting) }
12
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question::Modifier, '#apply_to' do
4
- let(:string) { "text to be modified"}
5
-
6
- it "doesn't apply modifiers" do
7
- modifier = described_class.new([])
8
- expect(modifier.apply_to(string)).to eq(string)
9
- end
10
-
11
- it 'combines whitespace & letter case modifications' do
12
- modifiers = [:collapse, :capitalize]
13
- modifier = described_class.new(modifiers)
14
- modified = modifier.apply_to(string)
15
- expect(modified).to eq('Text to be modified')
16
- end
17
-
18
- it 'combines letter case & whitespace modifications' do
19
- modifiers = [:up, :collapse]
20
- modifier = described_class.new(modifiers)
21
- modified = modifier.apply_to(string)
22
- expect(modified).to eq('TEXT TO BE MODIFIED')
23
- end
24
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question::Modifier, '#letter_case' do
4
- context "string" do
5
- let(:string) { 'text to modify' }
6
-
7
- it "changes to uppercase" do
8
- modified = described_class.letter_case(:up, string)
9
- expect(modified).to eq('TEXT TO MODIFY')
10
- end
11
-
12
- it "changes to lower case" do
13
- modified = described_class.letter_case(:down, string)
14
- expect(modified).to eq('text to modify')
15
- end
16
-
17
- it "capitalizes text" do
18
- modified = described_class.letter_case(:capitalize, string)
19
- expect(modified).to eq('Text to modify')
20
- end
21
- end
22
-
23
- context "nil (empty user input)" do
24
- let(:string) { nil }
25
-
26
- example "up returns nil" do
27
- modified = described_class.letter_case(:up, string)
28
- expect(modified).to be_nil
29
- end
30
-
31
- example "down returns nil" do
32
- modified = described_class.letter_case(:down, string)
33
- expect(modified).to be_nil
34
- end
35
-
36
- example "capitalize returns nil" do
37
- modified = described_class.letter_case(:capitalize, string)
38
- expect(modified).to be_nil
39
- end
40
- end
41
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question::Modifier, '#whitespace' do
4
- context "string with whitespaces" do
5
- let(:string) { " text\t \n to\t modify\r\n" }
6
-
7
- it "trims whitespace" do
8
- modified = described_class.whitespace(:trim, string)
9
- expect(modified).to eq("text\t \n to\t modify")
10
- end
11
-
12
- it "chomps whitespace" do
13
- modified = described_class.whitespace(:chomp, string)
14
- expect(modified).to eq(" text\t \n to\t modify")
15
- end
16
-
17
- it "collapses text" do
18
- modified = described_class.whitespace(:collapse, string)
19
- expect(modified).to eq(" text to modify ")
20
- end
21
-
22
- it "removes whitespace" do
23
- modified = described_class.whitespace(:remove, string)
24
- expect(modified).to eq("texttomodify")
25
- end
26
- end
27
-
28
- context "nil (empty user input)" do
29
- let(:string) { nil }
30
-
31
- example "trim returns nil" do
32
- modified = described_class.whitespace(:trim, string)
33
- expect(modified).to be_nil
34
- end
35
-
36
- example "chomp returns nil" do
37
- modified = described_class.whitespace(:chomp, string)
38
- expect(modified).to be_nil
39
- end
40
-
41
- example "collapse returns nil" do
42
- modified = described_class.whitespace(:collapse, string)
43
- expect(modified).to be_nil
44
- end
45
-
46
- example "remove returns nil" do
47
- modified = described_class.whitespace(:remove, string)
48
- expect(modified).to be_nil
49
- end
50
- end
51
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#modify' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'preserves answer for unkown modification' do
8
- prompt.input << 'piotr'
9
- prompt.input.rewind
10
- answer = prompt.ask("What is your name?") { |q| q.modify(:none) }
11
- expect(answer).to eq('piotr')
12
- end
13
-
14
- it 'converts to upper case' do
15
- prompt.input << 'piotr'
16
- prompt.input.rewind
17
- answer = prompt.ask("What is your name?") { |q| q.modify(:upcase) }
18
- expect(answer).to eq('PIOTR')
19
- end
20
-
21
- it 'trims whitespace' do
22
- prompt.input << " Some white\t space\t \there! \n"
23
- prompt.input.rewind
24
- answer = prompt.ask('Enter some text: ') { |q| q.modify(:trim) }
25
- expect(answer).to eq("Some white\t space\t \there!")
26
- end
27
-
28
- it 'collapses whitespace' do
29
- prompt.input << " Some white\t space\t \there! \n"
30
- prompt.input.rewind
31
- answer = prompt.ask('Enter some text: ') { |q| q.modify(:collapse) }
32
- expect(answer).to eq(' Some white space here! ')
33
- end
34
-
35
- it 'strips and collapses whitespace' do
36
- prompt.input << " Some white\t space\t \there! \n"
37
- prompt.input.rewind
38
- answer = prompt.ask('Enter some text: ') { |q| q.modify(:strip, :collapse) }
39
- expect(answer).to eq('Some white space here!')
40
- end
41
- end
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#required' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'requires value to be present' do
8
- prompt.input << "Piotr"
9
- prompt.input.rewind
10
- prompt.ask('What is your name?') { |q| q.required(true) }
11
- expect(prompt.output.string).to eq([
12
- "What is your name? ",
13
- "\e[2K\e[1GWhat is your name? P",
14
- "\e[2K\e[1GWhat is your name? Pi",
15
- "\e[2K\e[1GWhat is your name? Pio",
16
- "\e[2K\e[1GWhat is your name? Piot",
17
- "\e[2K\e[1GWhat is your name? Piotr",
18
- "\e[1A\e[2K\e[1G",
19
- "What is your name? \e[32mPiotr\e[0m\n"
20
- ].join)
21
- end
22
-
23
- it 'requires value to be present with option' do
24
- prompt.input << " \nPiotr"
25
- prompt.input.rewind
26
- prompt.ask('What is your name?', required: true)
27
- expect(prompt.output.string).to eq([
28
- "What is your name? ",
29
- "\e[2K\e[1GWhat is your name? ",
30
- "\e[2K\e[1GWhat is your name? ",
31
- "\e[2K\e[1GWhat is your name? \n",
32
- "\e[31m>>\e[0m Value must be provided\e[1A",
33
- "\e[2K\e[1G",
34
- "What is your name? ",
35
- "\e[2K\e[1GWhat is your name? P",
36
- "\e[2K\e[1GWhat is your name? Pi",
37
- "\e[2K\e[1GWhat is your name? Pio",
38
- "\e[2K\e[1GWhat is your name? Piot",
39
- "\e[2K\e[1GWhat is your name? Piotr",
40
- "\e[2K\e[1G",
41
- "\e[1A\e[2K\e[1G",
42
- "What is your name? \e[32mPiotr\e[0m\n"
43
- ].join)
44
- end
45
-
46
- it "doesn't require value to be present" do
47
- prompt.input << ''
48
- prompt.input.rewind
49
- answer = prompt.ask('What is your name?') { |q| q.required(false) }
50
- expect(answer).to be_nil
51
- end
52
-
53
- it "uses required in validation check" do
54
- prompt.input << " \nexists\ntest\n"
55
- prompt.input.rewind
56
- answer = prompt.ask('File name?') do |q|
57
- q.required(true)
58
- q.validate { |v| !(v =~ /exists/) }
59
- q.messages[:required?] = 'File name must not be empty!'
60
- q.messages[:valid?] = 'File already exists!'
61
- end
62
- expect(answer).to eq('test')
63
- expect(prompt.output.string).to eq([
64
- "File name? ",
65
- "\e[2K\e[1GFile name? ",
66
- "\e[2K\e[1GFile name? ",
67
- "\e[2K\e[1GFile name? \n",
68
- "\e[31m>>\e[0m File name must not be empty!",
69
- "\e[1A\e[2K\e[1G",
70
- "File name? ",
71
- "\e[2K\e[1GFile name? e",
72
- "\e[2K\e[1GFile name? ex",
73
- "\e[2K\e[1GFile name? exi",
74
- "\e[2K\e[1GFile name? exis",
75
- "\e[2K\e[1GFile name? exist",
76
- "\e[2K\e[1GFile name? exists",
77
- "\e[2K\e[1GFile name? exists\n",
78
- "\e[31m>>\e[0m File already exists!",
79
- "\e[1A\e[2K\e[1G",
80
- "File name? ",
81
- "\e[2K\e[1GFile name? t",
82
- "\e[2K\e[1GFile name? te",
83
- "\e[2K\e[1GFile name? tes",
84
- "\e[2K\e[1GFile name? test",
85
- "\e[2K\e[1GFile name? test\n",
86
- "\e[2K\e[1G",
87
- "\e[1A\e[2K\e[1G",
88
- "File name? \e[32mtest\e[0m\n",
89
- ].join)
90
- expect(answer).to eq('test')
91
- end
92
- end
@@ -1,115 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question, '#validate' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'validates input with regex' do
8
- prompt.input << 'p.m'
9
- prompt.input.rewind
10
-
11
- answer = prompt.ask('What is your username?') do |q|
12
- q.validate(/^[^\.]+\.[^\.]+/)
13
- end
14
-
15
- expect(answer).to eq('p.m')
16
- expect(prompt.output.string).to eq([
17
- "What is your username? ",
18
- "\e[2K\e[1GWhat is your username? p",
19
- "\e[2K\e[1GWhat is your username? p.",
20
- "\e[2K\e[1GWhat is your username? p.m",
21
- "\e[1A\e[2K\e[1G",
22
- "What is your username? \e[32mp.m\e[0m\n"
23
- ].join)
24
- end
25
-
26
- it 'validates input with proc' do
27
- prompt.input << 'piotr.murach'
28
- prompt.input.rewind
29
-
30
- answer = prompt.ask('What is your username?') do |q|
31
- q.validate { |input| input =~ /^[^\.]+\.[^\.]+/ }
32
- end
33
-
34
- expect(answer).to eq('piotr.murach')
35
- end
36
-
37
- it 'understands custom validation like :email' do
38
- prompt.input << 'piotr@example.com'
39
- prompt.input.rewind
40
-
41
- answer = prompt.ask('What is your email?') do |q|
42
- q.validate :email
43
- end
44
-
45
- expect(answer).to eq('piotr@example.com')
46
- end
47
-
48
- it "provides default error message for wrong input" do
49
- prompt.input << "wrong\np@m.com\n"
50
- prompt.input.rewind
51
-
52
- answer = prompt.ask('What is your email?') do |q|
53
- q.validate :email
54
- end
55
-
56
- expect(answer).to eq('p@m.com')
57
- expect(prompt.output.string).to eq([
58
- "What is your email? ",
59
- "\e[2K\e[1GWhat is your email? w",
60
- "\e[2K\e[1GWhat is your email? wr",
61
- "\e[2K\e[1GWhat is your email? wro",
62
- "\e[2K\e[1GWhat is your email? wron",
63
- "\e[2K\e[1GWhat is your email? wrong",
64
- "\e[2K\e[1GWhat is your email? wrong\n",
65
- "\e[31m>>\e[0m Your answer is invalid (must match :email)\e[1A",
66
- "\e[2K\e[1G",
67
- "What is your email? ",
68
- "\e[2K\e[1GWhat is your email? p",
69
- "\e[2K\e[1GWhat is your email? p@",
70
- "\e[2K\e[1GWhat is your email? p@m",
71
- "\e[2K\e[1GWhat is your email? p@m.",
72
- "\e[2K\e[1GWhat is your email? p@m.c",
73
- "\e[2K\e[1GWhat is your email? p@m.co",
74
- "\e[2K\e[1GWhat is your email? p@m.com",
75
- "\e[2K\e[1GWhat is your email? p@m.com\n",
76
- "\e[2K\e[1G",
77
- "\e[1A\e[2K\e[1G",
78
- "What is your email? \e[32mp@m.com\e[0m\n"
79
- ].join)
80
- end
81
-
82
- it "provides custom error message for wrong input" do
83
- prompt.input << "wrong\np@m.com"
84
- prompt.input.rewind
85
-
86
- answer = prompt.ask('What is your email?') do |q|
87
- q.validate :email
88
- q.messages[:valid?] = 'Not an email!'
89
- end
90
-
91
- expect(answer).to eq('p@m.com')
92
- expect(prompt.output.string).to eq([
93
- "What is your email? ",
94
- "\e[2K\e[1GWhat is your email? w",
95
- "\e[2K\e[1GWhat is your email? wr",
96
- "\e[2K\e[1GWhat is your email? wro",
97
- "\e[2K\e[1GWhat is your email? wron",
98
- "\e[2K\e[1GWhat is your email? wrong",
99
- "\e[2K\e[1GWhat is your email? wrong\n",
100
- "\e[31m>>\e[0m Not an email!\e[1A",
101
- "\e[2K\e[1G",
102
- "What is your email? ",
103
- "\e[2K\e[1GWhat is your email? p",
104
- "\e[2K\e[1GWhat is your email? p@",
105
- "\e[2K\e[1GWhat is your email? p@m",
106
- "\e[2K\e[1GWhat is your email? p@m.",
107
- "\e[2K\e[1GWhat is your email? p@m.c",
108
- "\e[2K\e[1GWhat is your email? p@m.co",
109
- "\e[2K\e[1GWhat is your email? p@m.com",
110
- "\e[2K\e[1G",
111
- "\e[1A\e[2K\e[1G",
112
- "What is your email? \e[32mp@m.com\e[0m\n"
113
- ].join)
114
- end
115
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question::Validation, '#call' do
4
- let(:pattern) { /^[^\.]+\.[^\.]+/ }
5
-
6
- it "validates nil input" do
7
- validation = described_class.new(pattern)
8
- expect(validation.(nil)).to eq(false)
9
- end
10
-
11
- it "validates successfully when the value matches pattern" do
12
- validation = described_class.new(pattern)
13
- expect(validation.('piotr.murach')).to eq(true)
14
- end
15
-
16
- it "validates with a proc" do
17
- pat = proc { |input| !pattern.match(input).nil? }
18
- validation = described_class.new(pat)
19
- expect(validation.call('piotr.murach')).to eq(true)
20
- end
21
-
22
- it "validates with custom name" do
23
- validation = described_class.new(:email)
24
- expect(validation.call('piotr@example.com')).to eq(true)
25
- end
26
-
27
- it "fails validation when not maching pattern" do
28
- validation = described_class.new(pattern)
29
- expect(validation.('piotrmurach')).to eq(false)
30
- end
31
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Prompt::Question::Validation, '#coerce' do
4
- let(:instance) { described_class.new }
5
-
6
- it "coerces lambda into proc" do
7
- pattern = lambda { "^[^\.]+\.[^\.]+" }
8
- validation = described_class.new(pattern)
9
- expect(validation.pattern).to be_a(Proc)
10
- end
11
-
12
- it "doesn't coerce symbols" do
13
- pattern = :email
14
- validation =described_class.new(pattern)
15
- expect(validation.pattern).to eq(:email)
16
- end
17
-
18
- it "coerces into regex" do
19
- pattern = /^[^\.]+\.[^\.]+/
20
- validation = described_class.new(pattern)
21
- expect(validation.pattern).to be_a(Regexp)
22
- end
23
-
24
- it "fails to coerce pattern into validation" do
25
- pattern = Object.new
26
- expect {
27
- described_class.new(pattern)
28
- }.to raise_error(TTY::Prompt::ValidationCoercion)
29
- end
30
- end