vedeu 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -5
  3. data/lib/vedeu.rb +6 -6
  4. data/lib/vedeu/application.rb +1 -1
  5. data/lib/vedeu/{process → input}/input.rb +0 -0
  6. data/lib/vedeu/output/background.rb +6 -2
  7. data/lib/vedeu/output/base.rb +8 -0
  8. data/lib/vedeu/output/compositor.rb +1 -1
  9. data/lib/vedeu/output/cursor.rb +49 -53
  10. data/lib/vedeu/output/esc.rb +40 -40
  11. data/lib/vedeu/output/foreground.rb +6 -2
  12. data/lib/vedeu/output/output.rb +19 -0
  13. data/lib/vedeu/process/process.rb +1 -1
  14. data/lib/vedeu/repository/interface.rb +12 -5
  15. data/lib/vedeu/repository/interface_repository.rb +8 -8
  16. data/lib/vedeu/{process → support}/event_loop.rb +0 -0
  17. data/lib/vedeu/{process → support}/exit.rb +0 -0
  18. data/lib/vedeu/{process → support}/queue.rb +4 -0
  19. data/lib/vedeu/support/terminal.rb +2 -0
  20. data/lib/vedeu/version.rb +1 -1
  21. data/test/lib/vedeu/application_test.rb +1 -1
  22. data/test/lib/vedeu/{process → input}/input_test.rb +0 -0
  23. data/test/lib/vedeu/output/background_test.rb +1 -1
  24. data/test/lib/vedeu/output/colour_test.rb +2 -2
  25. data/test/lib/vedeu/output/compositor_test.rb +50 -35
  26. data/test/lib/vedeu/output/cursor_test.rb +0 -12
  27. data/test/lib/vedeu/output/foreground_test.rb +1 -1
  28. data/test/lib/vedeu/output/output_test.rb +26 -0
  29. data/test/lib/vedeu/process/process_test.rb +7 -3
  30. data/test/lib/vedeu/repository/interface_repository_test.rb +4 -10
  31. data/test/lib/vedeu/repository/interface_test.rb +4 -6
  32. data/test/lib/vedeu/{process → support}/event_loop_test.rb +0 -0
  33. data/test/lib/vedeu/{process → support}/exit_test.rb +0 -0
  34. data/test/lib/vedeu/{process → support}/queue_test.rb +25 -6
  35. data/test/lib/vedeu/support/terminal_test.rb +35 -43
  36. metadata +17 -20
  37. data/lib/vedeu/output/renderer.rb +0 -21
  38. data/lib/vedeu/process/output.rb +0 -25
  39. data/test/lib/vedeu/output/renderer_test.rb +0 -37
  40. data/test/lib/vedeu/process/output_test.rb +0 -41
@@ -7,6 +7,8 @@ module Vedeu
7
7
 
8
8
  def output(stream = '')
9
9
  console.print(stream)
10
+
11
+ stream
10
12
  end
11
13
 
12
14
  def width
data/lib/vedeu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
@@ -15,7 +15,7 @@ module Vedeu
15
15
 
16
16
  before do
17
17
  Terminal.stubs(:open).yields(self)
18
- InterfaceRepository.stubs(:initial_state)
18
+ Output.stubs(:render)
19
19
  EventLoop.stubs(:main_sequence)
20
20
  Terminal.stubs(:close)
21
21
  end
File without changes
@@ -23,7 +23,7 @@ module Vedeu
23
23
  end
24
24
 
25
25
  it 'returns an escape sequence' do
26
- subject.must_equal("\e[48;5;49m")
26
+ subject.must_equal("\e[48;2;49m")
27
27
  end
28
28
  end
29
29
 
@@ -35,7 +35,7 @@ module Vedeu
35
35
  let(:pair) { [:blue] }
36
36
 
37
37
  it 'returns the code for blue on default' do
38
- subject.must_equal("\e[38;2;34m\e[48;5;49m")
38
+ subject.must_equal("\e[38;2;34m\e[48;2;49m")
39
39
  end
40
40
  end
41
41
 
@@ -43,7 +43,7 @@ module Vedeu
43
43
  let(:pair) { [nil, :cyan] }
44
44
 
45
45
  it 'returns the code for default with cyan background' do
46
- subject.must_equal("\e[38;5;39m\e[48;2;46m")
46
+ subject.must_equal("\e[38;2;39m\e[48;2;46m")
47
47
  end
48
48
  end
49
49
 
