vedeu 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/LICENSE.txt +5 -0
  4. data/bin/vedeu +3 -1
  5. data/docs/api.md +2 -0
  6. data/examples/cursor_app/cursor_app.rb +22 -7
  7. data/examples/hello_world.rb +42 -0
  8. data/lib/vedeu.rb +5 -5
  9. data/lib/vedeu/api/api.rb +16 -33
  10. data/lib/vedeu/api/helpers.rb +86 -0
  11. data/lib/vedeu/api/interface.rb +60 -17
  12. data/lib/vedeu/api/keymap.rb +5 -0
  13. data/lib/vedeu/api/line.rb +52 -34
  14. data/lib/vedeu/api/menu.rb +1 -1
  15. data/lib/vedeu/api/stream.rb +0 -34
  16. data/lib/vedeu/configuration/api.rb +10 -10
  17. data/lib/vedeu/configuration/cli.rb +1 -1
  18. data/lib/vedeu/launcher.rb +21 -6
  19. data/lib/vedeu/models/background.rb +1 -1
  20. data/lib/vedeu/models/composition.rb +1 -1
  21. data/lib/vedeu/models/cursor.rb +25 -35
  22. data/lib/vedeu/models/foreground.rb +1 -1
  23. data/lib/vedeu/models/geometry.rb +216 -6
  24. data/lib/vedeu/models/interface.rb +14 -16
  25. data/lib/vedeu/models/keymap.rb +38 -6
  26. data/lib/vedeu/models/line.rb +1 -1
  27. data/lib/vedeu/models/stream.rb +1 -1
  28. data/lib/vedeu/output/compositor.rb +1 -1
  29. data/lib/vedeu/output/render.rb +1 -5
  30. data/lib/vedeu/output/viewport.rb +37 -2
  31. data/lib/vedeu/repositories/buffers.rb +21 -27
  32. data/lib/vedeu/repositories/cursors.rb +3 -15
  33. data/lib/vedeu/repositories/focus.rb +2 -6
  34. data/lib/vedeu/repositories/groups.rb +1 -1
  35. data/lib/vedeu/repositories/interfaces.rb +1 -1
  36. data/lib/vedeu/repositories/keymaps.rb +26 -22
  37. data/lib/vedeu/repositories/menus.rb +1 -1
  38. data/lib/vedeu/repositories/offsets.rb +30 -12
  39. data/lib/vedeu/repositories/positional.rb +23 -0
  40. data/lib/vedeu/support/colour_translator.rb +1 -16
  41. data/lib/vedeu/support/esc.rb +23 -28
  42. data/lib/vedeu/support/event.rb +6 -14
  43. data/lib/vedeu/{output → support}/refresh.rb +0 -0
  44. data/lib/vedeu/support/registrar.rb +6 -14
  45. data/lib/vedeu/support/repository.rb +3 -2
  46. data/lib/vedeu/support/terminal.rb +9 -13
  47. data/lib/vedeu/support/trace.rb +2 -3
  48. data/test/integration/cursors_test.rb +9 -0
  49. data/test/integration/views/basic_view_test.rb +19 -0
  50. data/test/lib/vedeu/api/api_test.rb +28 -5
  51. data/test/lib/vedeu/api/composition_test.rb +7 -3
  52. data/test/lib/vedeu/api/defined_test.rb +9 -3
  53. data/test/lib/vedeu/api/helpers_test.rb +39 -5
  54. data/test/lib/vedeu/api/interface_test.rb +88 -8
  55. data/test/lib/vedeu/api/keymap_test.rb +5 -3
  56. data/test/lib/vedeu/api/line_test.rb +9 -3
  57. data/test/lib/vedeu/api/menu_test.rb +11 -7
  58. data/test/lib/vedeu/api/stream_test.rb +9 -31
  59. data/test/lib/vedeu/application_test.rb +25 -2
  60. data/test/lib/vedeu/configuration/api_test.rb +5 -3
  61. data/test/lib/vedeu/configuration/cli_test.rb +5 -3
  62. data/test/lib/vedeu/configuration/configuration_test.rb +5 -2
  63. data/test/lib/vedeu/input/input_test.rb +5 -2
  64. data/test/lib/vedeu/launcher_test.rb +37 -2
  65. data/test/lib/vedeu/models/background_test.rb +6 -2
  66. data/test/lib/vedeu/models/char_test.rb +9 -6
  67. data/test/lib/vedeu/models/colour_test.rb +6 -2
  68. data/test/lib/vedeu/models/composition_test.rb +4 -2
  69. data/test/lib/vedeu/models/cursor_test.rb +27 -16
  70. data/test/lib/vedeu/models/foreground_test.rb +6 -2
  71. data/test/lib/vedeu/models/geometry_test.rb +6 -2
  72. data/test/lib/vedeu/models/interface_test.rb +5 -2
  73. data/test/lib/vedeu/models/keymap_test.rb +6 -4
  74. data/test/lib/vedeu/models/line_test.rb +5 -2
  75. data/test/lib/vedeu/models/offset_test.rb +7 -3
  76. data/test/lib/vedeu/models/stream_test.rb +4 -2
  77. data/test/lib/vedeu/models/style_test.rb +5 -2
  78. data/test/lib/vedeu/output/clear_test.rb +6 -2
  79. data/test/lib/vedeu/output/compositor_test.rb +8 -4
  80. data/test/lib/vedeu/output/render_test.rb +9 -6
  81. data/test/lib/vedeu/output/view_test.rb +7 -3
  82. data/test/lib/vedeu/output/viewport_test.rb +42 -9
  83. data/test/lib/vedeu/repositories/buffers_test.rb +52 -12
  84. data/test/lib/vedeu/repositories/cursors_test.rb +4 -26
  85. data/test/lib/vedeu/repositories/events_test.rb +6 -2
  86. data/test/lib/vedeu/repositories/focus_test.rb +5 -2
  87. data/test/lib/vedeu/repositories/groups_test.rb +5 -2
  88. data/test/lib/vedeu/repositories/interfaces_test.rb +4 -2
  89. data/test/lib/vedeu/repositories/keymaps_test.rb +8 -2
  90. data/test/lib/vedeu/repositories/menus_test.rb +3 -2
  91. data/test/lib/vedeu/repositories/offsets_test.rb +26 -19
  92. data/test/lib/vedeu/repositories/positional_test.rb +50 -0
  93. data/test/lib/vedeu/support/coercions_test.rb +7 -3
  94. data/test/lib/vedeu/support/colour_translator_test.rb +6 -2
  95. data/test/lib/vedeu/support/common_test.rb +5 -3
  96. data/test/lib/vedeu/support/esc_test.rb +6 -2
  97. data/test/lib/vedeu/support/event_test.rb +6 -2
  98. data/test/lib/vedeu/support/grid_test.rb +9 -3
  99. data/test/lib/vedeu/support/keymap_validator_test.rb +5 -2
  100. data/test/lib/vedeu/support/log_test.rb +4 -2
  101. data/test/lib/vedeu/support/menu_test.rb +10 -2
  102. data/test/lib/vedeu/support/position_test.rb +10 -2
  103. data/test/lib/vedeu/support/presentation_test.rb +6 -3
  104. data/test/lib/vedeu/{output → support}/refresh_test.rb +6 -2
  105. data/test/lib/vedeu/support/registrar_test.rb +2 -2
  106. data/test/lib/vedeu/support/repository_test.rb +4 -3
  107. data/test/lib/vedeu/support/terminal_test.rb +6 -2
  108. data/test/lib/vedeu/support/trace_test.rb +17 -2
  109. data/test/lib/vedeu_test.rb +1 -1
  110. data/vedeu.gemspec +2 -2
  111. metadata +13 -13
  112. data/lib/vedeu/output/area.rb +0 -284
  113. data/lib/vedeu/support/move.rb +0 -50
  114. data/test/lib/vedeu/output/area_test.rb +0 -242
  115. data/test/lib/vedeu/support/move_test.rb +0 -35
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Stream do
5
6
  let(:stream) {
6
7
  Stream.new({
@@ -217,5 +218,6 @@ module Vedeu
217
218
  end
218
219
  end
219
220
 
220
- end
221
- end
221
+ end # Stream
222
+
223
+ end # Vedeu
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Style do
5
6
  describe '#initialize' do
6
7
  it 'returns an instance of itself' do
@@ -53,5 +54,7 @@ module Vedeu
53
54
  end
54
55
  end
55
56
  end
56
- end
57
- end
57
+
58
+ end # Style
59
+
60
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Clear do
6
+
5
7
  before { Interfaces.reset }
6
8
 
7
9
  describe '#initialize' do
@@ -45,5 +47,7 @@ module Vedeu
45
47
  )
46
48
  end
47
49
  end
48
- end
49
- end
50
+
51
+ end # Clear
52
+
53
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Compositor do
6
+
5
7
  before do
6
8
  Interfaces.reset
7
9
  Terminal.console.stubs(:print)
@@ -27,7 +29,7 @@ module Vedeu
27
29
  "\e[1;1H \e[1;1H" \
28
30
  "\e[2;1H \e[2;1H" \
29
31
  "\e[3;1H \e[3;1H" \
30
- "\e[1;1H\e[?25h"
32
+ "\e[1;1H\e[?25l"
31
33
  ])
