vedeu 0.5.13 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/bin/vedeu_drb_server +1 -0
  4. data/config/rubocop_enabled.yml +2 -2
  5. data/docs/events.md +2 -0
  6. data/docs/getting_started.md +1 -1
  7. data/examples/drb_app.rb +1 -0
  8. data/examples/editor_app.rb +76 -0
  9. data/lib/vedeu/all.rb +13 -7
  10. data/lib/vedeu/{bindings.rb → bindings/bindings.rb} +2 -0
  11. data/lib/vedeu/bindings/focus.rb +66 -0
  12. data/lib/vedeu/bindings/refresh.rb +77 -0
  13. data/lib/vedeu/bindings/system.rb +19 -88
  14. data/lib/vedeu/buffers/buffer.rb +8 -8
  15. data/lib/vedeu/configuration/api.rb +32 -11
  16. data/lib/vedeu/configuration/cli.rb +8 -0
  17. data/lib/vedeu/cursor/move.rb +1 -0
  18. data/lib/vedeu/distributed/templates/default_configuration.vedeu +1 -0
  19. data/lib/vedeu/{dsl.rb → dsl/dsl.rb} +0 -0
  20. data/lib/vedeu/exceptions.rb +1 -1
  21. data/lib/vedeu/geometry/position.rb +28 -0
  22. data/lib/vedeu/input/capture.rb +76 -0
  23. data/lib/vedeu/input/editor/all.rb +19 -0
  24. data/lib/vedeu/input/editor/cropper.rb +74 -0
  25. data/lib/vedeu/input/editor/document.rb +254 -0
  26. data/lib/vedeu/input/editor/documents.rb +18 -0
  27. data/lib/vedeu/input/editor/editor.rb +100 -0
  28. data/lib/vedeu/input/editor/line.rb +143 -0
  29. data/lib/vedeu/input/editor/lines.rb +199 -0
  30. data/lib/vedeu/input/editor/virtual_cursor.rb +167 -0
  31. data/lib/vedeu/input/input.rb +9 -93
  32. data/lib/vedeu/input/input_translator.rb +155 -0
  33. data/lib/vedeu/internal_api.rb +9 -0
  34. data/lib/vedeu/log/lockless_log_device.rb +1 -1
  35. data/lib/vedeu/models/escape.rb +7 -8
  36. data/lib/vedeu/output/direct.rb +59 -0
  37. data/lib/vedeu/output/renderers/terminal.rb +8 -0
  38. data/lib/vedeu/output/viewport.rb +2 -3
  39. data/lib/vedeu/{plugins.rb → plugins/plugins.rb} +0 -0
  40. data/lib/vedeu/refresh/refresh_cursor.rb +1 -0
  41. data/lib/vedeu/{repositories.rb → repositories/repositories.rb} +0 -0
  42. data/lib/vedeu/terminal/content.rb +88 -0
  43. data/lib/vedeu/terminal/mode.rb +79 -0
  44. data/lib/vedeu/{terminal.rb → terminal/terminal.rb} +9 -25
  45. data/lib/vedeu/version.rb +1 -1
  46. data/test/lib/vedeu/{bindings_test.rb → bindings/bindings_test.rb} +0 -0
  47. data/test/lib/vedeu/bindings/focus_test.rb +19 -0
  48. data/test/lib/vedeu/bindings/refresh_test.rb +19 -0
  49. data/test/lib/vedeu/bindings/system_test.rb +1 -6
  50. data/test/lib/vedeu/borders/render_border_test.rb +43 -10
  51. data/test/lib/vedeu/buffers/buffer_test.rb +18 -0
  52. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +15 -0
  53. data/test/lib/vedeu/configuration/api_test.rb +18 -2
  54. data/test/lib/vedeu/configuration/cli_test.rb +5 -0
  55. data/test/lib/vedeu/cursor/move_test.rb +1 -1
  56. data/test/lib/vedeu/dsl/dsl_test.rb +8 -0
  57. data/test/lib/vedeu/dsl/shared_test.rb +12 -0
  58. data/test/lib/vedeu/{output → esc}/esc_test.rb +0 -0
  59. data/test/lib/vedeu/geometry/position_test.rb +56 -0
  60. data/test/lib/vedeu/input/capture_test.rb +63 -0
  61. data/test/lib/vedeu/input/editor/cropper_test.rb +82 -0
  62. data/test/lib/vedeu/input/editor/document_test.rb +190 -0
  63. data/test/lib/vedeu/input/editor/documents_test.rb +17 -0
  64. data/test/lib/vedeu/input/editor/editor_test.rb +170 -0
  65. data/test/lib/vedeu/input/editor/line_test.rb +333 -0
  66. data/test/lib/vedeu/input/editor/lines_test.rb +561 -0
  67. data/test/lib/vedeu/input/editor/virtual_cursor_test.rb +184 -0
  68. data/test/lib/vedeu/input/input_test.rb +20 -4
  69. data/test/lib/vedeu/input/input_translator_test.rb +32 -0
  70. data/test/lib/vedeu/internal_api_test.rb +1 -0
  71. data/test/lib/vedeu/models/escape_test.rb +6 -6
  72. data/test/lib/vedeu/models/views/view_test.rb +15 -2
  73. data/test/lib/vedeu/null/null_test.rb +8 -0
  74. data/test/lib/vedeu/output/direct_test.rb +70 -0
  75. data/test/lib/vedeu/{plugins_test.rb → plugins/plugins_test.rb} +0 -0
  76. data/test/lib/vedeu/{repositories_test.rb → repositories/repositories_test.rb} +0 -0
  77. data/test/lib/vedeu/terminal/content_test.rb +100 -0
  78. data/test/lib/vedeu/terminal/mode_test.rb +95 -0
  79. data/test/lib/vedeu/{terminal_test.rb → terminal/terminal_test.rb} +23 -23
  80. data/test/test_helper.rb +1 -0
  81. metadata +67 -20
  82. data/lib/vedeu/terminal_mode.rb +0 -59
  83. data/test/lib/vedeu/terminal_mode_test.rb +0 -72