@@ -10,9 +10,8 @@ module Vedeu
10
10
  let(:interface) { 'dummy' }
11
11
 
12
12
  before do
13
- Interface.create({ name: 'dummy' })
14
- Interface.create({ name: 'test_interface' })
15
- Renderer.stubs(:write).returns(stream)
13
+ Interface.create({ name: 'dummy', width: 15, height: 2 })
14
+ Interface.create({ name: 'test_interface', width: 15, height: 2 })
16
15
  end
17
16
 
18
17
  after do
@@ -60,22 +59,28 @@ module Vedeu
60
59
 
61
60
  context 'when unstyled' do
62
61
  context 'and a single line' do
63
- let(:output) { [['Some text...']] }
64
- let(:stream) { 'Some text...' }
62
+ let(:output) { { 'dummy' => [['Some text...']] } }
63
+ let(:stream) {
64
+ [[["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1HSome text...\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"], ["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"]]]
65
+ }
65
66
 
66
- it 'returns a String' do
67
+ it 'returns the enqueue composition' do
67
68
  subject.must_equal(stream)
68
69
  end
69
70
  end
70
71
 
71
72
  context 'and multi-line' do
72
73
  let(:output) {
73
- [
74
- ['Some text...'],
75
- ['Some more text...']
76
- ]
74
+ {
75
+ 'dummy' => [
76
+ ['Some text...'],
77
+ ['Some more text...']
78
+ ]
79
+ }
80
+ }
81
+ let(:stream) {
82
+ [[["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1HSome text...\e[2;1H \e[2;1H", "\e[1;1H \e[1;1HSome more tex...\e[0m\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"], ["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"]]]
77
83
  }
78
- let(:stream) { "Some text...\nSome more text..." }
79
84
 
80
85
  it 'returns a String' do
81
86
  subject.must_equal(stream)
@@ -87,11 +92,15 @@ module Vedeu
87
92
  context 'with colour pair' do
88
93
  context 'and a single line' do
89
94
  let(:output) {
90
- [
91
- [{ colour: [:red, :white] }, 'Some text...']
92
- ]
95
+ {
96
+ 'dummy' => [
97
+ [{ colour: [:red, :white] }, 'Some text...']
98
+ ]
99
+ }
100
+ }
101
+ let(:stream) {
102
+ [[["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[38;2;31m\e[48;2;47m\e[2;1H \e[2;1HSome text...", "\e[38;2;39m\e[48;2;49m", "\e[?25h"], ["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"]]]
93
103
  }
94
- let(:stream) { "\e[38;5;31m\e[48;5;47mSome text..." }
95
104
 
96
105
  it 'returns a String' do
97
106
  subject.must_equal(stream)
@@ -100,14 +109,15 @@ module Vedeu
100
109
 
101
110
  context 'and multi-line' do
102
111
  let(:output) {
103
- [
104
- [{ colour: [:red, :white] }, 'Some text...'],
105
- [{ colour: [:blue, :yellow] }, 'Some more text...']
106
- ]
112
+ {
113
+ 'dummy' => [
114
+ [{ colour: [:red, :white] }, 'Some text...'],
115
+ [{ colour: [:blue, :yellow] }, 'Some more text...']
116
+ ]
117
+ }
107
118
  }
108
119
  let(:stream) {
109
- "\e[38;5;31m\e[48;5;47mSome text...\n" \
110
- "\e[38;5;34m\e[48;5;43mSome more text..."
120
+ [[["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[38;2;31m\e[48;2;47m\e[2;1H \e[2;1HSome text...", "\e[1;1H \e[1;1H\e[38;2;34m\e[48;2;43m\e[2;1H \e[2;1HSome more tex...\e[0m", "\e[38;2;39m\e[48;2;49m", "\e[?25h"], ["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"]]]
111
121
  }
112
122
 
113
123
  it 'returns a String' do
@@ -119,12 +129,14 @@ module Vedeu
119
129
  context 'with a style' do
120
130
  context 'and a single line' do
121
131
  let(:output) {
122
- [
123
- [{ style: :bold }, 'Some text...']
124
- ]
132
+ {
133
+ 'dummy' => [
134
+ [{ style: :bold }, 'Some text...']
135
+ ]
136
+ }
125
137
  }
126
138
  let(:stream) {
127
- "\e[1mSome text..."
139
+ [[["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[1m\e[2;1H \e[2;1HSome text...", "\e[38;2;39m\e[48;2;49m", "\e[?25h"], ["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"]]]
128
140
  }