32
34
  end
33
35
  end
@@ -62,10 +64,12 @@ module Vedeu
62
64
  "\e[1;1Hargon" \
63
65
  "\e[2;1Hboron" \
64
66
  "\e[3;1Hradon" \
65
- "\e[1;1H\e[?25h"
67
+ "\e[1;1H\e[?25l"
66
68
  ])
67
69
  end
68
70
  end
69
71
  end
70
- end
71
- end
72
+
73
+ end # Compositor
74
+
75
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Render do
6
+
5
7
  before do
6
8
  Buffers.reset
7
9
  Cursors.reset
@@ -37,7 +39,7 @@ module Vedeu
37
39
  "\e[1;1Hthis is the first" \
38
40
  "\e[2;1Hthis is the second and it is lon" \
39
41
  "\e[3;1Hthis is the third, it is even lo" \
40
- "\e[1;1H\e[?25h"
42
+ "\e[1;1H\e[?25l"
41
43
  )
42
44
  end
43
45
 
@@ -55,7 +57,7 @@ module Vedeu
55
57
  "\e[1;1H \e[1;1H" \
56
58
  "\e[2;1H \e[2;1H" \
57
59
  "\e[3;1H \e[3;1H" \
58
- "\e[1;1H\e[?25h"
60
+ "\e[1;1H\e[?25l"
59
61
  )
