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 Keymaps do
5
6
 
6
7
  describe '#add' do
@@ -147,6 +148,10 @@ module Vedeu
147
148
  it 'returns the defined keys for all interfaces' do
148
149
  Keymaps.interface_keys.must_equal(['d', 'e', 'f'])
149
150
  end
151
+
152
+ it 'returns the defined keys for the specified interface' do
153
+ Keymaps.interface_keys('magnesium').must_equal(['e', 'f'])
154
+ end
150
155
  end
151
156
 
152
157
  describe '#registered?' do
@@ -227,5 +232,6 @@ module Vedeu
227
232
  end
228
233
  end
229
234
 
230
- end
231
- end
235
+ end # Keymaps
236
+
237
+ end # Vedeu
@@ -188,5 +188,6 @@ module Vedeu
188
188
  end
189
189
  end
190
190
 
191
- end
192
- end
191
+ end # Menus
192
+
193
+ end # Vedeu
@@ -1,32 +1,39 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Offsets do
5
6
 
6
- before { Offsets.reset }
7
+ before do
8
+ Interfaces.reset
9
+ Registrar.record({ name: 'thorium' })
10
+ Terminal.console.stubs(:print)
11
+ end
12
+
13
+ context 'when no interfaces are defined' do
14
+ before { Interfaces.reset }
15
+
16
+ it { proc { Offsets.down }.must_raise(NoInterfacesDefined) }
7
17
 
8
- describe '#add' do
9
- it 'raises an exception if a :name attribute is not provided' do
10
- proc { Offsets.add({ no_name: 'no_name' }) }
11
- .must_raise(MissingRequired)
12
- end
18
+ it { proc { Offsets.up }.must_raise(NoInterfacesDefined) }
13
19
 
14
- it 'returns a new instance of Offset once stored' do
15
- Offsets.add({ name: 'praseodymium' }).must_be_instance_of(Offset)
16
- end
20
+ it { proc { Offsets.right }.must_raise(NoInterfacesDefined) }
21
+
22
+ it { proc { Offsets.left }.must_raise(NoInterfacesDefined) }
17
23
  end
18
24
 
19
- describe '#move' do
20
- before { Focus.stubs(:current).returns('praseodymium') }
25
+ context 'when there is at least one interface defined' do
26
+ before { Focus.stubs(:current).returns('thorium') }
27
+
28
+ it { Offsets.down.must_be_instance_of(Array) }
21
29
 
22
- it 'returns an instance of Offset' do
23
- Offsets.move(0, 1).must_be_instance_of(Offset)
24
- end
30
+ it { Offsets.up.must_be_instance_of(Array) }
25
31
 
26
- it 'alters the offset of the interface in focus' do
27
- Offsets.move(0, 1).x.must_equal(1)
28
- end
32
+ it { Offsets.right.must_be_instance_of(Array) }
33
+
34
+ it { Offsets.left.must_be_instance_of(Array) }
29
35
  end
30
36
 
31
- end
32
- end
37
+ end # Offsets
38
+
39
+ end # Vedeu
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe Positional do
6
+
7
+ before do
8
+ Offsets.reset
9
+ Cursors.reset
10
+ Registrar.record({ name: 'chromium' })
11
+ end
12
+
13
+ describe '#add' do
14
+ it 'raises an exception if a :name attribute is not provided' do
15
+ proc { Offsets.add({ no_name: 'no_name' }) }
16
+ .must_raise(MissingRequired)
17
+ end
18
+
19
+ it 'returns a new instance of Offset once stored' do
20
+ Offsets.add({ name: 'praseodymium' }).must_be_instance_of(Offset)
21
+ end
22
+ end
23
+
24
+ describe '#add' do
25
+ let(:attributes) { { name: 'chromium' } }
26
+
27
+ it 'returns a new Cursor after registering' do
28
+ Cursors.add(attributes).must_be_instance_of(Cursor)
29
+ end
30
+
31
+ it 'returns a new Cursor after updating' do
32
+ Cursors.update(attributes).must_be_instance_of(Cursor)
33
+ end
34
+
35
+ context 'when the attributes do not have the :name key' do
36
+ let(:attributes) { { no_name_key: 'some_value' } }
37
+
38
+ it 'raises an exception' do
39
+ proc { Cursors.update(attributes) }.must_raise(MissingRequired)
40
+ end
41
+
42
+ it 'raises an exception' do
43
+ proc { Cursors.add(attributes) }.must_raise(MissingRequired)
44
+ end
45
+ end
46
+ end
47
+
48
+ end # Positional
49
+
50
+ end # Vedeu
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  class TestClass
5
6
  include Coercions
6
7
 
@@ -10,9 +11,10 @@ module Vedeu
10
11
  @attributes = attributes
11
12
  @name = attributes[:name]
12
13
  end
13
- end
14
+ end # TestClass
14
15
 
15
16
  describe Coercions do
17
+
16
18
  describe '.coercer' do
17
19
  [nil, [], {}].each do |empty_value|
18
20
  it 'returns an empty collection when nil or empty' do
@@ -48,5 +50,7 @@ module Vedeu
48
50
  coerced.first.attributes.must_equal({ name: "test3" })
49
51
  end
50
52
  end
51
- end
52
- end
53
+
54
+ end # Coercions
55
+
56
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe ColourTranslator do
6
+
5
7
  describe '#initialize' do
6
8
  it 'returns an instance of itself' do
7
9
  colour = ''
@@ -9,5 +11,7 @@ module Vedeu
9
11
  ColourTranslator.new(colour).must_be_instance_of(ColourTranslator)
10
12
  end
11
13
  end