@@ -7,16 +7,24 @@ module Vedeu
7
7
  let(:described) { Vedeu::RenderBorder }
8
8
  let(:instance) { described.new(border) }
9
9
  let(:border) {
10
- Vedeu::Border.new(enabled: enabled,
11
- name: _name,
12
- title: title,
13
- caption: caption)
10
+ Vedeu::Border.new(enabled: enabled,
11
+ name: _name,
12
+ title: title,
13
+ caption: caption,
14
+ show_top: show_top,
15
+ show_bottom: show_bottom,
16
+ show_left: show_left,
17
+ show_right: show_right)
14
18
  }
15
19
  let(:visible) { false }
16
20
  let(:enabled) { false }
17
21
  let(:_name) { 'Vedeu::RenderBorder' }
18
22
  let(:title) {}
19
23
  let(:caption) {}
24
+ let(:show_top) { true }
25
+ let(:show_bottom) { true }
26
+ let(:show_left) { true }
27
+ let(:show_right) { true }
20
28
 
21
29
  it { described.must_respond_to(:with) }
22
30
 
@@ -57,28 +65,53 @@ module Vedeu
57
65
  let(:title) { 'T' }
58
66
 
59
67
  # @todo Add more tests.
60
- # it { skip }
68
+ it { subject.size.must_equal(18) }
61
69
  end
62
70
 
63
71
  context 'and a title is not given' do
64
72
  # @todo Add more tests.
65
- # it { skip }
73
+ it { subject.size.must_equal(18) }
66
74
  end
67
75
 
68
76
  context 'and a caption is given' do
69
77
  let(:caption) { 'C' }
70
78
 
71
79
  # @todo Add more tests.
72
- # it { skip }
80
+ it { subject.size.must_equal(18) }
73
81
  end
74
82
 
75
83
  context 'and a caption is not given' do
