tty-prompt 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -3
  3. data/CHANGELOG.md +12 -0
  4. data/README.md +3 -3
  5. data/appveyor.yml +2 -0
  6. data/lib/tty/prompt/keypress.rb +7 -4
  7. data/lib/tty/prompt/reader.rb +1 -1
  8. data/lib/tty/prompt/reader/win_api.rb +14 -0
  9. data/lib/tty/prompt/reader/win_console.rb +9 -2
  10. data/lib/tty/prompt/timeout.rb +44 -23
  11. data/lib/tty/prompt/version.rb +1 -1
  12. data/tty-prompt.gemspec +6 -3
  13. metadata +21 -131
  14. data/spec/spec_helper.rb +0 -45
  15. data/spec/unit/ask_spec.rb +0 -132
  16. data/spec/unit/choice/eql_spec.rb +0 -22
  17. data/spec/unit/choice/from_spec.rb +0 -29
  18. data/spec/unit/choices/add_spec.rb +0 -12
  19. data/spec/unit/choices/each_spec.rb +0 -13
  20. data/spec/unit/choices/find_by_spec.rb +0 -10
  21. data/spec/unit/choices/new_spec.rb +0 -10
  22. data/spec/unit/choices/pluck_spec.rb +0 -9
  23. data/spec/unit/collect_spec.rb +0 -33
  24. data/spec/unit/converters/convert_bool_spec.rb +0 -58
  25. data/spec/unit/converters/convert_char_spec.rb +0 -11
  26. data/spec/unit/converters/convert_custom_spec.rb +0 -14
  27. data/spec/unit/converters/convert_date_spec.rb +0 -34
  28. data/spec/unit/converters/convert_file_spec.rb +0 -17
  29. data/spec/unit/converters/convert_number_spec.rb +0 -39
  30. data/spec/unit/converters/convert_path_spec.rb +0 -18
  31. data/spec/unit/converters/convert_range_spec.rb +0 -22
  32. data/spec/unit/converters/convert_regex_spec.rb +0 -12
  33. data/spec/unit/converters/convert_string_spec.rb +0 -21
  34. data/spec/unit/converters/on_error_spec.rb +0 -9
  35. data/spec/unit/distance/distance_spec.rb +0 -73
  36. data/spec/unit/enum_paginator_spec.rb +0 -65
  37. data/spec/unit/enum_select_spec.rb +0 -310
  38. data/spec/unit/error_spec.rb +0 -20
  39. data/spec/unit/evaluator_spec.rb +0 -67
  40. data/spec/unit/expand_spec.rb +0 -198
  41. data/spec/unit/keypress_spec.rb +0 -58
  42. data/spec/unit/mask_spec.rb +0 -132
  43. data/spec/unit/multi_select_spec.rb +0 -319
  44. data/spec/unit/multiline_spec.rb +0 -77
  45. data/spec/unit/new_spec.rb +0 -20
  46. data/spec/unit/ok_spec.rb +0 -10
  47. data/spec/unit/paginator_spec.rb +0 -63
  48. data/spec/unit/question/checks_spec.rb +0 -97
  49. data/spec/unit/question/default_spec.rb +0 -31
  50. data/spec/unit/question/echo_spec.rb +0 -38
  51. data/spec/unit/question/in_spec.rb +0 -115
  52. data/spec/unit/question/initialize_spec.rb +0 -12
  53. data/spec/unit/question/modifier/apply_to_spec.rb +0 -24
  54. data/spec/unit/question/modifier/letter_case_spec.rb +0 -41
  55. data/spec/unit/question/modifier/whitespace_spec.rb +0 -51
  56. data/spec/unit/question/modify_spec.rb +0 -41
  57. data/spec/unit/question/required_spec.rb +0 -92
  58. data/spec/unit/question/validate_spec.rb +0 -115
  59. data/spec/unit/question/validation/call_spec.rb +0 -31
  60. data/spec/unit/question/validation/coerce_spec.rb +0 -30
  61. data/spec/unit/reader/history_spec.rb +0 -172
  62. data/spec/unit/reader/key_event_spec.rb +0 -86
  63. data/spec/unit/reader/line_spec.rb +0 -110
  64. data/spec/unit/reader/publish_keypress_event_spec.rb +0 -94
  65. data/spec/unit/reader/read_keypress_spec.rb +0 -80
  66. data/spec/unit/reader/read_line_spec.rb +0 -68
  67. data/spec/unit/reader/read_multiline_spec.rb +0 -60
  68. data/spec/unit/result_spec.rb +0 -40
  69. data/spec/unit/say_spec.rb +0 -67
  70. data/spec/unit/select_spec.rb +0 -359
  71. data/spec/unit/slider_spec.rb +0 -96
  72. data/spec/unit/statement/initialize_spec.rb +0 -15
  73. data/spec/unit/suggest_spec.rb +0 -28
  74. data/spec/unit/warn_spec.rb +0 -21
  75. data/spec/unit/yes_no_spec.rb +0 -235