60
62
  end
61
63
 
@@ -89,7 +91,7 @@ module Vedeu
89
91
  "\e[1;1Hthis is the first" \
90
92
  "\e[2;1H" \
91
93
  "\e[3;1Hthis is the third, it is even lo" \
92
- "\e[1;1H\e[?25h"
94
+ "\e[1;1H\e[?25l"
93
95
  )
94
96
  end
95
97
 
@@ -139,7 +141,8 @@ module Vedeu
139
141
  )
140
142
  end
141
143
  end
142
-
143
144
  end
144
- end
145
- end
145
+
146
+ end # Render
147
+
148
+ end # Vedeu
@@ -1,17 +1,21 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  class ViewTest < View
5
6
  def render
6
7
  { interfaces: [] }
7
8
  end
8
- end
9
+ end # ViewTest
9
10
 
10
11
  describe View do
12
+
11
13
  describe '.render' do
12
14
  it 'returns' do
13
15
  ViewTest.render.must_equal([])
14
16
  end
15
17
  end
16
- end
17
- end
18
+
19
+ end # View
20
+
21
+ end # Vedeu
@@ -12,25 +12,58 @@ module Vedeu
12
12
  height: 2,
13
13
  },
14
14
  lines: [
15
- { # 53
15
+ {
16
16
  streams: [{
17
- text: 'Something interesting ', # 22
17
+ text: 'Something interesting ',
18
18
  },{
19
- text: 'on this line ', # 13
19
+ text: 'on this line ',
20
20
  },{
21
- text: 'would be cool, eh?' # 18
21
+ text: 'would be cool, eh?'
22
22
  }]
23
- }, { # 49
23
+ }, {
24
24
  streams: [{
25
- text: 'Maybe a lyric, a little ditty ', # 30
25
+ text: 'Maybe a lyric, a little ditty ',
26
26
  },{
27
- text: 'to help you unwind.', # 19
27
+ text: 'to help you unwind.',
28
28
  }]
29
29
  }
30
30
  ]
31
31
  })