76
84
  # @todo Add more tests.
77
- # it { skip }
85
+ it { subject.size.must_equal(18) }
78
86
  end
79
87
 
80
- # @todo Add more tests.
81
- # it { skip }
88
+ context 'and the left side is disabled' do
89
+ let(:show_left) { false }
90
+
91
+ # @todo Add more tests.
92
+ it { subject.size.must_equal(16) }
93
+ end
94
+
95
+ context 'and the right side is disabled' do
96
+ let(:show_right) { false }
97
+
98
+ # @todo Add more tests.
99
+ it { subject.size.must_equal(16) }
100
+ end
101
+
102
+ context 'and the top side is disabled' do
103
+ let(:show_top) { false }
104
+
105
+ # @todo Add more tests.
106
+ it { subject.size.must_equal(13) }
107
+ end
108
+
109
+ context 'and the bottom side is disabled' do
110
+ let(:show_bottom) { false }
111
+
112
+ # @todo Add more tests.
113
+ it { subject.size.must_equal(13) }
114
+ end
82
115
  end
83
116
  end
84
117
  end
@@ -65,6 +65,24 @@ module Vedeu
65
65
  end
66
66
  end
67
67
 
68
+ describe '#clear' do
69
+ let(:emptiness) { mock }
70
+
71
+ before do
72
+ Vedeu::Clear::NamedInterface.stubs(:render).returns(emptiness)
73
+ Vedeu::Output.stubs(:render).returns(emptiness)
74
+ end
75
+
76
+ subject { instance.clear }
77
+
78
+ it {
79
+ Vedeu::Clear::NamedInterface.expects(:render).with(_name).
80
+ returns(emptiness)
81
+ Vedeu::Output.expects(:render).with(emptiness)
82
+ subject
83
+ }
84
+ end
85
+
68
86
  describe '#front?' do
69
87
  subject { instance.front? }
70
88
 
@@ -27,12 +27,22 @@ module Vedeu
27
27
  describe '.output' do
28
28
  let(:data) {}
29
29
 
30
+ before do
31
+ Vedeu.stubs(:width).returns(3)
32
+ Vedeu.stubs(:height).returns(3)
33
+ end
34
+
30
35
  subject { described.output(data) }
31
36
 
32
37
  it { subject.must_be_instance_of(Array) }
33
38
  end
34
39
 
35
40
  describe '#cells' do
41
+ before do
42
+ Vedeu.stubs(:width).returns(3)
43
+ Vedeu.stubs(:height).returns(3)
44
+ end
45
+
36
46
  subject { instance.cells }
37
47
 
38
48
  it { subject.must_be_instance_of(Array) }
@@ -77,6 +87,11 @@ module Vedeu
77
87
  end
78
88
 
79
89
  describe '#render' do
90
+ before do
91
+ Vedeu.stubs(:width).returns(3)
92
+ Vedeu.stubs(:height).returns(3)
93
+ end
94
+
80
95
  subject { instance.render }
81
96
 
82
97
  it { subject.must_be_instance_of(String) }
@@ -171,6 +171,15 @@ module Vedeu
171
171
  end
172
172
  end
173
173
 
174
+ describe '#fake!' do
175
+ it { instance.must_respond_to(:fake) }
176
+
177
+ it 'sets the option to the desired value' do
178
+ configuration = Vedeu.configure { fake! }
179
+ configuration.terminal_mode.must_equal(:fake)
180
+ end
181
+ end
182
+
174
183
  describe '#raw!' do
175
184
  subject { Vedeu.configure { raw! } }
176
185
 
@@ -312,14 +321,21 @@ module Vedeu
312
321
  end
313
322
 
314
323
  describe '#terminal_mode' do
315
- context 'when setting to :raw mode' do
324
+ context 'when setting to :fake mode' do
325
+ it {
326
+ configuration = Vedeu.configure { terminal_mode(:fake) }
327
+ configuration.terminal_mode.must_equal(:fake)
328
+ }
329
+ end
330
+
331
+ context 'when setting to :cooked mode' do
316
332
  it {
317
333
  configuration = Vedeu.configure { terminal_mode(:raw) }
318
334
  configuration.terminal_mode.must_equal(:raw)
319
335
  }
