vedeu 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -23
- data/deps.md +15 -19
- data/lib/vedeu.rb +8 -54
- data/lib/vedeu/api/base.rb +5 -3
- data/lib/vedeu/api/events.rb +75 -0
- data/lib/vedeu/api/interface.rb +12 -2
- data/lib/vedeu/api/store.rb +37 -0
- data/lib/vedeu/api/view.rb +12 -4
- data/lib/vedeu/application.rb +7 -3
- data/lib/vedeu/configuration.rb +4 -0
- data/lib/vedeu/instrumentation.rb +1 -9
- data/lib/vedeu/launcher.rb +5 -3
- data/lib/vedeu/models/attributes/background.rb +11 -0
- data/lib/vedeu/models/attributes/collection.rb +1 -7
- data/lib/vedeu/{output → models/attributes}/colour_translator.rb +19 -3
- data/lib/vedeu/models/attributes/foreground.rb +11 -0
- data/lib/vedeu/models/attributes/interface_collection.rb +5 -5
- data/lib/vedeu/models/colour.rb +2 -18
- data/lib/vedeu/models/interface.rb +22 -13
- data/lib/vedeu/models/line.rb +1 -2
- data/lib/vedeu/models/stream.rb +21 -13
- data/lib/vedeu/output/{clear_interface.rb → clear.rb} +5 -5
- data/lib/vedeu/output/{render_interface.rb → render.rb} +4 -4
- data/lib/vedeu/support/esc.rb +3 -0
- data/lib/vedeu/support/menu.rb +1 -1
- data/lib/vedeu/support/terminal.rb +4 -10
- data/test/lib/vedeu/api/base_test.rb +1 -1
- data/test/lib/vedeu/api/events_test.rb +37 -0
- data/test/lib/vedeu/api/grid_test.rb +11 -9
- data/test/lib/vedeu/api/interface_test.rb +10 -13
- data/test/lib/vedeu/api/line_test.rb +0 -2
- data/test/lib/vedeu/api/store_test.rb +49 -0
- data/test/lib/vedeu/api/stream_test.rb +1 -1
- data/test/lib/vedeu/api/view_test.rb +1 -1
- data/test/lib/vedeu/models/attributes/background_test.rb +8 -0
- data/test/lib/vedeu/models/attributes/colour_translator_test.rb +78 -0
- data/test/lib/vedeu/models/attributes/foreground_test.rb +8 -0
- data/test/lib/vedeu/models/attributes/interface_collection_test.rb +22 -6
- data/test/lib/vedeu/models/attributes/line_collection_test.rb +1 -6
- data/test/lib/vedeu/models/attributes/stream_collection_test.rb +1 -1
- data/test/lib/vedeu/models/composition_test.rb +108 -62
- data/test/lib/vedeu/models/geometry_test.rb +48 -0
- data/test/lib/vedeu/models/interface_test.rb +26 -10
- data/test/lib/vedeu/models/line_test.rb +0 -5
- data/test/lib/vedeu/output/{clear_interface_test.rb → clear_test.rb} +8 -8
- data/test/lib/vedeu/output/{render_interface_test.rb → render_test.rb} +7 -7
- data/test/lib/vedeu/support/esc_test.rb +12 -0
- data/test/lib/vedeu/support/terminal_test.rb +2 -1
- data/test/lib/vedeu_test.rb +0 -38
- data/test/support/colours.rb +1 -1
- data/vedeu.gemspec +1 -1
- metadata +23 -23
- data/lib/vedeu/output/text_adaptor.rb +0 -35
- data/lib/vedeu/support/events.rb +0 -51
- data/lib/vedeu/support/interface_store.rb +0 -43
- data/lib/vedeu/support/queue.rb +0 -31
- data/test/lib/vedeu/output/colour_translator_test.rb +0 -42
- data/test/lib/vedeu/output/text_adaptor_test.rb +0 -73
- data/test/lib/vedeu/support/events_test.rb +0 -35
- data/test/lib/vedeu/support/interface_store_test.rb +0 -51
- data/test/lib/vedeu/support/queue_test.rb +0 -44
@@ -2,7 +2,7 @@ require 'vedeu/models/line'
|
|
2
2
|
require 'vedeu/models/stream'
|
3
3
|
|
4
4
|
module Vedeu
|
5
|
-
class
|
5
|
+
class Render
|
6
6
|
def self.call(interface)
|
7
7
|
new(interface).render
|
8
8
|
end
|
@@ -15,7 +15,7 @@ module Vedeu
|
|
15
15
|
out = [interface.clear]
|
16
16
|
processed_lines.each_with_index do |line, index|
|
17
17
|
if index + 1 <= height
|
18
|
-
out << interface.
|
18
|
+
out << interface.origin(index)
|
19
19
|
out << line.to_s
|
20
20
|
end
|
21
21
|
end
|
@@ -62,11 +62,11 @@ module Vedeu
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def height
|
65
|
-
interface.
|
65
|
+
interface.height
|
66
66
|
end
|
67
67
|
|
68
68
|
def width
|
69
|
-
interface.
|
69
|
+
interface.width
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
data/lib/vedeu/support/esc.rb
CHANGED
@@ -17,9 +17,12 @@ module Vedeu
|
|
17
17
|
when 'bold' then "\e[1m"
|
18
18
|
when 'bold_off' then "\e[21m"
|
19
19
|
when 'clear' then "\e[38;2;39m\e[48;2;49m\e[2J"
|
20
|
+
when 'clear_line' then "\e[38;2;39m\e[48;2;49m\e[2K"
|
20
21
|
when 'colour_reset' then "\e[38;2;39m\e[48;2;49m"
|
21
22
|
when 'fg_reset' then "\e[38;2;39m"
|
22
23
|
when 'hide_cursor' then "\e[?25l"
|
24
|
+
when 'screen_init' then "\e[0m\e[38;2;39m\e[48;2;49m\e[2J\e[?25l"
|
25
|
+
when 'screen_exit' then "\e[?25h\e[38;2;39m\e[48;2;49m\e[0m"
|
23
26
|
when 'negative' then "\e[7m"
|
24
27
|
when 'positive' then "\e[27m"
|
25
28
|
when 'reset' then "\e[0m"
|
data/lib/vedeu/support/menu.rb
CHANGED
@@ -5,7 +5,7 @@ require 'vedeu/support/esc'
|
|
5
5
|
module Vedeu
|
6
6
|
module Terminal
|
7
7
|
extend self
|
8
|
-
|
8
|
+
|
9
9
|
def open(mode, &block)
|
10
10
|
@mode = mode
|
11
11
|
|
@@ -36,7 +36,6 @@ module Vedeu
|
|
36
36
|
|
37
37
|
end
|
38
38
|
end
|
39
|
-
# :nocov:
|
40
39
|
|
41
40
|
def output(stream = '')
|
42
41
|
console.print(stream)
|
@@ -44,18 +43,14 @@ module Vedeu
|
|
44
43
|
stream
|
45
44
|
end
|
46
45
|
|
47
|
-
# :nocov:
|
48
46
|
def initialize_screen(&block)
|
49
|
-
output Esc.string '
|
50
|
-
output Esc.string 'clear'
|
51
|
-
output Esc.string 'hide_cursor'
|
47
|
+
output Esc.string 'screen_init'
|
52
48
|
|
53
49
|
yield
|
54
50
|
end
|
55
51
|
|
56
52
|
def restore_screen
|
57
|
-
output Esc.string '
|
58
|
-
output Esc.string 'reset'
|
53
|
+
output Esc.string 'screen_exit'
|
59
54
|
output clear_last_line
|
60
55
|
end
|
61
56
|
|
@@ -66,10 +61,9 @@ module Vedeu
|
|
66
61
|
def raw_mode?
|
67
62
|
@mode == :raw
|
68
63
|
end
|
69
|
-
# :nocov:
|
70
64
|
|
71
65
|
def clear_last_line
|
72
|
-
Esc.set_position((height - 1), 1) +
|
66
|
+
Esc.set_position((height - 1), 1) + Esc.string('clear_line')
|
73
67
|
end
|
74
68
|
|
75
69
|
def centre
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'vedeu/api/events'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
module API
|
6
|
+
describe Events do
|
7
|
+
describe '#on' do
|
8
|
+
it 'adds the event block to the handlers' do
|
9
|
+
skip
|
10
|
+
events = Events.new
|
11
|
+
events.on(:some_event) { proc { |x| x } }
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'adds the specified throttle to the throttles' do
|
15
|
+
skip
|
16
|
+
events = Events.new
|
17
|
+
events.on(:some_event, 250) { proc { |x| x } }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#trigger' do
|
22
|
+
it 'returns a collection containing the event when the event is ' \
|
23
|
+
'pre-registered' do
|
24
|
+
events = Events.new do
|
25
|
+
on(:_exit_) { fail StopIteration }
|
26
|
+
end
|
27
|
+
proc { events.trigger(:_exit_) }.must_raise(StopIteration)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns an empty collection when the event has not been registered' do
|
31
|
+
events = Events.new
|
32
|
+
events.trigger(:_not_found_).must_be_empty
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -15,17 +15,19 @@ end
|
|
15
15
|
module Vedeu
|
16
16
|
module API
|
17
17
|
describe Grid do
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
describe '.columns' do
|
19
|
+
it 'raises an exception if the value is less than 1' do
|
20
|
+
proc { Grid.columns(0) }.must_raise(OutOfRange)
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
it 'raises an exception if the value is greater than 12' do
|
24
|
+
proc { Grid.columns(13) }.must_raise(OutOfRange)
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
it 'returns the width if the value is in range' do
|
28
|
+
IO.console.stub :winsize, [25, 80] do
|
29
|
+
Grid.columns(7).must_equal(42)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -4,6 +4,8 @@ require 'vedeu/api/interface'
|
|
4
4
|
module Vedeu
|
5
5
|
module API
|
6
6
|
describe Interface do
|
7
|
+
before { API::Store.reset }
|
8
|
+
|
7
9
|
interface = Interface.new('widget')
|
8
10
|
|
9
11
|
it 'creates and stores a new interface' do
|
@@ -12,27 +14,27 @@ module Vedeu
|
|
12
14
|
|
13
15
|
it 'allows interfaces to share behaviour' do
|
14
16
|
IO.console.stub :winsize, [10, 40] do
|
15
|
-
main =
|
17
|
+
main = Vedeu.interface('main') do
|
16
18
|
colour foreground: '#ff0000', background: '#000000'
|
17
19
|
cursor false
|
18
20
|
centred true
|
19
21
|
width 10
|
20
22
|
height 2
|
21
23
|
end
|
22
|
-
status =
|
24
|
+
status = Vedeu.interface('status') do
|
23
25
|
colour foreground: 'aadd00', background: '#4040cc'
|
24
26
|
cursor true
|
25
27
|
centred true
|
26
28
|
width 10
|
27
29
|
height 1
|
28
|
-
y main.
|
29
|
-
x main.
|
30
|
+
y use('main').bottom
|
31
|
+
x use('main').left
|
30
32
|
end
|
31
33
|
|
32
|
-
main.
|
33
|
-
main.
|
34
|
-
status.
|
35
|
-
status.
|
34
|
+
main.left.must_equal(15)
|
35
|
+
main.top.must_equal(4)
|
36
|
+
status.left.must_equal(15)
|
37
|
+
status.top.must_equal(5)
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -67,11 +69,6 @@ module Vedeu
|
|
67
69
|
it 'raises an exception when the value is out of bounds' do
|
68
70
|
proc { interface.save { height 999 } }.must_raise(InvalidHeight)
|
69
71
|
end
|
70
|
-
|
71
|
-
it 'should have a valid spec, please write one.' do
|
72
|
-
skip
|
73
|
-
interface = Interface.new('widget')
|
74
|
-
end
|
75
72
|
end
|
76
73
|
end
|
77
74
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'vedeu/api/store'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
module API
|
6
|
+
describe Store do
|
7
|
+
before { Store.reset }
|
8
|
+
|
9
|
+
describe '#create' do
|
10
|
+
it 'creates and returns the stored record' do
|
11
|
+
attributes = { name: 'sulphur' }
|
12
|
+
|
13
|
+
Store.create(attributes).must_equal({ name: 'sulphur' })
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#query' do
|
18
|
+
before do
|
19
|
+
Store.reset
|
20
|
+
Vedeu.interface('chlorine')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns the record when found' do
|
24
|
+
Store.query('chlorine').must_equal({ name: 'chlorine', geometry: {} })
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'raises an exception when name is empty' do
|
28
|
+
proc { Store.query('') }.must_raise(EntityNotFound)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises an exception when name is nil' do
|
32
|
+
proc { Store.query(nil) }.must_raise(EntityNotFound)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'raises an exception when the record cannot be found' do
|
36
|
+
proc { Store.query('dummy') }.must_raise(EntityNotFound)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#reset' do
|
41
|
+
it 'deletes all records stored' do
|
42
|
+
Vedeu.interface('potassium')
|
43
|
+
|
44
|
+
Store.reset.must_equal({})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'vedeu/models/attributes/colour_translator'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
describe ColourTranslator do
|
6
|
+
describe '#background' do
|
7
|
+
{
|
8
|
+
'#5f0000' => "\e[48;5;52m",
|
9
|
+
'#008700' => "\e[48;5;28m",
|
10
|
+
'#0000d7' => "\e[48;5;20m",
|
11
|
+
'#afafaf' => "\e[48;5;145m",
|
12
|
+
'#afd700' => "\e[48;5;148m",
|
13
|
+
'#af005f' => "\e[48;5;125m",
|
14
|
+
}.map do |html_colour, terminal_colour|
|
15
|
+
it 'translation is performed' do
|
16
|
+
ColourTranslator.new(html_colour).background
|
17
|
+
.must_equal(terminal_colour)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns empty string when not present' do
|
22
|
+
ColourTranslator.new.background.must_equal('')
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns empty string when the wrong type!' do
|
26
|
+
ColourTranslator.new(:wrong_type).background.must_equal('')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns empty string when invalid format' do
|
30
|
+
ColourTranslator.new('345678').background.must_equal('')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns empty string when invalid format' do
|
34
|
+
ColourTranslator.new('#h11111').background.must_equal('')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns empty string when invalid format' do
|
38
|
+
ColourTranslator.new('#1111').background.must_equal('')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#foreground' do
|
43
|
+
{
|
44
|
+
'#5f0000' => "\e[38;5;52m",
|
45
|
+
'#008700' => "\e[38;5;28m",
|
46
|
+
'#0000d7' => "\e[38;5;20m",
|
47
|
+
'#afafaf' => "\e[38;5;145m",
|
48
|
+
'#afd700' => "\e[38;5;148m",
|
49
|
+
'#af005f' => "\e[38;5;125m",
|
50
|
+
}.map do |html_colour, terminal_colour|
|
51
|
+
it 'translation is performed' do
|
52
|
+
ColourTranslator.new(html_colour).foreground
|
53
|
+
.must_equal(terminal_colour)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns empty string when not present' do
|
58
|
+
ColourTranslator.new.foreground.must_equal('')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns empty string when the wrong type!' do
|
62
|
+
ColourTranslator.new(:wrong_type).foreground.must_equal('')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns empty string when invalid format' do
|
66
|
+
ColourTranslator.new('345678').foreground.must_equal('')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns empty string when invalid format' do
|
70
|
+
ColourTranslator.new('#h11111').foreground.must_equal('')
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns empty string when invalid format' do
|
74
|
+
ColourTranslator.new('#1111').foreground.must_equal('')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
|
2
3
|
require 'vedeu/models/composition'
|
3
4
|
require 'vedeu/models/attributes/interface_collection'
|
5
|
+
require 'vedeu/api/store'
|
6
|
+
|
4
7
|
|
5
8
|
module Vedeu
|
6
9
|
describe InterfaceCollection do
|
7
10
|
describe '#coerce' do
|
8
|
-
before {
|
11
|
+
before { API::Store.reset }
|
9
12
|
|
10
13
|
it 'returns an empty collection when there are no interfaces' do
|
11
14
|
composition = Composition.new
|
@@ -13,15 +16,28 @@ module Vedeu
|
|
13
16
|
end
|
14
17
|
|
15
18
|
it 'returns a collection when there is a single interface' do
|
16
|
-
|
19
|
+
Vedeu.interface('dumb') {}
|
20
|
+
|
21
|
+
composition = Composition.new(
|
22
|
+
{
|
23
|
+
interfaces: { name: 'dumb' }
|
24
|
+
}
|
25
|
+
)
|
17
26
|
composition.interfaces.first.must_be_instance_of(Interface)
|
18
27
|
end
|
19
28
|
|
20
29
|
it 'returns a collection when there are multiple interfaces' do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
30
|
+
Vedeu.interface('dumb') {}
|
31
|
+
Vedeu.interface('dumber') {}
|
32
|
+
|
33
|
+
composition = Composition.new(
|
34
|
+
{
|
35
|
+
interfaces: [
|
36
|
+
{ name: 'dumb' },
|
37
|
+
{ name: 'dumber' }
|
38
|
+
]
|
39
|
+
}
|
40
|
+
)
|
25
41
|
composition.interfaces.size.must_equal(2)
|
26
42
|
end
|
27
43
|
end
|