vedeu 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Guardfile +1 -1
- data/README.md +14 -0
- data/lib/vedeu.rb +1 -0
- data/lib/vedeu/interface/dummy.rb +13 -0
- data/lib/vedeu/interface/interface.rb +1 -1
- data/lib/vedeu/interface/interfaces.rb +10 -9
- data/lib/vedeu/output/colour.rb +2 -0
- data/lib/vedeu/output/compositor.rb +3 -23
- data/lib/vedeu/output/directive.rb +27 -14
- data/lib/vedeu/output/geometry.rb +6 -1
- data/lib/vedeu/output/position.rb +8 -3
- data/lib/vedeu/output/wordwrap.rb +84 -0
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/application_test.rb +15 -5
- data/test/lib/vedeu/interface/dummy_test.rb +5 -5
- data/test/lib/vedeu/interface/interface_test.rb +17 -7
- data/test/lib/vedeu/interface/interfaces_test.rb +29 -20
- data/test/lib/vedeu/output/background_test.rb +40 -3
- data/test/lib/vedeu/output/base_test.rb +2 -4
- data/test/lib/vedeu/output/colour_test.rb +6 -6
- data/test/lib/vedeu/output/compositor_test.rb +15 -15
- data/test/lib/vedeu/output/directive_test.rb +36 -35
- data/test/lib/vedeu/output/esc_test.rb +9 -9
- data/test/lib/vedeu/output/foreground_test.rb +39 -2
- data/test/lib/vedeu/output/geometry_test.rb +51 -7
- data/test/lib/vedeu/output/position_test.rb +15 -6
- data/test/lib/vedeu/output/renderer_test.rb +19 -1
- data/test/lib/vedeu/output/style_test.rb +1 -2
- data/test/lib/vedeu/output/wordwrap_test.rb +59 -0
- data/test/lib/vedeu/process/command_test.rb +8 -8
- data/test/lib/vedeu/process/commands_test.rb +27 -7
- data/test/lib/vedeu/process/exit_test.rb +1 -1
- data/test/lib/vedeu/support/terminal_test.rb +27 -24
- data/test/test_helper.rb +1 -1
- data/vedeu.gemspec +5 -5
- metadata +21 -19
@@ -10,38 +10,47 @@ module Vedeu
|
|
10
10
|
describe Interfaces do
|
11
11
|
let(:described_class) { Interfaces }
|
12
12
|
|
13
|
-
describe '.
|
14
|
-
subject { described_class.
|
15
|
-
|
16
|
-
it { subject.must_be_instance_of(Hash) }
|
13
|
+
describe '.define' do
|
14
|
+
let(:subject) { described_class.define }
|
17
15
|
|
18
|
-
it
|
19
|
-
described_class.list.wont_be_empty
|
20
|
-
end
|
16
|
+
it { subject.must_be_instance_of(Module) }
|
21
17
|
end
|
22
18
|
|
23
19
|
describe '.defined' do
|
24
|
-
subject { described_class.defined }
|
20
|
+
let(:subject) { described_class.defined }
|
21
|
+
|
22
|
+
after { described_class.interfaces = {} }
|
23
|
+
|
24
|
+
context 'when interfaces are not defined' do
|
25
|
+
before { described_class.interfaces = {} }
|
26
|
+
|
27
|
+
it { subject.must_be_instance_of(NilClass) }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when no interfaces are defined' do
|
31
|
+
before { described_class.interfaces = { mock: :interface } }
|
25
32
|
|
26
|
-
|
33
|
+
it { subject.must_be_instance_of(Module) }
|
34
|
+
end
|
27
35
|
end
|
28
36
|
|
29
|
-
describe '.
|
30
|
-
subject { described_class.
|
37
|
+
describe '.default' do
|
38
|
+
let(:subject) { described_class.default }
|
31
39
|
|
32
40
|
it { subject.must_be_instance_of(Module) }
|
41
|
+
|
42
|
+
it 'adds the dummy interface to the interface list' do
|
43
|
+
described_class.list.wont_be_empty
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
47
|
describe '.add' do
|
48
|
+
let(:subject) { described_class.add(interface, klass, options) }
|
36
49
|
let(:interface) {}
|
37
50
|
let(:klass) { DummyInterface }
|
38
51
|
let(:options) { {} }
|
39
52
|
|
40
|
-
|
41
|
-
|
42
|
-
it { subject.must_be_instance_of(Hash) }
|
43
|
-
|
44
|
-
it { subject.wont_be_empty }
|
53
|
+
it { subject.must_be_instance_of(Module) }
|
45
54
|
|
46
55
|
context 'when the interface class does not exist' do
|
47
56
|
before { Object.stubs(:const_defined?).returns(false) }
|
@@ -51,25 +60,25 @@ module Vedeu
|
|
51
60
|
end
|
52
61
|
|
53
62
|
describe '.list' do
|
54
|
-
subject { described_class.list }
|
63
|
+
let(:subject) { described_class.list }
|
55
64
|
|
56
65
|
it { subject.must_be_instance_of(String) }
|
57
66
|
end
|
58
67
|
|
59
68
|
describe '.initial_state' do
|
60
|
-
subject { described_class.initial_state }
|
69
|
+
let(:subject) { described_class.initial_state }
|
61
70
|
|
62
71
|
it { subject.must_be_instance_of(Array) }
|
63
72
|
end
|
64
73
|
|
65
74
|
describe '.event_loop' do
|
75
|
+
let(:subject) { described_class.event_loop }
|
76
|
+
|
66
77
|
before do
|
67
78
|
Terminal.stubs(:input)
|
68
79
|
Commands.stubs(:execute).returns(:stop)
|
69
80
|
end
|
70
81
|
|
71
|
-
subject { described_class.event_loop }
|
72
|
-
|
73
82
|
it { subject.must_be_instance_of(Array) }
|
74
83
|
end
|
75
84
|
end
|
@@ -2,9 +2,46 @@ require_relative '../../../test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Background do
|
5
|
-
let(:described_class)
|
6
|
-
let(:
|
5
|
+
let(:described_class) { Background }
|
6
|
+
let(:described_instance) { described_class.new(colour) }
|
7
|
+
let(:colour) {}
|
7
8
|
|
8
|
-
it {
|
9
|
+
it { described_instance.must_be_instance_of(Background) }
|
10
|
+
|
11
|
+
describe '#escape_sequence' do
|
12
|
+
let(:subject) { described_instance.escape_sequence }
|
13
|
+
|
14
|
+
it { subject.must_be_instance_of(String) }
|
15
|
+
|
16
|
+
context 'with no colour' do
|
17
|
+
it { subject.must_be_instance_of(String) }
|
18
|
+
|
19
|
+
it { subject.must_equal("\e[48;5;49m") }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a named colour' do
|
23
|
+
let(:colour) { :red }
|
24
|
+
|
25
|
+
it { subject.must_be_instance_of(String) }
|
26
|
+
|
27
|
+
it { subject.must_equal("\e[48;5;41m") }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with a html colour' do
|
31
|
+
let(:colour) { '#aadd00' }
|
32
|
+
|
33
|
+
it { subject.must_be_instance_of(String) }
|
34
|
+
|
35
|
+
it { subject.must_equal("\e[48;5;148m") }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with a default colour' do
|
39
|
+
let(:colour) { :undefined }
|
40
|
+
|
41
|
+
it { subject.must_be_instance_of(String) }
|
42
|
+
|
43
|
+
it { subject.must_equal("\e[48;5;49m") }
|
44
|
+
end
|
45
|
+
end
|
9
46
|
end
|
10
47
|
end
|
@@ -2,9 +2,7 @@ require_relative '../../../test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Base do
|
5
|
-
let(:described_class)
|
6
|
-
let(:
|
7
|
-
|
8
|
-
it { instance.must_be_instance_of(Base) }
|
5
|
+
let(:described_class) { Base }
|
6
|
+
let(:described_instance) { described_class.new }
|
9
7
|
end
|
10
8
|
end
|
@@ -3,13 +3,13 @@ require_relative '../../../test_helper'
|
|
3
3
|
module Vedeu
|
4
4
|
describe Colour do
|
5
5
|
let(:described_class) { Colour }
|
6
|
-
let(:
|
7
|
-
let(:pair)
|
6
|
+
let(:described_instance) { described_class.new }
|
7
|
+
let(:pair) { [] }
|
8
8
|
|
9
|
-
it {
|
9
|
+
it { described_instance.must_be_instance_of(Colour) }
|
10
10
|
|
11
11
|
describe '.set' do
|
12
|
-
subject { described_class.set(pair) }
|
12
|
+
let(:subject) { described_class.set(pair) }
|
13
13
|
|
14
14
|
it { subject.must_be_instance_of(String) }
|
15
15
|
|
@@ -49,8 +49,8 @@ module Vedeu
|
|
49
49
|
context 'when no foreground/background is specified' do
|
50
50
|
let(:pair) { [] }
|
51
51
|
|
52
|
-
it '
|
53
|
-
subject.must_equal(
|
52
|
+
it 'return an empty string' do
|
53
|
+
subject.must_equal('')
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -2,11 +2,11 @@ require_relative '../../../test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Compositor do
|
5
|
-
let(:described_class)
|
6
|
-
let(:
|
7
|
-
let(:output)
|
8
|
-
let(:stream)
|
9
|
-
let(:interface)
|
5
|
+
let(:described_class) { Compositor }
|
6
|
+
let(:described_instance) { described_class.new(output, interface) }
|
7
|
+
let(:output) { [[]] }
|
8
|
+
let(:stream) {}
|
9
|
+
let(:interface) {
|
10
10
|
Vedeu::Interface.new({
|
11
11
|
geometry: {
|
12
12
|
y: 2,
|
@@ -22,10 +22,10 @@ module Vedeu
|
|
22
22
|
Renderer.stubs(:write).returns(stream)
|
23
23
|
end
|
24
24
|
|
25
|
-
it {
|
25
|
+
it { described_instance.must_be_instance_of(Compositor) }
|
26
26
|
|
27
|
-
describe '.
|
28
|
-
subject { described_class.
|
27
|
+
describe '.arrange' do
|
28
|
+
let(:subject) { described_class.arrange(output, interface) }
|
29
29
|
|
30
30
|
context 'when empty' do
|
31
31
|
let(:output) { [] }
|
@@ -59,7 +59,7 @@ module Vedeu
|
|
59
59
|
context 'and a single line' do
|
60
60
|
let(:output) {
|
61
61
|
[
|
62
|
-
[[:red, :white], 'Some text...']
|
62
|
+
[{ colour: [:red, :white] }, 'Some text...']
|
63
63
|
]
|
64
64
|
}
|
65
65
|
let(:stream) { "\e[38;5;31m\e[48;5;47mSome text..." }
|
@@ -70,8 +70,8 @@ module Vedeu
|
|
70
70
|
context 'and multi-line' do
|
71
71
|
let(:output) {
|
72
72
|
[
|
73
|
-
[[:red, :white], 'Some text...'],
|
74
|
-
[[:blue, :yellow], 'Some more text...']
|
73
|
+
[{ colour: [:red, :white] }, 'Some text...'],
|
74
|
+
[{ colour: [:blue, :yellow] }, 'Some more text...']
|
75
75
|
]
|
76
76
|
}
|
77
77
|
let(:stream) {
|
@@ -87,7 +87,7 @@ module Vedeu
|
|
87
87
|
context 'and a single line' do
|
88
88
|
let(:output) {
|
89
89
|
[
|
90
|
-
[:bold, 'Some text...']
|
90
|
+
[{ style: :bold }, 'Some text...']
|
91
91
|
]
|
92
92
|
}
|
93
93
|
let(:stream) {
|
@@ -100,8 +100,8 @@ module Vedeu
|
|
100
100
|
context 'and multi-line' do
|
101
101
|
let(:output) {
|
102
102
|
[
|
103
|
-
[:inverse, 'Some text...'],
|
104
|
-
[:underline, 'Some more text...']
|
103
|
+
[{ style: :inverse }, 'Some text...'],
|
104
|
+
[{ style: :underline }, 'Some more text...']
|
105
105
|
]
|
106
106
|
}
|
107
107
|
let(:stream) {
|
@@ -116,7 +116,7 @@ module Vedeu
|
|
116
116
|
context 'with an unknown style' do
|
117
117
|
let(:output) {
|
118
118
|
[
|
119
|
-
[:unknown, 'Some text...']
|
119
|
+
[{ style: :unknown }, 'Some text...']
|
120
120
|
]
|
121
121
|
}
|
122
122
|
let(:stream) {
|
@@ -2,53 +2,54 @@ require_relative '../../../test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Directive do
|
5
|
-
let(:described_class)
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
|
9
|
-
|
5
|
+
let(:described_class) { Directive }
|
6
|
+
let(:described_instance) { described_class.new(directives) }
|
7
|
+
let(:directives) {
|
8
|
+
{
|
9
|
+
position: position,
|
10
|
+
colour: colour,
|
11
|
+
style: style
|
12
|
+
}
|
13
|
+
}
|
14
|
+
let(:position) { [] }
|
15
|
+
let(:colour) { [] }
|
16
|
+
let(:style) { [] }
|
17
|
+
|
18
|
+
it { described_instance.must_be_instance_of(Directive) }
|
10
19
|
|
11
20
|
describe '.enact' do
|
12
|
-
subject { described_class.enact(
|
21
|
+
let(:subject) { described_class.enact(directives) }
|
13
22
|
|
14
|
-
|
15
|
-
it 'raises an exception' do
|
16
|
-
proc { subject }.must_raise(InvalidDirective)
|
17
|
-
end
|
18
|
-
end
|
23
|
+
it { subject.must_be_instance_of(String) }
|
19
24
|
|
20
|
-
context 'when the
|
21
|
-
|
22
|
-
|
25
|
+
context 'when the position is not set' do
|
26
|
+
it { subject.must_equal('') }
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
context 'when the position is set' do
|
30
|
+
let(:position) { [4, 5] }
|
26
31
|
|
27
|
-
|
32
|
+
it { subject.must_equal("\e[5;6H") }
|
33
|
+
end
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
35
|
+
context 'when the colour is not set' do
|
36
|
+
it { subject.must_equal('') }
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
39
|
+
context 'when the colour is set' do
|
40
|
+
let(:colour) { [:red, :black] }
|
36
41
|
|
37
|
-
|
42
|
+
it { subject.must_equal("\e[38;5;31m\e[48;5;40m") }
|
43
|
+
end
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
45
|
+
context 'when the style is not set' do
|
46
|
+
it { subject.must_equal('') }
|
47
|
+
end
|
44
48
|
|
45
|
-
|
46
|
-
|
49
|
+
context 'when the style is set' do
|
50
|
+
let(:style) { [:normal, :underline, :normal] }
|
47
51
|
|
48
|
-
|
49
|
-
skip
|
50
|
-
end
|
51
|
-
end
|
52
|
+
it { subject.must_equal("\e[0m\e[4m\e[0m") }
|
52
53
|
end
|
53
54
|
end
|
54
55
|
end
|
@@ -2,10 +2,10 @@ require_relative '../../../test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Esc do
|
5
|
-
let(:described_class)
|
5
|
+
let(:described_class) { Esc }
|
6
6
|
|
7
7
|
describe '.bold' do
|
8
|
-
subject { described_class.bold }
|
8
|
+
let(:subject) { described_class.bold }
|
9
9
|
|
10
10
|
it { subject.must_be_instance_of(String) }
|
11
11
|
|
@@ -13,7 +13,7 @@ module Vedeu
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '.clear' do
|
16
|
-
subject { described_class.clear }
|
16
|
+
let(:subject) { described_class.clear }
|
17
17
|
|
18
18
|
it { subject.must_be_instance_of(String) }
|
19
19
|
|
@@ -21,7 +21,7 @@ module Vedeu
|
|
21
21
|
end
|
22
22
|
|
23
23
|
describe '.esc' do
|
24
|
-
subject { described_class.esc }
|
24
|
+
let(:subject) { described_class.esc }
|
25
25
|
|
26
26
|
it { subject.must_be_instance_of(String) }
|
27
27
|
|
@@ -29,7 +29,7 @@ module Vedeu
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '.hide_cursor' do
|
32
|
-
subject { described_class.hide_cursor }
|
32
|
+
let(:subject) { described_class.hide_cursor }
|
33
33
|
|
34
34
|
it { subject.must_be_instance_of(String) }
|
35
35
|
|
@@ -37,7 +37,7 @@ module Vedeu
|
|
37
37
|
end
|
38
38
|
|
39
39
|
describe '.inverse' do
|
40
|
-
subject { described_class.inverse }
|
40
|
+
let(:subject) { described_class.inverse }
|
41
41
|
|
42
42
|
it { subject.must_be_instance_of(String) }
|
43
43
|
|
@@ -45,7 +45,7 @@ module Vedeu
|
|
45
45
|
end
|
46
46
|
|
47
47
|
describe '.reset' do
|
48
|
-
subject { described_class.reset }
|
48
|
+
let(:subject) { described_class.reset }
|
49
49
|
|
50
50
|
it { subject.must_be_instance_of(String) }
|
51
51
|
|
@@ -53,7 +53,7 @@ module Vedeu
|
|
53
53
|
end
|
54
54
|
|
55
55
|
describe '.show_cursor' do
|
56
|
-
subject { described_class.show_cursor }
|
56
|
+
let(:subject) { described_class.show_cursor }
|
57
57
|
|
58
58
|
it { subject.must_be_instance_of(String) }
|
59
59
|
|
@@ -61,7 +61,7 @@ module Vedeu
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe '.underline' do
|
64
|
-
subject { described_class.underline }
|
64
|
+
let(:subject) { described_class.underline }
|
65
65
|
|
66
66
|
it { subject.must_be_instance_of(String) }
|
67
67
|
|
@@ -3,8 +3,45 @@ require_relative '../../../test_helper'
|
|
3
3
|
module Vedeu
|
4
4
|
describe Foreground do
|
5
5
|
let(:described_class) { Foreground }
|
6
|
-
let(:
|
6
|
+
let(:described_instance) { described_class.new(colour) }
|
7
|
+
let(:colour) {}
|
7
8
|
|
8
|
-
it {
|
9
|
+
it { described_instance.must_be_instance_of(Foreground) }
|
10
|
+
|
11
|
+
describe '#escape_sequence' do
|
12
|
+
let(:subject) { described_instance.escape_sequence }
|
13
|
+
|
14
|
+
it { subject.must_be_instance_of(String) }
|
15
|
+
|
16
|
+
context 'with no colour' do
|
17
|
+
it { subject.must_be_instance_of(String) }
|
18
|
+
|
19
|
+
it { subject.must_equal("\e[38;5;39m") }
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with a named colour' do
|
23
|
+
let(:colour) { :red }
|
24
|
+
|
25
|
+
it { subject.must_be_instance_of(String) }
|
26
|
+
|
27
|
+
it { subject.must_equal("\e[38;5;31m") }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'with a html colour' do
|
31
|
+
let(:colour) { '#aadd00' }
|
32
|
+
|
33
|
+
it { subject.must_be_instance_of(String) }
|
34
|
+
|
35
|
+
it { subject.must_equal("\e[38;5;148m") }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with a default colour' do
|
39
|
+
let(:colour) { :undefined }
|
40
|
+
|
41
|
+
it { subject.must_be_instance_of(String) }
|
42
|
+
|
43
|
+
it { subject.must_equal("\e[38;5;39m") }
|
44
|
+
end
|
45
|
+
end
|
9
46
|
end
|
10
47
|
end
|