tty 0.2.1 → 0.3.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +45 -115
  4. data/lib/tty.rb +3 -31
  5. data/lib/tty/plugins/plugin.rb +2 -2
  6. data/lib/tty/terminal.rb +2 -58
  7. data/lib/tty/terminal/home.rb +27 -9
  8. data/lib/tty/version.rb +1 -1
  9. data/spec/tty/plugins/plugin/load_spec.rb +10 -18
  10. data/spec/tty/system/editor/open_spec.rb +1 -1
  11. data/spec/tty/terminal/home_spec.rb +18 -26
  12. data/spec/tty/tty_spec.rb +1 -1
  13. data/spec/tty/vector/new_spec.rb +1 -1
  14. metadata +2 -83
  15. data/lib/tty/shell.rb +0 -211
  16. data/lib/tty/shell/distance.rb +0 -49
  17. data/lib/tty/shell/question.rb +0 -335
  18. data/lib/tty/shell/question/modifier.rb +0 -93
  19. data/lib/tty/shell/question/validation.rb +0 -92
  20. data/lib/tty/shell/reader.rb +0 -110
  21. data/lib/tty/shell/response.rb +0 -249
  22. data/lib/tty/shell/response_delegation.rb +0 -55
  23. data/lib/tty/shell/statement.rb +0 -60
  24. data/lib/tty/shell/suggestion.rb +0 -126
  25. data/lib/tty/support/utils.rb +0 -16
  26. data/lib/tty/terminal/echo.rb +0 -38
  27. data/lib/tty/terminal/raw.rb +0 -38
  28. data/spec/tty/shell/ask_spec.rb +0 -77
  29. data/spec/tty/shell/distance/distance_spec.rb +0 -75
  30. data/spec/tty/shell/distance/initialize_spec.rb +0 -14
  31. data/spec/tty/shell/error_spec.rb +0 -30
  32. data/spec/tty/shell/print_table_spec.rb +0 -24
  33. data/spec/tty/shell/question/argument_spec.rb +0 -30
  34. data/spec/tty/shell/question/character_spec.rb +0 -24
  35. data/spec/tty/shell/question/default_spec.rb +0 -25
  36. data/spec/tty/shell/question/in_spec.rb +0 -23
  37. data/spec/tty/shell/question/initialize_spec.rb +0 -24
  38. data/spec/tty/shell/question/modifier/apply_to_spec.rb +0 -34
  39. data/spec/tty/shell/question/modifier/letter_case_spec.rb +0 -27
  40. data/spec/tty/shell/question/modifier/whitespace_spec.rb +0 -33
  41. data/spec/tty/shell/question/modify_spec.rb +0 -44
  42. data/spec/tty/shell/question/valid_spec.rb +0 -46
  43. data/spec/tty/shell/question/validate_spec.rb +0 -30
  44. data/spec/tty/shell/question/validation/coerce_spec.rb +0 -24
  45. data/spec/tty/shell/question/validation/valid_value_spec.rb +0 -28
  46. data/spec/tty/shell/reader/getc_spec.rb +0 -42
  47. data/spec/tty/shell/response/read_bool_spec.rb +0 -40
  48. data/spec/tty/shell/response/read_char_spec.rb +0 -16
  49. data/spec/tty/shell/response/read_date_spec.rb +0 -20
  50. data/spec/tty/shell/response/read_email_spec.rb +0 -42
  51. data/spec/tty/shell/response/read_multiple_spec.rb +0 -23
  52. data/spec/tty/shell/response/read_number_spec.rb +0 -28
  53. data/spec/tty/shell/response/read_range_spec.rb +0 -31
  54. data/spec/tty/shell/response/read_spec.rb +0 -68
  55. data/spec/tty/shell/response/read_string_spec.rb +0 -19
  56. data/spec/tty/shell/say_spec.rb +0 -67
  57. data/spec/tty/shell/statement/initialize_spec.rb +0 -15
  58. data/spec/tty/shell/suggest_spec.rb +0 -50
  59. data/spec/tty/shell/warn_spec.rb +0 -30
  60. data/spec/tty/terminal/color_spec.rb +0 -16
  61. data/spec/tty/terminal/echo_spec.rb +0 -21
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question::Validation, '#valid_value?' do
6
- let(:validation) { /^[^\.]+\.[^\.]+/ }
7
- let(:instance) { described_class.new validation }
8
-
9
- subject { instance.valid_value?(value) }
10
-
11
- context '' do
12
- let(:value) { nil }
13
-
14
- it { is_expected.to eq(false) }
15
- end
16
-
17
- context 'when the value matches validation' do
18
- let(:value) { 'piotr.murach' }
19
-
20
- it { is_expected.to eq(true) }
21
- end
22
-
23
- context 'when the value is not matching validation' do
24
- let(:value) { 'piotrmurach' }
25
-
26
- it { expect { subject }.to raise_error(TTY::InvalidArgument) }
27
- end
28
- end
@@ -1,42 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Reader, '#getc' do
6
- let(:instance) { described_class.new(shell) }
7
-
8
- let(:input) { StringIO.new }
9
- let(:output) { StringIO.new }
10
- let(:shell) { TTY::Shell.new(input, output) }
11
-
12
- subject(:reader) { instance.getc mask }
13
-
14
- context 'with mask' do
15
- let(:mask) { '*'}
16
-
17
- it 'masks characters' do
18
- input << "password\n"
19
- input.rewind
20
- expect(reader).to eql "password"
21
- expect(output.string).to eql("********")
22
- end
23
- end
24
-
25
- context "without mask" do
26
- let(:mask) { }
27
-
28
- it 'masks characters' do
29
- input << "password\n"
30
- input.rewind
31
- expect(reader).to eql "password"
32
- expect(output.string).to eql("password")
33
- end
34
-
35
- it 'deletes characters when backspace pressed' do
36
- input << "\b\b"
37
- input.rewind
38
- expect(reader).to eql ''
39
- expect(output.string).to eql('')
40
- end
41
- end
42
- end
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#read_bool' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- it 'fails to read boolean' do
11
- input << 'invalid'
12
- input.rewind
13
- q = shell.ask("Do you read books?")
14
- expect { q.read_bool }.to raise_error(Necromancer::ConversionTypeError)
15
- end
16
-
17
- it 'reads negative boolean' do
18
- input << 'No'
19
- input.rewind
20
- q = shell.ask("Do you read books?")
21
- answer = q.read_bool
22
- expect(answer).to eql false
23
- end
24
-
25
- it 'reads positive boolean' do
26
- input << 'Yes'
27
- input.rewind
28
- q = shell.ask("Do you read books?")
29
- answer = q.read_bool
30
- expect(answer).to eql true
31
- end
32
-
33
- it 'reads single positive boolean' do
34
- input << 'y'
35
- input.rewind
36
- q = shell.ask("Do you read books?")
37
- answer = q.read_bool
38
- expect(answer).to eql true
39
- end
40
- end
@@ -1,16 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#read_char' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- it 'reads single character' do
11
- input << "abcde"
12
- input.rewind
13
- q = shell.ask("What is your favourite letter?")
14
- expect(q.read_char).to eql "a"
15
- end
16
- end
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#read_date' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- it 'reads date' do
11
- input << "20th April 1887"
12
- input.rewind
13
- q = shell.ask("When were your born?")
14
- answer = q.read_date
15
- expect(answer).to be_kind_of Date
16
- expect(answer.day).to eql 20
17
- expect(answer.month).to eql 4
18
- expect(answer.year).to eql 1887
19
- end
20
- end
@@ -1,42 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#read_email' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- context 'with valid email' do
11
- it 'reads empty' do
12
- input << ""
13
- input.rewind
14
- q = shell.ask("What is your email?")
15
- expect { q.read_email }.to raise_error(TTY::InvalidArgument)
16
- end
17
-
18
- it 'reads valid email' do
19
- input << "piotr@example.com"
20
- input.rewind
21
- q = shell.ask("What is your email?")
22
- expect(q.read_email).to eql "piotr@example.com"
23
- end
24
- end
25
-
26
- context 'with invalid email' do
27
- it 'fails to read invalid email' do
28
- input << "this will@neverwork"
29
- input.rewind
30
- q = shell.ask("What is your email?")
31
- expect { q.read_email }.to raise_error(TTY::InvalidArgument)
32
- end
33
-
34
- it 'reads invalid and asks again' do
35
- input << "this will@neverwork\nthis.will@example.com"
36
- input.rewind
37
- q = shell.ask("What is your email?").on_error(:retry)
38
- expect(q.read_email).to eql "this.will@example.com"
39
- expect(output.string).to eql "What is your email?\nWhat is your email?\n"
40
- end
41
- end
42
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#read_multiple' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- it 'reads multiple lines' do
11
- input << "First line\nSecond line\nThird line"
12
- input.rewind
13
- q = shell.ask("Provide description?")
14
- expect(q.read_multiple).to eq("First line\nSecond line\nThird line")
15
- end
16
-
17
- it 'skips empty lines' do
18
- input << "First line\n\nSecond line"
19
- input.rewind
20
- q = shell.ask("Provide description?")
21
- expect(q.read_multiple).to eq("First line\nSecond line")
22
- end
23
- end
@@ -1,28 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#read_numbers' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- it 'reads integer' do
11
- input << 35
12
- input.rewind
13
- q = shell.ask("What temperature?")
14
- answer = q.read_int
15
- expect(answer).to be_kind_of Integer
16
- expect(answer).to eql 35
17
- end
18
-
19
- it 'reads float' do
20
- number = 6.666
21
- input << number
22
- input.rewind
23
- q = shell.ask("How tall are you?")
24
- answer = q.read_float
25
- expect(answer).to be_kind_of Float
26
- expect(answer).to eql number
27
- end
28
- end
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#read_range' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- subject {
11
- input << value
12
- input.rewind
13
- shell.ask("Which age group?").read_range
14
- }
15
-
16
- context 'with valid range' do
17
- let(:value) { "20-30" }
18
-
19
- it { expect(subject).to be_kind_of Range }
20
-
21
- it { expect(subject).to eql (20..30) }
22
- end
23
-
24
- context 'with invalid range' do
25
- let(:value) { "abcd" }
26
-
27
- it "fails to convert to range" do
28
- expect { subject }.to raise_error(Necromancer::ConversionTypeError)
29
- end
30
- end
31
- end # read_range
@@ -1,68 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#read_password' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- context 'with no mask' do
11
- it 'asks with echo on' do
12
- input << "password"
13
- input.rewind
14
- q = shell.ask("What is your password: ").echo(true)
15
- expect(q.read).to eql("password")
16
- expect(output.string).to eql('What is your password: ')
17
- expect(q.mask?).to eq(false)
18
- end
19
-
20
- it 'asks with echo off' do
21
- input << "password"
22
- input.rewind
23
- q = shell.ask("What is your password: ").echo(false)
24
- expect(q.read).to eql("password")
25
- expect(output.string).to eql('What is your password: ')
26
- expect(q.mask?).to eq(false)
27
- end
28
- end
29
-
30
- context 'with mask' do
31
- it 'masks output with character' do
32
- input << "password\n"
33
- input.rewind
34
- q = shell.ask("What is your password: ").mask('*')
35
- expect(q.read).to eql("password")
36
- expect(output.string).to eql('What is your password: ********')
37
- expect(q.mask?).to eq(true)
38
- end
39
-
40
- it 'ignores mask if echo is off' do
41
- input << "password"
42
- input.rewind
43
- q = shell.ask("What is your password: ").echo(false).mask('*')
44
- expect(q.read).to eql("password")
45
- expect(output.string).to eql('What is your password: ')
46
- expect(q.mask?).to eq(true)
47
- end
48
- end
49
-
50
- context 'with mask and echo as options' do
51
- it 'asks with options' do
52
- input << "password"
53
- input.rewind
54
- q = shell.ask("What is your password: ", :echo => false, :mask => '*')
55
- expect(q.read_password).to eq("password")
56
- end
57
-
58
- it 'asks with block' do
59
- input << "password"
60
- input.rewind
61
- q = shell.ask "What is your password: " do
62
- echo false
63
- mask '*'
64
- end
65
- expect(q.read_password).to eq("password")
66
- end
67
- end
68
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell::Question, '#initialize' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- it 'reads string' do
11
- name = "Piotr"
12
- input << name
13
- input.rewind
14
- q = shell.ask("What is your name?")
15
- answer = q.read_string
16
- expect(answer).to be_kind_of String
17
- expect(answer).to eql name
18
- end
19
- end
@@ -1,67 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe TTY::Shell, '#say' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:color) { Pastel.new(enabled: true) }
9
-
10
- subject(:shell) { TTY::Shell.new(input, output) }
11
-
12
- before { allow(Pastel).to receive(:new).and_return(color) }
13
-
14
- after { output.rewind }
15
-
16
- it 'prints an empty message' do
17
- shell.say ""
18
- expect(output.string).to eql ""
19
- end
20
-
21
- context 'with new line' do
22
- it 'prints a message with newline' do
23
- shell.say "Hell yeah!\n"
24
- expect(output.string).to eql "Hell yeah!\n"
25
- end
26
-
27
- it 'prints a message with implicit newline' do
28
- shell.say "Hell yeah!\n"
29
- expect(output.string).to eql "Hell yeah!\n"
30
- end
31
-
32
- it 'prints a message with newline within text' do
33
- shell.say "Hell\n yeah!"
34
- expect(output.string).to eql "Hell\n yeah!\n"
35
- end
36
-
37
- it 'prints a message with newline within text and blank space' do
38
- shell.say "Hell\n yeah! "
39
- expect(output.string).to eql "Hell\n yeah! "
40
- end
41
-
42
- it 'prints a message without newline' do
43
- shell.say "Hell yeah!", :newline => false
44
- expect(output.string).to eql "Hell yeah!"
45
- end
46
- end
47
-
48
- context 'with tab or space' do
49
- it 'prints ' do
50
- shell.say "Hell yeah!\t"
51
- expect(output.string).to eql "Hell yeah!\t"
52
- end
53
- end
54
-
55
- context 'with color' do
56
- it 'prints message with ansi color' do
57
- shell.say "Hell yeah!", :color => :green
58
- expect(output.string).to eql "\e[32mHell yeah!\e[0m\n"
59
- end
60
-
61
- it 'prints message with ansi color without newline' do
62
- shell.say "Hell yeah! ", :color => :green
63
- expect(output.string).to eql "\e[32mHell yeah! \e[0m"
64
- end
65
- end
66
-
67
- end # say
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe TTY::Shell::Statement, '#new' do
6
- let(:input) { StringIO.new }
7
- let(:output) { StringIO.new }
8
- let(:shell) { TTY::Shell.new(input, output) }
9
-
10
- subject(:statement) { described_class.new }
11
-
12
- it { expect(statement.newline).to eq(true) }
13
-
14
- it { expect(statement.color).to eq(false) }
15
- end