vedeu 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +0 -1
  4. data/Guardfile +0 -8
  5. data/README.md +33 -1
  6. data/Rakefile +0 -8
  7. data/bin/vedeu +9 -0
  8. data/lib/vedeu.rb +23 -6
  9. data/lib/vedeu/application.rb +47 -0
  10. data/lib/vedeu/interface/interface.rb +37 -0
  11. data/lib/vedeu/interface/interfaces.rb +49 -0
  12. data/lib/vedeu/output/background.rb +23 -0
  13. data/lib/vedeu/output/base.rb +49 -0
  14. data/lib/vedeu/output/colour.rb +30 -0
  15. data/lib/vedeu/output/compositor.rb +60 -0
  16. data/lib/vedeu/output/directive.rb +34 -0
  17. data/lib/vedeu/output/esc.rb +37 -0
  18. data/lib/vedeu/output/foreground.rb +23 -0
  19. data/lib/vedeu/output/position.rb +22 -0
  20. data/lib/vedeu/output/style.rb +32 -0
  21. data/lib/vedeu/output/translator.rb +62 -0
  22. data/lib/vedeu/process/command.rb +51 -0
  23. data/lib/vedeu/process/commands.rb +58 -0
  24. data/lib/vedeu/process/process.rb +31 -0
  25. data/lib/vedeu/support/terminal.rb +139 -0
  26. data/lib/vedeu/version.rb +1 -1
  27. data/test/lib/vedeu/application_test.rb +18 -0
  28. data/test/lib/vedeu/interface/interface_test.rb +76 -0
  29. data/test/lib/vedeu/interface/interfaces_test.rb +63 -0
  30. data/test/lib/vedeu/output/background_test.rb +10 -0
  31. data/test/lib/vedeu/output/base_test.rb +10 -0
  32. data/test/lib/vedeu/output/colour_test.rb +67 -0
  33. data/test/lib/vedeu/output/compositor_test.rb +106 -0
  34. data/test/lib/vedeu/output/directive_test.rb +55 -0
  35. data/test/lib/vedeu/output/esc_test.rb +71 -0
  36. data/test/lib/vedeu/output/foreground_test.rb +10 -0
  37. data/test/lib/vedeu/output/position_test.rb +33 -0
  38. data/test/lib/vedeu/output/style_test.rb +59 -0
  39. data/test/lib/vedeu/output/translator_test.rb +52 -0
  40. data/test/lib/vedeu/process/command_test.rb +54 -0
  41. data/test/lib/vedeu/process/commands_test.rb +62 -0
  42. data/test/lib/vedeu/process/process_test.rb +11 -0
  43. data/test/lib/vedeu/support/terminal_test.rb +140 -0
  44. data/test/lib/vedeu/version_test.rb +9 -0
  45. data/test/support/test_app/bin/testapp +32 -0
  46. data/test/test_helper.rb +4 -0
  47. data/vedeu.gemspec +0 -6
  48. metadata +60 -99
  49. data/.rubocop.yml +0 -2
  50. data/features/.gitkeep +0 -0
  51. data/lib/vedeu/buffer.rb +0 -106
  52. data/lib/vedeu/colour.rb +0 -98
  53. data/lib/vedeu/terminal.rb +0 -25
  54. data/test/lib/vedeu/buffer_test.rb +0 -114
  55. data/test/lib/vedeu/colour_test.rb +0 -57
  56. data/test/lib/vedeu/terminal_test.rb +0 -30