data/spec/spec_helper.rb DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'tty-prompt'
19
-
20
- RSpec.configure do |config|
21
- config.expect_with :rspec do |expectations|
22
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
23
- end
24
-
25
- config.mock_with :rspec do |mocks|
26
- mocks.verify_partial_doubles = true
27
- end
28
-
29
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
30
- config.disable_monkey_patching!
31
-
32
- # This setting enables warnings. It's recommended, but in some cases may
33
- # be too noisy due to issues in dependencies.
34
- config.warnings = true
35
-
36
- if config.files_to_run.one?
37
- config.default_formatter = 'doc'
38
- end
39
-
40
- config.profile_examples = 2
41
-
42
- config.order = :random
43
-
44
- Kernel.srand config.seed
45
- end
@@ -1,132 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt, '#ask' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'asks question' do
8
- prompt.ask('What is your name?')
9
- expect(prompt.output.string).to eq([
10
- "What is your name? ",
11
- "\e[1A\e[2K\e[1G",
12
- "What is your name? \n"
13
- ].join)
14
- end
15
-
16
- it 'asks an empty question ' do
17
- prompt.ask('')
18
- expect(prompt.output.string).to eql('')
19
- end
20
-
21
- it 'asks an empty question and returns nil if EOF is sent to stdin' do
22
- prompt.input << nil
23
- prompt.input.rewind
24
- answer = prompt.ask('')
25
- expect(answer).to eql(nil)
26
- expect(prompt.output.string).to eq('')
27
- end
28
-
29
- it "asks a question with a prefix [?]" do
30
- prompt = TTY::TestPrompt.new(prefix: "[?] ")
31
- prompt.input << "\r"
32
- prompt.input.rewind
33
- answer = prompt.ask 'Are you Polish?'
34
- expect(answer).to eq(nil)
35
- expect(prompt.output.string).to eq([
36
- "[?] Are you Polish? ",
37
- "\e[2K\e[1G[?] Are you Polish? \n",
38
- "\e[1A\e[2K\e[1G",
39
- "[?] Are you Polish? \n"
40
- ].join)
41
- end
42
-
43
- it 'asks a question with block' do
44
- prompt.input << ''
45
- prompt.input.rewind
46
- answer = prompt.ask "What is your name?" do |q|
47
- q.default 'Piotr'
48
- end
49
- expect(answer).to eq('Piotr')
50
- expect(prompt.output.string).to eq([
51
- "What is your name? \e[90m(Piotr)\e[0m ",
52
- "\e[1A\e[2K\e[1G",
53
- "What is your name? \e[32mPiotr\e[0m\n"
54
- ].join)
55
- end
56
-
57
- it "changes question color" do
58
- prompt.input << ''
59
- prompt.input.rewind
60
- options = {default: 'Piotr', help_color: :red, active_color: :cyan}
61
- answer = prompt.ask("What is your name?", options)
62
- expect(answer).to eq('Piotr')
63
- expect(prompt.output.string).to eq([
64
- "What is your name? \e[31m(Piotr)\e[0m ",
65
- "\e[1A\e[2K\e[1G",
66
- "What is your name? \e[36mPiotr\e[0m\n"
67
- ].join)
68
- end
69
-
70
- it "permits empty default parameter" do
71
- prompt.input << "\r"
72
- prompt.input.rewind
73
-
74
- answer = prompt.ask("What is your name?", default: '')
75
- expect(answer).to eq('')
76
- expect(prompt.output.string).to eq([
77
- "What is your name? ",
78
- "\e[2K\e[1GWhat is your name? \n",
79
- "\e[1A\e[2K\e[1G",
80
- "What is your name? \n"
81
- ].join)
82
- end
83
-
84
- it "permits nil default parameter" do
85
- prompt.input << "\r"
86
- prompt.input.rewind
87
-
88
- answer = prompt.ask("What is your name?", default: nil)
89
- expect(answer).to eq(nil)
90
- expect(prompt.output.string).to eq([
91
- "What is your name? ",
92
- "\e[2K\e[1GWhat is your name? \n",
93
- "\e[1A\e[2K\e[1G",
94
- "What is your name? \n"
95
- ].join)
96
- end
97
-
98
- it "overwrites global settings" do
99
- global_settings = {prefix: "[?] ", active_color: :cyan, help_color: :red}
100
- prompt = TTY::TestPrompt.new(global_settings)
101
-
102
- prompt.input << "Piotr\r"
103
- prompt.input.rewind
104
- prompt.ask('What is your name?')
105
-
106
- prompt.input << "Piotr\r"
107
- prompt.input.rewind
108
- local_settings = {prefix: ':-) ', active_color: :blue, help_color: :magenta}
109
- prompt.ask('What is your name?', local_settings)
110
-
111
- expect(prompt.output.string).to eq([
112
- "[?] What is your name? ",
113
- "\e[2K\e[1G[?] What is your name? P",
114
- "\e[2K\e[1G[?] What is your name? Pi",
115
- "\e[2K\e[1G[?] What is your name? Pio",
116
- "\e[2K\e[1G[?] What is your name? Piot",
117
- "\e[2K\e[1G[?] What is your name? Piotr",
118
- "\e[2K\e[1G[?] What is your name? Piotr\n",
119
- "\e[1A\e[2K\e[1G",
120
- "[?] What is your name? \e[36mPiotr\e[0m\n",
121
- ":-) What is your name? ",
122
- "\e[2K\e[1G:-) What is your name? P",
123
- "\e[2K\e[1G:-) What is your name? Pi",
124
- "\e[2K\e[1G:-) What is your name? Pio",
125
- "\e[2K\e[1G:-) What is your name? Piot",
126
- "\e[2K\e[1G:-) What is your name? Piotr",
127
- "\e[2K\e[1G:-) What is your name? Piotr\n",
128
- "\e[1A\e[2K\e[1G",
129
- ":-) What is your name? \e[34mPiotr\e[0m\n"
130
- ].join)
131
- end
132
- end
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Choice, '#==' do
4
- it "is true with the same name and value attributes" do
5
- expect(described_class.new(:large, 1)).
6
- to eq(described_class.new(:large, 1))
7
- end
8
-
9
- it "is false with different name attribute" do
10
- expect(described_class.new(:large, 1)).
11
- not_to eq(described_class.new(:medium, 1))
12
- end
13
-
14
- it "is false with different value attribute" do
15
- expect(described_class.new(:large, 1)).
16
- not_to eq(described_class.new(:large, 2))
17
- end
18
-
19
- it "is false with non-choice object" do
20
- expect(described_class.new(:large, 1)).not_to eq(:other)
21
- end
22
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Choice, '#from' do
4
- it "skips Choice instance" do
5
- choice = described_class.new(:large, 1)
6
- expect(described_class.from(choice)).to eq(choice)
7
- end
8
-
9
- it "creates choice from string" do
10
- choice = described_class.new('large', 'large')
11
- expect(described_class.from('large')).to eq(choice)
12
- end
13
-
14
- it "creates choice from array" do
15
- choice = described_class.new('large', 1)
16
- expect(described_class.from([:large, 1])).to eq(choice)
17
- end
18
-
19
- it "creates choice from hash value" do
20
- choice = described_class.new('large', 1)
21
- expect(described_class.from({large: 1})).to eq(choice)
22
- end
23
-
24
- it "create choice from hash with key property" do
25
- default = {key: 'h', name: 'Help', value: :help}
26
- choice = described_class.new('Help', :help)
27
- expect(described_class.from(default)).to eq(choice)
28
- end
29
- end
@@ -1,12 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Choices, '#<<' do
4
- it "adds choice to collection" do
5
- choices = described_class.new
6
- expect(choices).to be_empty
7
- choice = TTY::Prompt::Choice.from([:label, 1])
8
- choices << [:label, 1]
9
- expect(choices.size).to eq(1)
10
- expect(choices.to_ary).to eq([choice])
11
- end
12
- end
@@ -1,13 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Choices, '.each' do
4
- it "iterates over collection" do
5
- choices = described_class[:large, :medium, :small]
6
- actual = []
7
- choices.each do |choice|
8
- actual << choice.name
9
- end
10
- expect(actual).to eq([:large, :medium, :small])
11
- expect(choices.each).to be_kind_of(Enumerator)
12
- end
13
- end
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Choices, '#find_by' do
4
- it "finds a matching choice by key name" do
5
- collection = [{name: 'large'},{name: 'medium'},{name: 'small'}]
6
- choice = TTY::Prompt::Choice.from(name: 'small')
7
- choices = described_class[*collection]
8
- expect(choices.find_by(:name, 'small')).to eq(choice)
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Choices, '.new' do
4
- it "creates choices collection" do
5
- choice_1 = TTY::Prompt::Choice.from(:label1)
6
- choice_2 = TTY::Prompt::Choice.from(:label2)
7
- collection = described_class[:label1, :label2]
8
- expect(collection.choices).to eq([choice_1, choice_2])
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Choices, '#pluck' do
4
- it "plucks choice by key name" do
5
- collection = [{name: 'large'},{name: 'medium'},{name: 'small'}]
6
- choices = described_class[*collection]
7
- expect(choices.pluck(:name)).to eq(['large', 'medium', 'small'])
8
- end
9
- end
@@ -1,33 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt, '#collect' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it "collects more than one answer" do
8
- prompt.input << "Piotr\r30\rStreet\rCity\r123\r"
9
- prompt.input.rewind
10
-
11
- result = prompt.collect do
12
- key(:name).ask('Name?')
13
-
14
- key(:age).ask('Age?', convert: :int)
15
-
16
- key(:address) do
17
- key(:street).ask('Street?', required: true)
18
- key(:city).ask('City?')
19
- key(:zip).ask('Zip?', validate: /\A\d{3}\Z/)
20
- end
21
- end
22
-
23
- expect(result).to include({
24
- name: 'Piotr',
25
- age: 30,
26
- address: {
27
- street: 'Street',
28
- city: 'City',
29
- zip: '123'
30
- }
31
- })
32
- end
33
- end
@@ -1,58 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Question, 'convert bool' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new}
6
-
7
- it 'fails to convert boolean' do
8
- prompt.input << 'invalid'
9
- prompt.input.rewind
10
- expect {
11
- prompt.ask("Do you read books?", convert: :bool)
12
- }.to raise_error(TTY::Prompt::ConversionError)
13
- end
14
-
15
- it "handles default values" do
16
- prompt.input << "\n"
17
- prompt.input.rewind
18
- response = prompt.ask('Do you read books?', convert: :bool, default: true)
19
- expect(response).to eql(true)
20
- expect(prompt.output.string).to eq([
21
- "Do you read books? \e[90m(true)\e[0m ",
22
- "\e[2K\e[1GDo you read books? \e[90m(true)\e[0m \n",
23
- "\e[1A\e[2K\e[1G",
24
- "Do you read books? \e[32mtrue\e[0m\n"
25
- ].join)
26
- end
27
-
28
- it "handles default values" do
29
- prompt.input << "\n"
30
- prompt.input.rewind
31
- response = prompt.ask("Do you read books?") { |q|
32
- q.default true
33
- q.convert :bool
34
- }
35
- expect(response).to eq(true)
36
- end
37
-
38
- it 'converts negative boolean' do
39
- prompt.input << 'No'
40
- prompt.input.rewind
41
- response = prompt.ask('Do you read books?', convert: :bool)
42
- expect(response).to eq(false)
43
- end
44
-
45
- it 'converts positive boolean' do
46
- prompt.input << 'Yes'
47
- prompt.input.rewind
48
- response = prompt.ask("Do you read books?", convert: :bool)
49
- expect(response).to eq(true)
50
- end
51
-
52
- it 'converts single positive boolean' do
53
- prompt.input << 'y'
54
- prompt.input.rewind
55
- response = prompt.ask('Do you read books?', convert: :bool)
56
- expect(response).to eq(true)
57
- end
58
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Question, 'convert char' do
4
- it 'reads single character' do
5
- prompt = TTY::TestPrompt.new
6
- prompt.input << "abcde"
7
- prompt.input.rewind
8
- response = prompt.ask("What is your favourite letter?", convert: :char)
9
- expect(response).to eq('a')
10
- end
11
- end
@@ -1,14 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Question, 'convert custom' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new }
6
-
7
- it 'converts response with custom conversion' do
8
- prompt.input << "one,two,three\n"
9
- prompt.input.rewind
10
- conversion = proc { |input| input.split(/,\s*/) }
11
- answer = prompt.ask('Ingredients? (comma sep list)', convert: conversion)
12
- expect(answer).to eq(['one','two','three'])
13
- end
14
- end
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Prompt::Question, 'convert date' do
4
-
5
- subject(:prompt) { TTY::TestPrompt.new}
6
-
7
- it 'fails to convert date' do
8
- prompt.input << 'invalid'
9
- prompt.input.rewind
10
- expect {
11
- prompt.ask("When were you born?", convert: :date)
12
- }.to raise_error(TTY::Prompt::ConversionError)
13
- end
14
-
15
- it 'converts date' do
16
- prompt.input << "20th April 1887"
17
- prompt.input.rewind
18
- response = prompt.ask("When were your born?", convert: :date)
19
- expect(response).to be_kind_of(Date)
20
- expect(response.day).to eq(20)
21
- expect(response.month).to eq(4)
22
- expect(response.year).to eq(1887)
23
- end
24
-
25
- it "converts datetime" do
26
- prompt.input << "20th April 1887"
27
- prompt.input.rewind
28
- response = prompt.ask("When were your born?", convert: :datetime)
29
- expect(response).to be_kind_of(DateTime)
30
- expect(response.day).to eq(20)
31
- expect(response.month).to eq(4)
32
- expect(response.year).to eq(1887)
33
- end
34
- end