320
336
  end
321
337
 
322
- context 'when setting to :cooked mode' do
338
+ context 'when setting to :raw mode' do
323
339
  it {
324
340
  configuration = Vedeu.configure { terminal_mode(:raw) }
325
341
  configuration.terminal_mode.must_equal(:raw)
@@ -139,6 +139,11 @@ module Vedeu
139
139
  Configuration.terminal_mode.must_equal(:cooked)
140
140
  end
141
141
 
142
+ it '--fake' do
143
+ Configuration.configure(['--fake'])
144
+ Configuration.terminal_mode.must_equal(:fake)
145
+ end
146
+
142
147
  it '--raw' do
143
148
  Configuration.configure(['--raw'])
144
149
  Configuration.terminal_mode.must_equal(:raw)
@@ -30,7 +30,7 @@ module Vedeu
30
30
  }
31
31
 
32
32
  before do
33
- IO.console.stubs(:winsize).returns([25, 80])
33
+ IO.console.stubs(:winsize).returns([10, 40])
34
34
  IO.console.stubs(:print)
35
35
 
36
36
  Vedeu.borders.stubs(:by_name).returns(border)
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe DSL do
6
+ end # DSL
7
+
8
+ end # Vedeu
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module DSL
6
+
7
+ describe Shared do
8
+ end # Shared
9
+
10
+ end # DSL
11
+
12
+ end # Vedeu
File without changes
@@ -157,6 +157,62 @@ module Vedeu
157
157
  end
158
158
  end
159
159
 
160
+ describe '#down' do
161
+ subject { instance.down }
162
+
163
+ it { subject.must_be_instance_of(Vedeu::Position) }
164
+ it { subject.y.must_equal(13) }
165
+ it { subject.x.must_equal(19) }
166
+
167
+ context 'when y is 0' do
168
+ let(:y) { 0 }
169
+
170
+ it { subject.y.must_equal(2) }
171
+ end
172
+ end
173
+
174
+ describe '#left' do
175
+ subject { instance.left }
176
+
177
+ it { subject.must_be_instance_of(Vedeu::Position) }
178
+ it { subject.y.must_equal(12) }
179
+ it { subject.x.must_equal(18) }
180
+
181
+ context 'when x is 0' do
182
+ let(:x) { 0 }
183
+
184
+ it { subject.x.must_equal(1) }
185
+ end
186
+ end
187
+
188
+ describe '#right' do
189
+ subject { instance.right }
190
+
191
+ it { subject.must_be_instance_of(Vedeu::Position) }
192
+ it { subject.y.must_equal(12) }
193
+ it { subject.x.must_equal(20) }
194
+
195
+ context 'when x is 0' do
196
+ let(:x) { 0 }
197
+
198
+ it { subject.x.must_equal(2) }
199
+ end
200
+ end
201
+
202
+ describe '#up' do
203
+ subject { instance.up }
204
+
205
+ it { subject.must_be_instance_of(Vedeu::Position) }
206
+ it { subject.y.must_equal(11) }
207
+ it { subject.x.must_equal(19) }
208
+
209
+ context 'when y is 0' do
210
+ let(:y) { 0 }
211
+
212
+ it { subject.y.must_equal(1) }
213
+ end
214
+ end
215
+
160
216
  end # Position
161
217
 