32
32
  }
33
33
 
34
- end
34
+ describe '#initialize' do
35
+ it 'returns an instance of itself' do
36
+ Viewport.new(interface).must_be_instance_of(Viewport)
37
+ end
38
+ end
35
39
 
36
- end
40
+ describe '.show' do
41
+ it 'returns an Array' do
42
+ Viewport.show(interface).must_be_instance_of(Array)
43
+ end
44
+
45
+ context 'when there is no content' do
46
+ before { interface.stubs(:content).returns([]) }
47
+
48
+ it 'returns an empty collection' do
49
+ Viewport.show(interface).must_equal([])
50
+ end
51
+ end
52
+
53
+ context 'when there is content, it returns only the visible content ' \
54
+ 'determined by the geometry of the interface and the current ' \
55
+ 'offset stored' do
56
+ it 'returns a collection of lines, each a collection of characters' do
57
+ Viewport.show(interface).must_equal(
58
+ [
59
+ ['S', 'o', 'm', 'e', 't', 'h', 'i', 'n', 'g', ' ', 'i', 'n', 't', 'e', 'r', 'e', 's', 't', 'i', 'n', 'g', ' ', 'o', 'n', ' ', 't', 'h', 'i', 's', ' '],
60
+ ['M', 'a', 'y', 'b', 'e', ' ', 'a', ' ', 'l', 'y', 'r', 'i', 'c', ',', ' ', 'a', ' ', 'l', 'i', 't', 't', 'l', 'e', ' ', 'd', 'i', 't', 't', 'y', ' ']
61
+ ]
62
+ )
63
+ end
64
+ end
65
+ end
66
+
67
+ end # Viewport
68
+
69
+ end # Vedeu
@@ -1,11 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Buffers do
5
6
 
6
- describe '.add' do
7
- before { Buffers.reset }
7
+ before { Buffers.reset }
8
8
 
9
+ describe '.add' do
9
10
  it 'returns the name of the buffer added to storage' do
10
11
  Buffers.add({ name: 'molybdenum' }).must_equal('molybdenum')
11
12
  end
@@ -18,32 +19,71 @@ module Vedeu
18
19
 
19
20
  context 'when the buffer is already registered' do
20
21
  it 'retrieves the buffer in storage, and adds the attributes to the ' \
21
- 'back buffer, preserving the front which may already have content' do
22
+ 'back buffer, preserving the front which may already have content' do
22
23
  skip
23
24
  end
24
25
  end
25
26
 
26
27
  context 'when the buffer was not registered' do
27
28
  it 'stores a new buffer by name, and adds the attributes to the back ' \
28
- 'buffer' do
29
+ 'buffer' do
29
30
  skip
30
31
  end
31
32
  end
32
33
  end
33
34
 