129
141
 
130
142
  it 'returns a String' do
@@ -134,14 +146,15 @@ module Vedeu
134
146
 
135
147
  context 'and multi-line' do
136
148
  let(:output) {
137
- [
138
- [{ style: :inverse }, 'Some text...'],
139
- [{ style: :underline }, 'Some more text...']
140
- ]
149
+ {
150
+ 'dummy' => [
151
+ [{ style: :inverse }, 'Some text...'],
152
+ [{ style: :underline }, 'Some more text...']
153
+ ]
154
+ }
141
155
  }
142
156
  let(:stream) {
143
- "\e[7mSome text...\n" \
144
- "\e[4mSome more text..."
157
+ [[["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[7m\e[2;1H \e[2;1HSome text...", "\e[1;1H \e[1;1H\e[4m\e[2;1H \e[2;1HSome more tex...\e[0m", "\e[38;2;39m\e[48;2;49m", "\e[?25h"], ["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"]]]
145
158
  }
146
159
 
147
160
  it 'returns a String' do
@@ -152,12 +165,14 @@ module Vedeu
152
165
 
153
166
  context 'with an unknown style' do
154
167
  let(:output) {
155
- [
156
- [{ style: :unknown }, 'Some text...']
157
- ]
168
+ {
169
+ 'dummy' => [
170
+ [{ style: :unknown }, 'Some text...']
171
+ ]
172
+ }
158
173
  }
159
174
  let(:stream) {
160
- "Some text..."
175
+ [[["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[2;1H \e[2;1HSome text...", "\e[38;2;39m\e[48;2;49m", "\e[?25h"], ["\e[38;2;39m\e[48;2;49m", "\e[1;1H \e[1;1H\e[2;1H \e[2;1H", "\e[38;2;39m\e[48;2;49m", "\e[?25h"]]]
161
176
  }
162
177
 
163
178
  it 'renders in the default style' do
@@ -171,17 +171,5 @@ module Vedeu
171
171
  subject.must_equal("\e[8")
172
172
  end
173
173
  end
174
-
175
- describe '.esc' do
176
- let(:subject) { described_class.esc }
177
-
178
- it 'returns a String' do
179
- subject.must_be_instance_of(String)
180
- end
181
-
182
- it 'returns an escape sequence' do
183
- subject.must_equal("\e[")
184
- end
185
- end
186
174
  end
187
175
  end
@@ -23,7 +23,7 @@ module Vedeu
23
23
  end
24
24
 
25
25
  it 'returns an escape sequence' do
26
- subject.must_equal("\e[38;5;39m")
26
+ subject.must_equal("\e[38;2;39m")
27
27
  end
28
28
  end
29
29
 
@@ -0,0 +1,26 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Output do
5
+ let(:described_class) { Output }
6
+ let(:subject) { described_class.new }
7
+ let(:result) {}
8
+ let(:queued_result) { { 'dummy' => [['queued...']] } }
9
+
10
+ before do
11
+ Interface.create({ name: 'dummy', width: 10, height: 2, cursor: true })
12
+ end
13
+
14
+ after do
15
+ InterfaceRepository.reset
16
+ end
17
+
18
+ it 'returns an Output instance' do
19
+ subject.must_be_instance_of(Output)
20
+ end
21
+
22
+ describe '.render' do
23
+ let(:subject) { described_class.render }
24
+ end
25
+ end
26
+ end
@@ -16,13 +16,17 @@ module Vedeu
16
16
  let(:command) { Command.new }
17
17
 
18
18
  before do
19
+ Interface.create({ name: 'dummy' })
19
20
  Queue.stubs(:dequeue).returns(input)
20
21
  CommandRepository.stubs(:by_keypress).returns(command)
21
22
  CommandRepository.stubs(:by_keyword).returns(command)
22
23
  command.stubs(:execute).returns(result)
23
24
  end
24
25
 
25
- after { Queue.clear }
26
+ after do
27
+ InterfaceRepository.reset
28
+ Queue.clear
29
+ end
26
30
 
27
31
  context 'when there is no input' do
28
32
  it 'returns a NilClass' do
@@ -48,7 +52,7 @@ module Vedeu
48
52
  end
49
53
 
50
54
  context 'or the result is anything else' do
51
- let(:result) { :something_else }
55
+ let(:result) { { 'dummy' => [['output...']] } }
52
56
 
53
57
  it 'returns an Array' do
54
58
  subject.must_be_instance_of(Array)
