vedeu 0.1.17 → 0.1.18
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/.yardopts +1 -0
- data/README.md +17 -3
- data/lib/vedeu.rb +12 -7
- data/lib/vedeu/api/api.rb +37 -13
- data/lib/vedeu/api/composition.rb +1 -6
- data/lib/vedeu/api/helpers.rb +2 -0
- data/lib/vedeu/api/interface.rb +47 -55
- data/lib/vedeu/api/line.rb +6 -0
- data/lib/vedeu/api/stream.rb +9 -1
- data/lib/vedeu/application.rb +38 -50
- data/lib/vedeu/configuration.rb +163 -44
- data/lib/vedeu/launcher.rb +3 -6
- data/lib/vedeu/models/attributes/background.rb +9 -1
- data/lib/vedeu/models/attributes/colour_translator.rb +40 -2
- data/lib/vedeu/models/attributes/foreground.rb +9 -1
- data/lib/vedeu/models/colour.rb +6 -0
- data/lib/vedeu/models/composition.rb +8 -1
- data/lib/vedeu/models/geometry.rb +27 -14
- data/lib/vedeu/models/interface.rb +59 -0
- data/lib/vedeu/models/line.rb +4 -0
- data/lib/vedeu/models/stream.rb +10 -0
- data/lib/vedeu/models/style.rb +2 -0
- data/lib/vedeu/support/buffer.rb +12 -1
- data/lib/vedeu/support/buffers.rb +10 -0
- data/lib/vedeu/support/clear.rb +4 -0
- data/lib/vedeu/support/esc.rb +26 -8
- data/lib/vedeu/support/event.rb +28 -0
- data/lib/vedeu/support/events.rb +2 -0
- data/lib/vedeu/support/focus.rb +14 -6
- data/lib/vedeu/support/grid.rb +6 -0
- data/lib/vedeu/support/groups.rb +13 -3
- data/lib/vedeu/support/input.rb +7 -2
- data/lib/vedeu/support/log.rb +7 -1
- data/lib/vedeu/support/position.rb +6 -0
- data/lib/vedeu/support/render.rb +38 -0
- data/lib/vedeu/support/terminal.rb +69 -15
- data/lib/vedeu/support/trace.rb +8 -0
- data/lib/vedeu/support/view.rb +6 -0
- data/test/integration/run_once_test.rb +26 -0
- data/test/lib/vedeu/api/api_test.rb +19 -6
- data/test/lib/vedeu/api/interface_test.rb +67 -1
- data/test/lib/vedeu/api/line_test.rb +10 -0
- data/test/lib/vedeu/api/stream_test.rb +8 -0
- data/test/lib/vedeu/configuration_test.rb +119 -12
- data/test/lib/vedeu/models/attributes/background_test.rb +1 -1
- data/test/lib/vedeu/models/attributes/foreground_test.rb +1 -1
- data/test/lib/vedeu/models/interface_test.rb +22 -0
- data/test/lib/vedeu/support/buffer_test.rb +44 -0
- data/test/lib/vedeu/support/events_test.rb +3 -9
- data/test/lib/vedeu/support/input_test.rb +1 -0
- data/test/lib/vedeu/support/terminal_test.rb +128 -5
- data/test/test_helper.rb +2 -2
- data/vedeu.gemspec +1 -1
- metadata +5 -2
@@ -7,6 +7,14 @@ module Vedeu
|
|
7
7
|
it 'returns the value assigned' do
|
8
8
|
Stream.new.align(:left).must_equal(:left)
|
9
9
|
end
|
10
|
+
|
11
|
+
it 'returns the value assigned' do
|
12
|
+
Stream.new.align('left').must_equal(:left)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'raises an exception if the value is invalid' do
|
16
|
+
proc { Stream.new.align(:unknown) }.must_raise(InvalidSyntax)
|
17
|
+
end
|
10
18
|
end
|
11
19
|
|
12
20
|
describe '#text' do
|
@@ -2,30 +2,137 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Configuration do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
before { Configuration.reset }
|
6
|
+
|
7
|
+
after { Configuration.reset }
|
8
|
+
|
9
|
+
describe '#colour_mode' do
|
10
|
+
it 'returns the value of the colour_mode option' do
|
11
|
+
ENV['VEDEU_TERM'] = 'xterm-truecolor'
|
12
|
+
Configuration.colour_mode.must_equal(16777216)
|
13
|
+
end
|
14
|
+
|
15
|
+
it '--colour-mode' do
|
16
|
+
Configuration.configure(['--colour-mode', '16'])
|
17
|
+
Configuration.colour_mode.must_equal(16)
|
18
|
+
end
|
19
|
+
|
20
|
+
it '--colour-mode' do
|
21
|
+
Configuration.configure(['--colour-mode', '256'])
|
22
|
+
Configuration.colour_mode.must_equal(256)
|
23
|
+
end
|
24
|
+
|
25
|
+
it '--colour-mode' do
|
26
|
+
Configuration.configure(['--colour-mode', '348'])
|
27
|
+
Configuration.colour_mode.must_equal(8)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#debug?' do
|
32
|
+
it 'returns the value of the debug option' do
|
33
|
+
Configuration.debug?.must_equal(false)
|
34
|
+
end
|
35
|
+
|
36
|
+
it '--debug' do
|
37
|
+
Configuration.configure(['--debug'])
|
38
|
+
Configuration.debug?.must_equal(true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#interactive?' do
|
43
|
+
it 'returns the value of the interactive option' do
|
44
|
+
Configuration.interactive?.must_equal(true)
|
45
|
+
end
|
46
|
+
|
47
|
+
it '--interactive' do
|
48
|
+
Configuration.configure(['--interactive'])
|
49
|
+
Configuration.interactive?.must_equal(true)
|
50
|
+
end
|
51
|
+
|
52
|
+
it '--noninteractive' do
|
53
|
+
Configuration.configure(['--noninteractive'])
|
54
|
+
Configuration.interactive?.must_equal(false)
|
8
55
|
end
|
9
56
|
|
10
|
-
it '
|
57
|
+
it '--standalone' do
|
58
|
+
Configuration.configure(['--standalone'])
|
59
|
+
Configuration.interactive?.must_equal(false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#once?' do
|
64
|
+
it 'returns the value of the once option' do
|
65
|
+
Configuration.once?.must_equal(false)
|
66
|
+
end
|
67
|
+
|
68
|
+
it '--run-once' do
|
11
69
|
Configuration.configure(['--run-once'])
|
12
|
-
|
70
|
+
Configuration.once?.must_equal(true)
|
13
71
|
end
|
14
72
|
|
15
|
-
it '
|
73
|
+
it '--run-many' do
|
74
|
+
Configuration.configure(['--run-many'])
|
75
|
+
Configuration.once?.must_equal(false)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#terminal_mode' do
|
80
|
+
it 'returns the value of the mode option' do
|
81
|
+
Configuration.terminal_mode.must_equal(:raw)
|
82
|
+
end
|
83
|
+
|
84
|
+
it '--cooked' do
|
16
85
|
Configuration.configure(['--cooked'])
|
17
|
-
|
86
|
+
Configuration.terminal_mode.must_equal(:cooked)
|
18
87
|
end
|
19
88
|
|
20
|
-
it '
|
89
|
+
it '--raw' do
|
21
90
|
Configuration.configure(['--raw'])
|
22
|
-
|
91
|
+
Configuration.terminal_mode.must_equal(:raw)
|
23
92
|
end
|
93
|
+
end
|
24
94
|
|
25
|
-
|
26
|
-
|
27
|
-
|
95
|
+
describe '#trace?' do
|
96
|
+
it 'returns the value of the trace option' do
|
97
|
+
Configuration.trace?.must_equal(false)
|
98
|
+
end
|
99
|
+
|
100
|
+
it '--trace' do
|
101
|
+
Configuration.configure(['--trace'])
|
102
|
+
Configuration.trace?.must_equal(true)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#options' do
|
107
|
+
it 'returns the options configured' do
|
108
|
+
Configuration.options.must_equal(
|
109
|
+
{
|
110
|
+
colour_mode: 16777216,
|
111
|
+
debug: false,
|
112
|
+
interactive: true,
|
113
|
+
once: false,
|
114
|
+
terminal_mode: :raw,
|
115
|
+
trace: false
|
116
|
+
}
|
117
|
+
)
|
28
118
|
end
|
29
119
|
end
|
120
|
+
|
121
|
+
describe 'exploring multiple options set' do
|
122
|
+
it 'returns the options correctly configured' do
|
123
|
+
Configuration.configure(['--standalone', '--run-once'])
|
124
|
+
Configuration.options.must_equal(
|
125
|
+
{
|
126
|
+
interactive: false,
|
127
|
+
once: true,
|
128
|
+
colour_mode: 16777216,
|
129
|
+
debug: false,
|
130
|
+
terminal_mode: :raw,
|
131
|
+
trace: false
|
132
|
+
}
|
133
|
+
)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
30
137
|
end
|
31
138
|
end
|
@@ -106,5 +106,27 @@ module Vedeu
|
|
106
106
|
)
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
describe '#clear' do
|
111
|
+
it 'delegates to the Clear class to return an empty interface' do
|
112
|
+
Interface.new({
|
113
|
+
name: '#to_s',
|
114
|
+
lines: [],
|
115
|
+
colour: {
|
116
|
+
foreground: '#ff0000',
|
117
|
+
background: '#000000'
|
118
|
+
},
|
119
|
+
geometry: {
|
120
|
+
width: 9,
|
121
|
+
height: 3
|
122
|
+
}
|
123
|
+
}).clear.must_equal(
|
124
|
+
"\e[38;2;255;0;0m\e[48;2;0;0;0m" \
|
125
|
+
"\e[1;1H \e[1;1H" \
|
126
|
+
"\e[2;1H \e[2;1H" \
|
127
|
+
"\e[3;1H \e[3;1H"
|
128
|
+
)
|
129
|
+
end
|
130
|
+
end
|
109
131
|
end
|
110
132
|
end
|
@@ -34,6 +34,50 @@ module Vedeu
|
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '#refresh' do
|
37
|
+
it 'renders the fresh content if available' do
|
38
|
+
interface = Interface.new
|
39
|
+
buffer = Buffer.new({ back: interface, front: nil, interface: interface })
|
40
|
+
Terminal.stub(:output, '') do
|
41
|
+
buffer.refresh.must_be_instance_of(Buffer)
|
42
|
+
buffer.refresh.wont_equal(buffer)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'clears the interface if no content is available' do
|
47
|
+
interface = Interface.new
|
48
|
+
buffer = Buffer.new({ back: nil, front: nil, interface: interface })
|
49
|
+
Terminal.stub(:output, '') do
|
50
|
+
buffer.refresh.must_equal(buffer)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'renders the previous/old content if nothing new has arrived' do
|
55
|
+
interface = Interface.new
|
56
|
+
buffer = Buffer.new({ back: nil, front: interface, interface: interface })
|
57
|
+
Terminal.stub(:output, '') do
|
58
|
+
buffer.refresh.must_equal(buffer)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#render' do
|
64
|
+
it 'renders the interface and returns the Buffer instance' do
|
65
|
+
interface = Interface.new
|
66
|
+
buffer = Buffer.new({ back: nil, front: nil, interface: interface })
|
67
|
+
Terminal.stub(:output, '') do
|
68
|
+
buffer.render.must_equal(buffer)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#clear' do
|
74
|
+
it 'clears the interface and returns the Buffer instance' do
|
75
|
+
interface = Interface.new
|
76
|
+
buffer = Buffer.new({ back: nil, front: nil, interface: interface })
|
77
|
+
Terminal.stub(:output, '') do
|
78
|
+
buffer.clear.must_equal(buffer)
|
79
|
+
end
|
80
|
+
end
|
37
81
|
end
|
38
82
|
end
|
39
83
|
end
|
@@ -4,15 +4,9 @@ module Vedeu
|
|
4
4
|
describe Events do
|
5
5
|
describe '#event' do
|
6
6
|
it 'adds the event block to the handlers' do
|
7
|
-
skip
|
8
7
|
events = Events.new
|
9
|
-
events.event(:
|
10
|
-
|
11
|
-
|
12
|
-
it 'adds the specified throttle to the throttles' do
|
13
|
-
skip
|
14
|
-
events = Events.new
|
15
|
-
events.event(:some_event, 250) { proc { |x| x } }
|
8
|
+
events.event(:sulphur) { proc { |x| x } }
|
9
|
+
events.registered.must_equal([:sulphur])
|
16
10
|
end
|
17
11
|
end
|
18
12
|
|
@@ -61,7 +55,7 @@ module Vedeu
|
|
61
55
|
describe '#reset' do
|
62
56
|
it 'removes all events registered' do
|
63
57
|
events = Events.new do
|
64
|
-
event(:
|
58
|
+
event(:potassium) { proc { |x| x } }
|
65
59
|
end
|
66
60
|
events.reset.must_equal({})
|
67
61
|
end
|
@@ -4,17 +4,57 @@ module Vedeu
|
|
4
4
|
describe Terminal do
|
5
5
|
let(:console) { IO.console }
|
6
6
|
|
7
|
-
describe '.
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
describe '.open' do
|
8
|
+
before { IO.console.stubs(:print) }
|
9
|
+
|
10
|
+
it 'raises an exception when no block is given' do
|
11
|
+
proc { Terminal.open }.must_raise(InvalidSyntax)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'opens a new terminal console in raw mode' do
|
15
|
+
Configuration.stub(:terminal_mode, :raw) do
|
16
|
+
capture_io do
|
17
|
+
Terminal.open do
|
18
|
+
print "Hello from raw mode!"
|
19
|
+
end
|
20
|
+
end.must_equal(["Hello from raw mode!", ""])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'opens a new terminal console in cooked mode' do
|
25
|
+
Configuration.stub(:terminal_mode, :cooked) do
|
26
|
+
capture_io do
|
27
|
+
Terminal.open do
|
28
|
+
print "Hello from cooked mode!"
|
29
|
+
end
|
30
|
+
end.must_equal(["Hello from cooked mode!", ""])
|
11
31
|
end
|
12
32
|
end
|
13
33
|
end
|
14
34
|
|
35
|
+
describe '.input' do
|
36
|
+
# it 'returns the entered string in cooked mode' do
|
37
|
+
# Configuration.stub(:terminal_mode, :cooked) do
|
38
|
+
# Terminal.console.stub(:gets, "test\n") do
|
39
|
+
# Terminal.input.must_equal('test')
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
|
44
|
+
# it 'returns the entered string in raw mode' do
|
45
|
+
# Configuration.stub(:terminal_mode, :raw) do
|
46
|
+
# console.stub :getch, "a" do
|
47
|
+
# Terminal.input.must_equal("a")
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
end
|
52
|
+
|
15
53
|
describe '.output' do
|
54
|
+
before { IO.console.stubs(:print) }
|
55
|
+
|
16
56
|
it 'returns the output' do
|
17
|
-
Terminal.output.must_equal('')
|
57
|
+
Terminal.output('Some output...').must_equal('Some output...')
|
18
58
|
end
|
19
59
|
end
|
20
60
|
|
@@ -27,6 +67,73 @@ module Vedeu
|
|
27
67
|
end
|
28
68
|
end
|
29
69
|
|
70
|
+
describe '.clear_screen' do
|
71
|
+
it 'clears the screen' do
|
72
|
+
console.stub :print, nil do
|
73
|
+
Terminal.clear_screen.must_equal("\e[38;2;39m\e[48;2;49m\e[2J")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '.set_cursor_mode' do
|
79
|
+
it 'shows the cursor in cooked mode' do
|
80
|
+
Terminal.cooked_mode!
|
81
|
+
Terminal.set_cursor_mode.must_equal("\e[?25h")
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'hides the cursor in raw mode' do
|
85
|
+
Terminal.raw_mode!
|
86
|
+
Terminal.set_cursor_mode.must_equal(nil)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '.raw_mode?' do
|
91
|
+
it 'returns true if the terminal is in raw mode' do
|
92
|
+
Terminal.raw_mode!
|
93
|
+
Terminal.raw_mode?.must_equal(true)
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns false if the terminal is not in raw mode' do
|
97
|
+
Terminal.cooked_mode!
|
98
|
+
Terminal.raw_mode?.must_equal(false)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '.cooked_mode?' do
|
103
|
+
it 'returns true if the terminal is in cooked mode' do
|
104
|
+
Terminal.cooked_mode!
|
105
|
+
Terminal.cooked_mode?.must_equal(true)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'returns false if the terminal is not in cooked mode' do
|
109
|
+
Terminal.raw_mode!
|
110
|
+
Terminal.cooked_mode?.must_equal(false)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '.switch_mode!' do
|
115
|
+
it 'returns :cooked if previously :raw' do
|
116
|
+
Terminal.raw_mode!
|
117
|
+
Terminal.switch_mode!.must_equal(:cooked)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'returns :raw if previously :cooked' do
|
121
|
+
Terminal.cooked_mode!
|
122
|
+
Terminal.switch_mode!.must_equal(:raw)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '.mode' do
|
127
|
+
before do
|
128
|
+
Configuration.stubs(:terminal_mode).returns(:raw)
|
129
|
+
Terminal.switch_mode! if Terminal.mode == :cooked
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'returns the configured terminal mode' do
|
133
|
+
Terminal.mode.must_equal(:raw)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
30
137
|
describe '.centre' do
|
31
138
|
it 'returns the centre point on the terminal' do
|
32
139
|
console.stub :winsize, [25, 80] do
|
@@ -35,6 +142,22 @@ module Vedeu
|
|
35
142
|
end
|
36
143
|
end
|
37
144
|
|
145
|
+
describe '.centre_y' do
|
146
|
+
it 'returns the centre `y` point on the terminal' do
|
147
|
+
console.stub :winsize, [25, 80] do
|
148
|
+
Terminal.centre_y.must_equal(12)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe '.centre_x' do
|
154
|
+
it 'returns the centre `x` point on the terminal' do
|
155
|
+
console.stub :winsize, [25, 80] do
|
156
|
+
Terminal.centre_x.must_equal(40)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
38
161
|
describe '.width' do
|
39
162
|
it 'returns the width of the terminal' do
|
40
163
|
console.stub :winsize, [25, 80] do
|