162
218
  end # Vedeu
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Editor
6
+
7
+ describe Capture do
8
+
9
+ let(:described) { Vedeu::Editor::Capture }
10
+ let(:instance) { described.new(console) }
11
+ let(:console) { mock }
12
+
13
+ describe '#initialize' do
14
+ it { instance.must_be_instance_of(described) }
15
+ it { instance.instance_variable_get('@console').must_equal(console) }
16
+ end
17
+
18
+ describe '.read' do
19
+ subject { described.read(console) }
20
+
21
+ before do
22
+ Vedeu::Terminal.stubs(:console).returns(console)
23
+ console.stubs(:getch).returns(keys)
24
+ end
25
+
26
+ context 'when nothing is given' do
27
+ let(:keys) { nil }
28
+ end
29
+
30
+ context 'when a single keypress is given' do
31
+ let(:keys) { 'a' }
32
+
33
+ it { subject.must_equal('a') }
34
+ end
35
+
36
+ context 'when a ctrl+keypress is given' do
37
+ let(:keys) { "\u0001" }
38
+
39
+ it { subject.must_equal(:ctrl_a) }
40
+ end
41
+
42
+ context 'when a shift+keypress is given' do
43
+ let(:keys) { 'A' }
44
+
45
+ it { subject.must_equal('A') }
46
+ end
47
+
48
+ context 'when a alt+keypress is given' do
49
+ end
50
+
51
+ context 'when a super+keypress is given' do
52
+ end
53
+ end
54
+
55
+ describe '#read' do
56
+ it { instance.must_respond_to(:read) }
57
+ end
58
+
59
+ end # Capture
60
+
61
+ end # Editor
62
+
63
+ end # Vedeu
@@ -0,0 +1,82 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Editor
6
+
7
+ describe Cropper do
8
+
9
+ let(:described) { Vedeu::Editor::Cropper }
10
+ let(:instance) {
11
+ described.new(lines: lines,
12
+ height: height,
13
+ width: width,
14
+ ox: ox,
15
+ oy: oy)
16
+ }
17
+ let(:lines) { Vedeu::Editor::Lines.new }
18
+ let(:height) { 3 }
19
+ let(:width) { 5 }
20
+ let(:ox) { 1 }
21
+ let(:oy) { 1 }
22
+
23
+ describe '#initialize' do
24
+ it { instance.must_be_instance_of(described) }
25
+ it { instance.instance_variable_get('@lines').must_equal(lines) }
26
+ it { instance.instance_variable_get('@height').must_equal(height) }
27
+ it { instance.instance_variable_get('@width').must_equal(width) }
28
+ it { instance.instance_variable_get('@ox').must_equal(ox) }
29
+ it { instance.instance_variable_get('@oy').must_equal(oy) }
30
+ end
31
+
32
+ describe '#cropped' do
33
+ subject { instance.cropped }
34
+
35
+ context 'when there are no lines' do
36
+ let(:lines) { Vedeu::Editor::Lines.new }
37
+
38
+ it { subject.must_equal([]) }
39
+ end
40
+
41
+ context 'when there are lines' do
42
+ let(:lines) {
43
+ Vedeu::Editor::Lines.new([
44
+ Vedeu::Editor::Line.new('Hydrogen'),
45
+ Vedeu::Editor::Line.new('Helium'),
46
+ Vedeu::Editor::Line.new('Lithium'),
47
+ Vedeu::Editor::Line.new('Beryllium'),
48
+ Vedeu::Editor::Line.new('Boron'),
49
+ ])
50
+ }
51
+
52
+ it { subject.must_equal(['elium', 'ithiu', 'eryll']) }
53
+
54
+ context 'when oy is near the bottom' do
55
+ let(:oy) { 6 }
56
+
57
+ it { subject.must_equal([]) }
58
+ end
59
+
60
+ context 'when ox is nearly past the content width' do
61
+ let(:oy) { 5 }
62
+ let(:ox) { 10 }
63
+
64
+ it 'returns only that which is visible, discarding empty lines' do
65
+ subject.must_equal([])
66
+ end
67
+ end
68
+
69
+ context 'when both oy and ox are effectively out of range' do
70
+ let(:oy) { 10 }
71
+ let(:ox) { 20 }
72
+
73
+ it { subject.must_equal([]) }
74
+ end
75
+ end
76
+ end
77
+
78
+ end # Cropper
79
+
80
+ end # Editor
81
+
82
+ end # Vedeu