@@ -74,7 +78,7 @@ module Vedeu
74
78
  end
75
79
 
76
80
  context 'or the result is anything else' do
77
- let(:result) { :something_else }
81
+ let(:result) { { 'dummy' => [['output...']] } }
78
82
 
79
83
  it 'returns an Array' do
80
84
  subject.must_be_instance_of(Array)
@@ -8,6 +8,8 @@ module Vedeu
8
8
 
9
9
  before { Interface.create({ name: 'dummy' }) }
10
10
 
11
+ after { InterfaceRepository.reset }
12
+
11
13
  describe '.activate' do
12
14
  let(:subject) { described_class.activate(interface) }
13
15
 
@@ -40,19 +42,11 @@ module Vedeu
40
42
  end
41
43
  end
42
44
 
43
- describe '.initial_state' do
44
- let(:subject) { described_class.initial_state }
45
-
46
- before { Compositor.stubs(:arrange) }
47
-
48
- it 'returns an Array' do
49
- subject.must_be_instance_of(Array)
50
- end
51
- end
52
-
53
45
  describe '.update' do
54
46
  let(:subject) { described_class.update }
55
47
 
48
+ before { Compositor.stubs(:arrange) }
49
+
56
50
  it 'returns an Array' do
57
51
  subject.must_be_instance_of(Array)
58
52
  end
@@ -43,13 +43,11 @@ module Vedeu
43
43
  end
44
44
  end
45
45
 
46
- describe '#initial_state' do
47
- let(:subject) { described_instance.initial_state }
46
+ describe '#update' do
47
+ let(:subject) { described_instance.update }
48
48
 
49
- before { Compositor.stubs(:arrange) }
50
-
51
- it 'returns a NilClass' do
52
- subject.must_be_instance_of(NilClass)
49
+ it 'returns a Array' do
50
+ subject.must_be_instance_of(Array)
53
51
  end
54
52
  end
55
53
 
File without changes
@@ -4,20 +4,21 @@ module Vedeu
4
4
  describe Queue do
5
5
  let(:described_class) { Queue }
6
6
 
7
- before { described_class.clear }
7
+ before { described_class.enqueue(:result) }
8
+ after { described_class.clear }
8
9
 
9
10
  describe '.dequeue' do
10
11
  let(:subject) { described_class.dequeue }
11
12
 
12
13
  context 'when the queue is empty' do
14
+ before { described_class.clear }
15
+
13
16
  it 'returns a NilClass' do
14
17
  subject.must_be_instance_of(NilClass)
15
18
  end
16
19
  end
17
20
 
18
21
  context 'when the queue is not empty' do
19
- before { described_class.enqueue(:result) }
20
-
21
22
  it 'returns the first entry added' do
22
23
  subject.must_be_instance_of(Symbol)
23
24
  end
@@ -33,7 +34,25 @@ module Vedeu
33
34
  end
34
35
 
35
36
  it 'contains the enqueued item' do
36
- subject.size.must_equal(1)
37
+ subject.size.must_equal(2)
38
+ end
39
+ end
40
+
41
+ describe '.enqueued?' do
42
+ let(:subject) { described_class.enqueued? }
43
+
44
+ context 'when the queue contains data' do
45
+ it 'returns a TrueClass' do
46
+ subject.must_be_instance_of(TrueClass)
47
+ end
48
+ end
49
+
50
+ context 'when the queue is empty' do
51
+ before { described_class.clear }
52
+
53
+ it 'returns a FalseClass' do
54
+ subject.must_be_instance_of(FalseClass)
55
+ end
37
56
  end
38
57
  end
39
58
 
@@ -45,7 +64,7 @@ module Vedeu
45
64
  end
46
65
 
47
66
  it 'returns the size of the queue' do
48
- subject.must_equal(0)
67
+ subject.must_equal(1)
49
68
  end
50
69
  end
51
70
 
@@ -69,7 +88,7 @@ module Vedeu
69
88
  end
70
89
 
71
90
  it 'returns the queue as a String' do
72
- subject.must_equal("[]")
91
+ subject.must_equal("[:result]")
73
92
  end
74
93
  end
75
94
  end
@@ -28,14 +28,12 @@ module Vedeu
28
28
  describe '.output' do
29
29
  let(:subject) { described_class.output }
30
30
 
31
- before { console.stubs(:print).returns("test") }
32
-
33
31
  it 'returns a String' do
34
32
  subject.must_be_instance_of(String)
35
33
  end
36
34
 
37
35
  it 'returns the output' do