35
+ describe '.back' do
36
+ context 'when the buffer does not exist' do
37
+ it 'raises an exception' do
38
+ proc { Buffers.back('actinium') }.must_raise(BufferNotFound)
39
+ end
40
+ end
41
+
42
+ context 'when the buffer exists' do
43
+ before { Buffers.add({ name: 'mercury' }) }
44
+
45
+ it 'returns a Hash' do
46
+ Buffers.back('mercury').must_be_instance_of(Hash)
47
+ end
48
+
49
+ it 'returns the stored attributes' do
50
+ Buffers.back('mercury').must_equal({ name: 'mercury' })
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '.front' do
56
+ context 'when the buffer does not exist' do
57
+ it 'raises an exception' do
58
+ proc { Buffers.front('mercury') }.must_raise(BufferNotFound)
59
+ end
60
+ end
61
+
62
+ context 'when the buffer exists but there is no content' do
63
+ before { Buffers.add({ name: 'actinium' }) }
64
+
65
+ it 'returns a NilClass' do
66
+ Buffers.front('actinium').must_be_instance_of(NilClass)
67
+ end
68
+ end
69
+ end
70
+
34
71
  describe '.latest' do
35
- context 'when the buffer does not exist by this name' do
36
- it '' do
37
- skip
72
+ context 'when the buffer does not exist' do
73
+ it 'raises an exception' do
74
+ proc { Buffers.front('nobelium') }.must_raise(BufferNotFound)
38
75
  end
39
76
  end
40
77
 
41
- context 'when the buffer can be found by name' do
42
- it '' do
43
- skip
78
+ context 'when the buffer exists and there is content' do
79
+ before { Buffers.add({ name: 'nobelium' }) }
80
+
81
+ it 'returns the stored attributes' do
82
+ Buffers.latest('nobelium').must_equal({ name: 'nobelium' })
44
83
  end
45
84
  end
46
85
  end
47
86
 
48
- end
49
- end
87
+ end # Buffers
88
+
89
+ end # Vedeu
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Cursors do
5
6
 
6
7
  before do
@@ -8,30 +9,6 @@ module Vedeu
8
9
  Registrar.record({ name: 'chromium' })
9
10
  end
10
11
 
11
- describe '#add' do
12
- let(:attributes) { { name: 'chromium' } }
13
-
14
- it 'returns a new Cursor after registering' do
15
- Cursors.add(attributes).must_be_instance_of(Cursor)
16
- end
17
-
18
- it 'returns a new Cursor after updating' do
19
- Cursors.update(attributes).must_be_instance_of(Cursor)
20
- end
21
-
22
- context 'when the attributes do not have the :name key' do
23
- let(:attributes) { { no_name_key: 'some_value' } }
24
-
25
- it 'raises an exception' do
26
- proc { Cursors.update(attributes) }.must_raise(MissingRequired)
27
- end
28
-
29
- it 'raises an exception' do
30
- proc { Cursors.add(attributes) }.must_raise(MissingRequired)
31
- end
32
- end
33
- end
34
-
35
12
  describe '#hide' do
36
13
  it 'sets the state attribute of the Cursor to :hide' do
37
14
  cursor = Cursors.hide
@@ -46,5 +23,6 @@ module Vedeu
46
23
  end
47
24
  end
48
25
 
49
- end
50
- end
26
+ end # Cursors
27
+
28
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Events do
6
+
5
7
  describe '#add' do
6
8
  it 'adds the event' do
7
9
  Events.add(:sulphur) { proc { |x| x } }
@@ -37,5 +39,7 @@ module Vedeu
37
39
  Events.use(:_not_found_).must_be_empty
38
40
  end
39
41
  end
40
- end
41
- end
42
+
43
+ end # Events
44
+
45
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Focus do
6
+
5
7
  before { Focus.reset }
6
8
  after { Focus.reset }
7
9
 
@@ -113,5 +115,6 @@ module Vedeu
113
115
  end
114
116
  end
115
117
 
116
- end
117
- end
118
+ end # Focus
119
+
120
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Groups do
6
+
5
7
  describe '#add' do
6
8
  before { Groups.reset }
7
9
 
@@ -21,5 +23,6 @@ module Vedeu
21
23
  end
22
24
  end
23
25
 
24
- end
25
- end
26
+ end # Groups
27
+
28
+ end # Vedeu
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Interfaces do
5
6
 
6
7
  describe '#add' do
@@ -45,5 +46,6 @@ module Vedeu
45
46
  end
46
47
  end
47
48
 
48
- end
49
- end
49
+ end # Interfaces
50
+
51
+ end # Vedeu