12
- end
13
- end
14
+
15
+ end # ColourTranslator
16
+
17
+ end # Vedeu
@@ -6,9 +6,10 @@ class VedeuCommonClass
6
6
  def defined_value_test(variable)
7
7
  defined_value?(variable)
8
8
  end
9
- end
9
+ end # VedeuCommonClass
10
10
 
11
11
  module Vedeu
12
+
12
13
  describe Common do
13
14
 
14
15
  describe '#defined_value?' do
@@ -28,5 +29,6 @@ module Vedeu
28
29
  end
29
30
  end
30
31
 
31
- end
32
- end
32
+ end # Common
33
+
34
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Esc do
6
+
5
7
  describe 'colours defined via define_method' do
6
8
  it 'returns an escape sequence for the foreground colour' do
7
9
  Esc.magenta.must_equal("\e[35m")
@@ -111,5 +113,7 @@ module Vedeu
111
113
  Esc.string('underline_off').must_equal("\e[24m")
112
114
  end
113
115
  end
114
- end
115
- end
116
+
117
+ end # Esc
118
+
119
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Event do
6
+
5
7
  let(:closure) { proc { :event_triggered } }
6
8
  let(:options) { {} }
7
9
 
@@ -37,5 +39,7 @@ module Vedeu
37
39
  event.trigger.must_equal(:event_triggered)
38
40
  end
39
41
  end
40
- end
41
- end
42
+
43
+ end # Event
44
+
45
+ end # Vedeu
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe Fixnum do
4
+
4
5
  describe '#columns' do
5
6
  it 'returns the width if the value is in range' do
6
7
  IO.console.stub :winsize, [25, 60] do
@@ -8,10 +9,13 @@ describe Fixnum do
8
9
  end
9
10
  end
10
11
  end
11
- end
12
+
13
+ end # Fixnum
12
14
 
13
15
  module Vedeu
16
+
14
17
  describe Grid do
18
+
15
19
  describe '.columns' do
16
20
  it 'raises an exception if the value is less than 1' do
17
21
  proc { Grid.columns(0) }.must_raise(OutOfRange)
@@ -27,5 +31,7 @@ module Vedeu
27
31
  end
28
32
  end
29
33
  end
30
- end
31
- end
34
+
35
+ end # Grid
36
+
37
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe KeymapValidator do
6
+
5
7
  let(:storage) {
6
8
  {
7
9
  'dubnium' => {
@@ -58,5 +60,6 @@ module Vedeu
58
60
  end
59
61
  end
60
62
 
61
- end
62
- end
63
+ end # KeymapValidator
64
+
65
+ end # Vedeu
@@ -1,6 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Log do
5
- end
6
- end
6
+ end # Log
7
+
8
+ end # Vedeu
@@ -1,10 +1,16 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Menu do
6
+
5
7
  let(:collection) { ['hydrogen', 'carbon', 'nitrogen', 'oxygen'] }
6
8
  let(:menu) { Menu.new(collection) }
7
9
 
10
+ describe '#initialize' do
11
+ it { skip }
12
+ end
13
+
8
14
  describe '#current' do
9
15
  it 'returns the current index' do
10
16
  menu.current.must_equal(0)
@@ -229,5 +235,7 @@ module Vedeu
229
235
  menu.size.must_equal(4)
230
236
  end
231
237
  end
232
- end
233
- end
238
+
239
+ end # Menu
240
+
241
+ end # Vedeu
@@ -1,7 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Position do
6
+
7
+ describe '#initialize' do
8
+ it { skip }
9
+ end
10
+
5
11
  describe '#to_s' do
6
12
  it 'returns an escape sequence when no coordinates are provided' do
7
13
  Position.new.to_s.must_equal("\e[1;1H")
@@ -15,5 +21,7 @@ module Vedeu
15
21
  Position.new(4, 9).to_s { 'test' }.must_equal("\e[4;9Htest\e[4;9H")
16
22
  end
17
23
  end
18
- end
19
- end
24
+
25
+ end # Position
26
+
27
+ end # Vedeu
@@ -10,9 +10,10 @@ module Vedeu
10
10
  style: ['bold']
11
11
  }
12
12
  end
13
- end
13
+ end # PresentationTestClass
14
14
 
15
15
  describe Presentation do
16
+
16
17
  let(:receiver) { PresentationTestClass.new }
17
18
 
18
19
  describe '#colour' do
@@ -56,5 +57,7 @@ module Vedeu
56
57
  )
57
58
  end
58
59
  end
59
- end
60
- end
60
+
61
+ end # Presentation
62
+
63
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe Refresh do
6
+
5
7
  describe '.all' do
6
8
  it 'returns an empty collection when there are no registered ' \
7
9
  'interfaces' do
@@ -32,5 +34,7 @@ module Vedeu
32
34
  proc { Refresh.by_name('') }.must_raise(BufferNotFound)
33
35
  end
34
36
  end
35
- end
36
- end
37
+
38
+ end # Refresh
39
+
40
+ end # Vedeu
@@ -75,6 +75,6 @@ module Vedeu
75
75
 
76
76
  end
77
77
 
78
- end
78
+ end # Registrar
79
79
 
80
- end
80
+ end # Vedeu
@@ -14,7 +14,7 @@ module Vedeu
14
14
  def not_found(name)
15
15
  fail EntityNotFound
16
16
  end
17
- end
17
+ end # RepositoryTestClass
18
18
 
19
19
  describe Repository do
20
20
 
@@ -66,5 +66,6 @@ module Vedeu
66
66
  end
67
67
  end
68
68
 
69
- end
70
- end
69
+ end # Repository
70
+
71
+ end # Vedeu