38
- subject.must_equal("test")
36
+ subject.must_equal("")
39
37
  end
40
38
  end
41
39
 
@@ -86,8 +84,12 @@ module Vedeu
86
84
  describe '.close' do
87
85
  let(:subject) { described_class.close }
88
86
 
89
- it 'returns a NilClass' do
90
- subject.must_be_instance_of(NilClass)
87
+ it 'returns a String' do
88
+ subject.must_be_instance_of(String)
89
+ end
90
+
91
+ it 'returns an escape sequence' do
92
+ subject.must_equal("\e[24;1H \e[24;1H")
91
93
  end
92
94
  end
93
95
 
@@ -120,18 +122,12 @@ module Vedeu
120
122
  describe '.clear_screen' do
121
123
  let(:subject) { described_class.clear_screen }
122
124
 
123
- before { Esc.stubs(:clear).returns('') }
124
-
125
- it 'returns a NilClass' do
126
- subject.must_be_instance_of(NilClass)
125
+ it 'returns a String' do
126
+ subject.must_be_instance_of(String)
127
127
  end
128
128
 
129
- context 'capturing output' do
130
- let(:io) { capture_io { subject }.join }
131
-
132
- it 'returns a String' do
133
- io.must_be_instance_of(String)
134
- end
129
+ it 'returns an escape sequence' do
130
+ subject.must_equal("\e[2J")
135
131
  end
136
132
  end
137
133
 
@@ -139,56 +135,48 @@ module Vedeu
139
135
  let(:subject) { described_class.clear_line(index) }
140
136
  let(:index) { 0 }
141
137
 
142
- it 'returns a NilClass' do
143
- subject.must_be_instance_of(NilClass)
138
+ it 'returns a String' do
139
+ subject.must_be_instance_of(String)
140
+ end
141
+
142
+ it 'returns an escape sequence' do
143
+ subject.must_equal("\e[0;1H \e[0;1H")
144
144
  end
145
145
  end
146
146
 
147
147
  describe '.show_cursor' do
148
148
  let(:subject) { described_class.show_cursor }
149
149
 
150
- it 'returns a NilClass' do
151
- subject.must_be_instance_of(NilClass)
150
+ it 'returns a String' do
151
+ subject.must_be_instance_of(String)
152
152
  end
153
153
 
154
- context 'capturing output' do
155
- let(:io) { capture_io { subject }.join }
156
-
157
- it 'returns a String' do
158
- io.must_be_instance_of(String)
159
- end
154
+ it 'returns an escape sequence' do
155
+ subject.must_equal("\e[?25h")
160
156
  end
161
157
  end
162
158
 
163
159
  describe '.hide_cursor' do
164
160
  let(:subject) { described_class.hide_cursor }
165
161
 
166
- it 'returns a NilClass' do
167
- subject.must_be_instance_of(NilClass)
162
+ it 'returns a String' do
163
+ subject.must_be_instance_of(String)
168
164
  end
169
165
 
170
- context 'capturing output' do
171
- let(:io) { capture_io { subject }.join }
172
-
173
- it 'returns a String' do
174
- io.must_be_instance_of(String)
175
- end
166
+ it 'returns an escape sequence' do
167
+ subject.must_equal("\e[?25l")
176
168
  end
177
169
  end
178
170
 
179
171
  describe '.reset_colours' do
180
172
  let(:subject) { described_class.reset_colours }
181
173
 
182
- it 'returns a NilClass' do
183
- subject.must_be_instance_of(NilClass)
174
+ it 'returns a String' do
175
+ subject.must_be_instance_of(String)
184
176
  end
185
177
 
186
- context 'capturing output' do
187
- let(:io) { capture_io { subject }.join }
188
-
189
- it 'returns a String' do
190
- io.must_be_instance_of(String)
191
- end
178
+ it 'returns an escape sequence' do
179
+ subject.must_equal("\e[0m")
192
180
  end
193
181
  end
194
182
 
@@ -211,8 +199,12 @@ module Vedeu
211
199
  describe '#initial_setup!' do
212
200
  let(:subject) { described_class.new.initial_setup! }
213
201
 
214
- it 'returns a NilClass' do
215
- subject.must_be_instance_of(NilClass)
202
+ it 'returns a String' do
203
+ subject.must_be_instance_of(String)
204
+ end
205
+
206
+ it 'returns an escape sequence' do
207
+ subject.must_equal("\e[1;1H")
216
208
  end
217
209
  end
218
210
  end