data/lib/vedeu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Application do
5
+ let(:described_class){ Application }
6
+ let(:instance) { described_class.new(interfaces, options) }
7
+ let(:interfaces) {}
8
+ let(:options) { {} }
9
+
10
+ describe '#start' do
11
+ before { Esc.stubs(:clear).returns('') }
12
+
13
+ subject { instance.start }
14
+
15
+ it { skip }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,76 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Interface do
5
+ let(:described_class) { Interface }
6
+ let(:instance) { described_class.new(options) }
7
+ let(:options) { {} }
8
+
9
+ before do
10
+ Terminal.stubs(:width).returns(80)
11
+ Terminal.stubs(:height).returns(25)
12
+ Terminal.stubs(:show_cursor)
13
+ Terminal.stubs(:hide_cursor)
14
+ end
15
+
16
+ it { instance.must_be_instance_of(Interface) }
17
+
18
+ describe '#initial' do
19
+ subject { instance.initial }
20
+
21
+ context 'capturing output' do
22
+ let(:io) { capture_io { subject }.join }
23
+
24
+ it { io.must_be_instance_of(String) }
25
+ end
26
+ end
27
+
28
+ describe '#main' do
29
+ subject { instance.main }
30
+
31
+ it { subject.must_be_instance_of(NilClass) }
32
+
33
+ context 'capturing output' do
34
+ let(:io) { capture_io { subject }.join }
35
+
36
+ it { io.must_be_instance_of(String) }
37
+ end
38
+ end
39
+
40
+ describe '#input' do
41
+ subject { instance.input }
42
+
43
+ it { subject.must_be_instance_of(NilClass) }
44
+
45
+ context 'capturing output' do
46
+ let(:io) { capture_io { subject }.join }
47
+
48
+ it { io.must_be_instance_of(String) }
49
+ end
50
+ end
51
+
52
+ describe '#output' do
53
+ subject { instance.output }
54
+
55
+ it { subject.must_be_instance_of(NilClass) }
56
+
57
+ context 'capturing output' do
58
+ let(:io) { capture_io { subject }.join }
59
+
60
+ it { io.must_be_instance_of(String) }
61
+ end
62
+ end
63
+
64
+ describe '#width' do
65
+ subject { instance.width }
66
+
67
+ it { subject.must_be_instance_of(Fixnum) }
68
+ end
69
+
70
+ describe '#height' do
71
+ subject { instance.height }
72
+
73
+ it { subject.must_be_instance_of(Fixnum) }
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,63 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Interfaces do
5
+ let(:described_class) { Interfaces }
6
+ let(:instance) { described_class.new }
7
+ let(:block) {}
8
+
9
+ it { instance.must_be_instance_of(Interfaces) }
10
+
11
+ describe '.default' do
12
+ subject { described_class.default }
13
+
14
+ it { subject.must_be_instance_of(Interfaces) }
15
+
16
+ it 'adds the dummy interface to the interface list' do
17
+ subject.show.wont_be_empty
18
+ end
19
+ end
20
+
21
+ describe '.define' do
22
+ subject { described_class.define }
23
+
24
+ it { subject.must_be_instance_of(Interfaces) }
25
+ end
26
+
27
+ describe '#add' do
28
+ let(:interface_name) {}
29
+ let(:klass) { Class }
30
+ let(:options) { {} }
31
+
32
+ subject { instance.add(interface_name, klass, options) }
33
+
34
+ it { subject.must_be_instance_of(Hash) }
35
+
36
+ it { subject.wont_be_empty }
37
+
38
+ context 'when the interface class does not exist' do
39
+ before { Object.stubs(:const_defined?).returns(false) }
40
+
41
+ it { proc { subject }.must_raise(UndefinedInterface) }
42
+ end
43
+ end
44
+
45
+ describe '#show' do
46
+ subject { instance.show }
47
+
48
+ it { subject.must_be_instance_of(Hash) }
49
+ end
50
+
51
+ describe '#initial' do
52
+ subject { instance.initial }
53
+
54
+ it { subject.must_be_instance_of(Array) }
55
+ end
56
+
57
+ describe '#main' do
58
+ subject { instance.main }
59
+
60
+ it { subject.must_be_instance_of(Array) }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,10 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Background do
5
+ let(:described_class) { Background }
6
+ let(:instance) { described_class.new }
7
+
8
+ it { instance.must_be_instance_of(Background) }
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Base do
5
+ let(:described_class) { Base }
6
+ let(:instance) { described_class.new }
7
+
8
+ it { instance.must_be_instance_of(Base) }
9
+ end
10
+ end
@@ -0,0 +1,67 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Colour do
5
+ let(:described_class) { Colour }
6
+ let(:instance) { described_class.new }
7
+ let(:pair) { [] }
8
+
9
+ it { instance.must_be_instance_of(Colour) }
10
+
11
+ describe '.set' do
12
+ subject { described_class.set(pair) }
13
+
14
+ it { subject.must_be_instance_of(String) }
15
+
16
+ context 'when the foreground and background are specified as symbols' do
17
+ context 'when both the foreground and background is specified' do
18
+ let(:pair) { [:red, :yellow] }
19
+
20
+ it 'returns the code for red on yellow' do
21
+ subject.must_equal("\e[38;5;31m\e[48;5;43m")
22
+ end
23
+ end
24
+
25
+ context 'when a foreground is specified' do
26
+ let(:pair) { [:blue] }
27
+
28
+ it 'returns the code for blue on default' do
29
+ subject.must_equal("\e[38;5;34m\e[48;5;49m")
30
+ end
31
+ end
32
+
33
+ context 'when a background is specified' do
34
+ let(:pair) { [nil, :cyan] }
35
+
36
+ it 'returns the code for default with cyan background' do
37
+ subject.must_equal("\e[38;5;39m\e[48;5;46m")
38
+ end
39
+ end
40
+
41
+ context 'when an invalid foreground/background is specified' do
42
+ let(:pair) { [:melon, :raspberry] }
43
+
44
+ it 'returns the default code' do
45
+ subject.must_equal("\e[38;5;39m\e[48;5;49m")
46
+ end
47
+ end
48
+
49
+ context 'when no foreground/background is specified' do
50
+ let(:pair) { [] }
51
+
52
+ it 'returns the reset code' do
53
+ subject.must_equal("\e[38;5;39m\e[48;5;49m")
54
+ end
55
+ end
56
+ end
57
+
58
+ context 'when the foreground and background are specified as strings' do
59
+ let(:pair) { ['#ff0000', '#0000ff'] }
60
+
61
+ it 'returns the default code' do
62
+ subject.must_equal("\e[38;5;196m\e[48;5;21m")
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,106 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Compositor do
5
+ let(:described_class) { Compositor }
6
+ let(:instance) { described_class.new(rows) }
7
+ let(:rows) { [[]] }
8
+
9
+ before { Terminal.stubs(:output) }
10
+
11
+ it { instance.must_be_instance_of(Compositor) }
12
+
13
+ describe '.write' do
14
+ subject { described_class.write(rows) }
15
+
16
+ it { subject.must_be_instance_of(String) }
17
+
18
+ context 'when empty' do
19
+ let(:rows) { [] }
20
+
21
+ it { subject.must_be_instance_of(NilClass) }
22
+ end
23
+
24
+ context 'when unstyled' do
25
+ context 'and a single line' do
26
+ let(:rows) { [['Some text...']] }
27
+
28
+ it { subject.must_equal('Some text...') }
29
+ end
30
+
31
+ context 'and multi-line' do
32
+ let(:rows) {
33
+ [
34
+ ['Some text...'],
35
+ ['Some more text...']
36
+ ]
37
+ }
38
+
39
+ it { subject.must_equal("Some text...\nSome more text...") }
40
+ end
41
+ end
42
+
43
+ context 'when styled' do
44
+ context 'with colour pair' do
45
+ context 'and a single line' do
46
+ let(:rows) {
47
+ [
48
+ [[:red, :white], 'Some text...']
49
+ ]
50
+ }
51
+
52
+ it { subject.must_equal("\e[38;5;31m\e[48;5;47mSome text...") }
53
+ end
54
+
55
+ context 'and multi-line' do
56
+ let(:rows) {
57
+ [
58
+ [[:red, :white], 'Some text...'],
59
+ [[:blue, :yellow], 'Some more text...']
60
+ ]
61
+ }
62
+
63
+ it { subject.must_equal("\e[38;5;31m\e[48;5;47mSome text...\n" \
64
+ "\e[38;5;34m\e[48;5;43mSome more text...") }
65
+ end
66
+ end
67
+
68
+ context 'with a style' do
69
+ context 'and a single line' do
70
+ let(:rows) {
71
+ [
72
+ [:bold, 'Some text...']
73
+ ]
74
+ }
75
+
76
+ it { subject.must_equal("\e[1mSome text...") }
77
+ end
78
+
79
+ context 'and multi-line' do
80
+ let(:rows) {
81
+ [
82
+ [:inverse, 'Some text...'],
83
+ [:underline, 'Some more text...']
84
+ ]
85
+ }
86
+
87
+ it { subject.must_equal("\e[7mSome text...\n" \
88
+ "\e[4mSome more text...") }
89
+ end
90
+ end
91
+
92
+ context 'with an unknown style' do
93
+ let(:rows) {
94
+ [
95
+ [:unknown, 'Some text...']
96
+ ]
97
+ }
98
+
99
+ it 'renders in the default style' do
100
+ subject.must_equal("Some text...")
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Directive do
5
+ let(:described_class) { Directive }
6
+ let(:instance) { described_class.new(directive) }
7
+ let(:directive) {}
8
+
9
+ it { instance.must_be_instance_of(Directive) }
10
+
11
+ describe '.enact' do
12
+ subject { described_class.enact(directive) }
13
+
14
+ context 'when the directive is invalid' do
15
+ it 'raises an exception' do
16
+ proc { subject }.must_raise(InvalidDirective)
17
+ end
18
+ end
19
+
20
+ context 'when the directive is valid' do
21
+ context 'when the directive is a collection' do
22
+ let(:directive) { [] }
23
+
24
+ context 'and the first element is a number' do
25
+ let(:directive) { [0, 0] }
26
+
27
+ before { Position.stubs(:set) }
28
+
29
+ it 'must be a position' do
30
+ skip
31
+ end
32
+ end
33
+
34
+ context 'and the first element is a symbol' do
35
+ let(:directive) { [:default, :default] }
36
+
37
+ before { Colour.stubs(:set) }
38
+
39
+ it 'must be a colour' do
40
+ skip
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'when the directive is individual' do
46
+ let(:directive) { :normal }
47
+
48
+ it 'must be a style' do
49
+ skip
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,71 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Esc do
5
+ let(:described_class) { Esc }
6
+
7
+ describe '.bold' do
8
+ subject { described_class.bold }
9
+
10
+ it { subject.must_be_instance_of(String) }
11
+
12
+ it { subject.must_equal("\e[1m") }
13
+ end
14
+
15
+ describe '.clear' do
16
+ subject { described_class.clear }
17
+
18
+ it { subject.must_be_instance_of(String) }
19
+
20
+ it { subject.must_equal("\e[2J") }
21
+ end
22
+
23
+ describe '.esc' do
24
+ subject { described_class.esc }
25
+
26
+ it { subject.must_be_instance_of(String) }
27
+
28
+ it { subject.must_equal("\e[") }
29
+ end
30
+
31
+ describe '.hide_cursor' do
32
+ subject { described_class.hide_cursor }
33
+
34
+ it { subject.must_be_instance_of(String) }
35
+
36
+ it { subject.must_equal("\e[?25l") }
37
+ end
38
+
39
+ describe '.inverse' do
40
+ subject { described_class.inverse }
41
+
42
+ it { subject.must_be_instance_of(String) }
43
+
44
+ it { subject.must_equal("\e[7m") }
45
+ end
46
+
47
+ describe '.reset' do
48
+ subject { described_class.reset }
49
+
50
+ it { subject.must_be_instance_of(String) }
51
+
52
+ it { subject.must_equal("\e[0m") }
53
+ end
54
+
55
+ describe '.show_cursor' do
56
+ subject { described_class.show_cursor }
57
+
58
+ it { subject.must_be_instance_of(String) }
59
+
60
+ it { subject.must_equal("\e[?25h") }
61
+ end
62
+
63
+ describe '.underline' do
64
+ subject { described_class.underline }
65
+
66
+ it { subject.must_be_instance_of(String) }
67
+
68
+ it { subject.must_equal("\e[4m") }
69
+ end
70
+ end
71
+ end