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
@@ -0,0 +1,184 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Editor
6
+
7
+ describe VirtualCursor do
8
+
9
+ let(:described) { Vedeu::Editor::VirtualCursor }
10
+ let(:instance) {
11
+ described.new(y: y,
12
+ x: x,
13
+ bx: bx,
14
+ by: by,
15
+ byn: byn,
16
+ bxn: bxn,
17
+ oy: oy,
18
+ ox: ox)
19
+ }
20
+ let(:y) { 0 }
21
+ let(:x) { 0 }
22
+ let(:by) { 1 }
23
+ let(:bx) { 1 }
24
+ let(:byn) { 6 }
25
+ let(:bxn) { 6 }
26
+ let(:oy) { 0 }
27
+ let(:ox) { 0 }
28
+
29
+ describe '#initialize' do
30
+ it { instance.must_be_instance_of(described) }
31
+ it { instance.instance_variable_get('@y').must_equal(y) }
32
+ it { instance.instance_variable_get('@x').must_equal(x) }
33
+ it { instance.instance_variable_get('@by').must_equal(by) }
34
+ it { instance.instance_variable_get('@bx').must_equal(bx) }
35
+ it { instance.instance_variable_get('@byn').must_equal(byn) }
36
+ it { instance.instance_variable_get('@bxn').must_equal(bxn) }
37
+ it { instance.instance_variable_get('@oy').must_equal(0) }
38
+ it { instance.instance_variable_get('@ox').must_equal(0) }
39
+
40
+ context 'when x is nil' do
41
+ it { instance.instance_variable_get('@x').must_equal(0) }
42
+ end
43
+
44
+ context 'when x is not nil' do
45
+ let(:x) { 3 }
46
+
47
+ it { instance.instance_variable_get('@x').must_equal(3) }
48
+ end
49
+
50
+ context 'when y is nil' do
51
+ it { instance.instance_variable_get('@y').must_equal(0) }
52
+ end
53
+
54
+ context 'when y is not nil' do
55
+ let(:y) { 6 }
56
+
57
+ it { instance.instance_variable_get('@y').must_equal(6) }
58
+ end
59
+ end
60
+
61
+ describe '#accessors' do
62
+ it { instance.must_respond_to(:bx) }
63
+ it { instance.must_respond_to(:bx=) }
64
+ it { instance.must_respond_to(:by) }
65
+ it { instance.must_respond_to(:by=) }
66
+ it { instance.must_respond_to(:bxn) }
67
+ it { instance.must_respond_to(:bxn=) }
68
+ it { instance.must_respond_to(:byn) }
69
+ it { instance.must_respond_to(:byn=) }
70
+ it { instance.must_respond_to(:ox) }
71
+ it { instance.must_respond_to(:ox=) }
72
+ it { instance.must_respond_to(:oy) }
73
+ it { instance.must_respond_to(:oy=) }
74
+ it { instance.must_respond_to(:x) }
75
+ it { instance.must_respond_to(:x=) }
76
+ it { instance.must_respond_to(:y) }
77
+ it { instance.must_respond_to(:y=) }
78
+ end
79
+
80
+ describe '#bol' do
81
+ let(:x) { 11 }
82
+ let(:ox) { 4 }
83
+
84
+ subject { instance.bol }
85
+
86
+ it { subject.must_be_instance_of(described) }
87
+
88
+ it { subject.x.must_equal(0) }
89
+ it { subject.ox.must_equal(0) }
90
+ end
91
+
92
+ describe '#down' do
93
+ let(:y) { 11 }
94
+
95
+ subject { instance.down }
96
+
97
+ it { subject.must_be_instance_of(described) }
98
+
99
+ it { subject.y.must_equal(12) }
100
+ end
101
+
102
+ describe '#left' do
103
+ let(:x) { 11 }
104
+ let(:ox) { 4 }
105
+
106
+ subject { instance.left }
107
+
108
+ it { subject.must_be_instance_of(described) }
109
+
110
+ it { subject.x.must_equal(10) }
111
+ it { subject.ox.must_equal(3) }
112
+ end
113
+
114
+ describe '#reset!' do
115
+ let(:x) { 11 }
116
+ let(:y) { 5 }
117
+ let(:ox) { 4 }
118
+ let(:oy) { 2 }
119
+
120
+ subject { instance.reset! }
121
+
122
+ it { subject.must_be_instance_of(described) }
123
+ it { subject.x.must_equal(0) }
124
+ it { subject.y.must_equal(0) }
125
+ it { subject.ox.must_equal(0) }
126
+ it { subject.oy.must_equal(0) }
127
+ end
128
+
129
+ describe '#right' do
130
+ let(:x) { 11 }
131
+
132
+ subject { instance.right }
133
+
134
+ it { subject.must_be_instance_of(described) }
135
+
136
+ it { subject.x.must_equal(12) }
137
+ end
138
+
139
+ describe '#to_s' do
140
+ let(:x) { 11 }
141
+ let(:y) { 5 }
142
+
143
+ subject { instance.to_s }
144
+
145
+ it { subject.must_be_instance_of(String) }
146
+
147
+ it { subject.must_equal("\e[6;6H\e[?25h") }
148
+ end
149
+
150
+ describe '#up' do
151
+ let(:y) { 11 }
152
+ let(:oy) { 2 }
153
+
154
+ subject { instance.up }
155
+
156
+ it { subject.must_be_instance_of(described) }
157
+
158
+ it { subject.y.must_equal(10) }
159
+ it { subject.oy.must_equal(1) }
160
+ end
161
+
162
+ describe '#x' do
163
+ subject { instance.x }
164
+
165
+ it { subject.must_be_instance_of(Fixnum) }
166
+
167
+ # @todo Add more tests.
168
+ # it { skip }
169
+ end
170
+
171
+ describe '#y' do
172
+ subject { instance.x }
173
+
174
+ it { subject.must_be_instance_of(Fixnum) }
175
+
176
+ # @todo Add more tests.
177
+ # it { skip }
178
+ end
179
+
180
+ end # VirtualCursor
181
+
182
+ end # Editor
183
+
184
+ end # Vedeu
@@ -18,14 +18,16 @@ module Vedeu
18
18
  describe '.capture' do
19
19
  before do
20
20
  reader.stubs(:raw_mode?).returns(raw_mode)
21
+ reader.stubs(:fake_mode?).returns(fake_mode)
21
22
  Vedeu.stubs(:trigger).returns([false])
22
23
  end
23
24
 
24
25
  subject { described.capture(reader) }
25
26
 
26
27
  context 'when in cooked mode' do
27
- let(:raw_mode) { false }
28
- let(:command) { 'help' }
28
+ let(:raw_mode) { false }
29
+ let(:fake_mode) { false }
30
+ let(:command) { 'help' }
29
31
 
30
32
  before { reader.stubs(:read).returns(command) }
31
33
 
@@ -35,9 +37,23 @@ module Vedeu
35
37
  end
36
38
  end
37
39
 
40
+ context 'when in fake mode' do
41
+ let(:raw_mode) { false }
42
+ let(:fake_mode) { true }
43
+ let(:keypress) { 'b' }
44
+
45
+ before { reader.stubs(:read).returns(keypress) }
46
+
47
+ it 'triggers an event with the keypress' do
48
+ Vedeu.expects(:trigger).with(:_editor_, keypress)
49
+ subject
50
+ end
51
+ end
52
+
38
53
  context 'when in raw mode' do
39
- let(:raw_mode) { true }
40
- let(:keypress) { 'a' }
54
+ let(:raw_mode) { true }
55
+ let(:fake_mode) { false }
56
+ let(:keypress) { 'a' }
41
57
 
42
58
  before { reader.stubs(:read).returns(keypress) }
43
59
 
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe InputTranslator do
6
+
7
+ let(:described) { Vedeu::InputTranslator }
8
+ let(:instance) { described.new(code) }
9
+ let(:code) {}
10
+
11
+ describe '#initialize' do
12
+ it { instance.must_be_instance_of(described) }
13
+ it { instance.instance_variable_get('@code').must_equal(code) }
14
+ end
15
+
16
+ describe '.translate' do
17
+ context 'when the code is not recognised' do
18
+ it { described.translate('a').must_equal('a') }
19
+ end
20
+
21
+ context 'when the code is recognised' do
22
+ it { described.translate("\e[H").must_equal(:home) }
23
+ end
24
+ end
25
+
26
+ describe '#translate' do
27
+ it { instance.must_respond_to(:translate) }
28
+ end
29
+
30
+ end # InputTranslator
31
+
32
+ end # Vedeu
@@ -9,6 +9,7 @@ module Vedeu
9
9
  it { Vedeu.must_respond_to(:buffers) }
10
10
  it { Vedeu.must_respond_to(:cursors) }
11
11
  it { Vedeu.must_respond_to(:debug) }
12
+ it { Vedeu.must_respond_to(:documents) }
12
13
  it { Vedeu.must_respond_to(:events) }
13
14
  it { Vedeu.must_respond_to(:foreground_colours) }
14
15
  it { Vedeu.must_respond_to(:geometries) }
@@ -24,8 +24,12 @@ module Vedeu
24
24
  it { instance.must_respond_to(:value) }
25
25
  end
26
26
 
27
- describe '#colour' do
28
- it { instance.colour.must_equal('') }
27
+ describe '#null' do
28
+ it { instance.null.must_equal(nil) }
29
+ it { instance.background.must_equal(nil) }
30
+ it { instance.colour.must_equal(nil) }
31
+ it { instance.foreground.must_equal(nil) }
32
+ it { instance.style.must_equal(nil) }
29
33
  end
30
34
 
31
35
  describe '#eql?' do
@@ -48,10 +52,6 @@ module Vedeu
48
52
  it { instance.position.must_be_instance_of(Vedeu::Position) }
49
53
  end
50
54
 
51
- describe '#style' do
52
- it { instance.style.must_equal('') }
53
- end
54
-
55
55
  describe '#value' do
56
56
  it { instance.value.must_be_instance_of(String) }
57
57
  end
@@ -83,8 +83,21 @@ module Vedeu
83
83
  end
84
84
 
85
85
  describe '#visible?' do
86
- # @todo Add more tests.
87
- # it { skip }
86
+ subject { instance.visible? }
87
+
88
+ context 'when the interface is visible' do
89
+ let(:interface) { Vedeu::Interface.new(visible: true) }
90
+
91
+ before do
92
+ Vedeu.interfaces.stubs(:by_name).with(_name).returns(interface)
93
+ end
94
+
95
+ it { subject.must_equal(true) }
96
+ end
97
+
98
+ context 'when the interface is not visible' do
99
+ it { subject.must_equal(false) }
100
+ end
88
101
  end
89
102
 
90
103
  end # View
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe Null do
6
+ end # Null
7
+
8
+ end # Vedeu
@@ -0,0 +1,70 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe Direct do
6
+
7
+ let(:described) { Vedeu::Direct }
8
+ let(:instance) { described.new(value: _value, x: x, y: y) }
9
+ let(:_value) {}
10
+ let(:x) {}
11
+ let(:y) {}
12
+
13
+ describe '#initialize' do
14
+ it { instance.must_be_instance_of(described) }
15
+
16
+ context 'when no value is given' do
17
+ it { instance.instance_variable_get('@value').must_equal('') }
18
+ end
19
+
20
+ context 'when a value is given' do
21
+ let(:_value) { 'some value' }
22
+
23
+ it { instance.instance_variable_get('@value').must_equal('some value') }
24
+ end
25
+
26
+ context 'when no x is given' do
27
+ it { instance.instance_variable_get('@x').must_equal(1) }
28
+ end
29
+
30
+ context 'when an x is given' do
31
+ let(:x) { 6 }
32
+ it { instance.instance_variable_get('@x').must_equal(6) }
33
+ end
34
+
35
+ context 'when no y is given' do
36
+ it { instance.instance_variable_get('@y').must_equal(1) }
37
+ end
38
+
39
+ context 'when a y is given' do
40
+ let(:y) { 3 }
41
+
42
+ it { instance.instance_variable_get('@y').must_equal(3) }
43
+ end
44
+ end
45
+
46
+ describe '.write' do
47
+ before { Vedeu::Terminal.stubs(:output) }
48
+
49
+ subject { described.write(value: _value, x: x, y: y) }
50
+
51
+ it { subject.must_be_instance_of(String) }
52
+
53
+ context 'when a value is given' do
54
+ let(:_value) { 'some value' }
55
+
56
+ it { subject.must_equal("\e[1;1Hsome value") }
57
+ end
58
+
59
+ context 'when a value is not given' do
60
+ it { subject.must_equal("\e[1;1H") }
61
+ end
62
+ end
63
+
64
+ describe '#write' do
65
+ it { instance.must_respond_to(:write) }
66
+ end
67
+
68
+ end # Direct
69
+
70
+ end # Vedeu
@@ -0,0 +1,100 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Terminal
6
+
7
+ describe Content do
8
+
9
+ let(:described) { Vedeu::Terminal::Content }
10
+
11
+ describe '.valid?' do
12
+ let(:char) { mock }
13
+
14
+ subject { described.valid?(char) }
15
+
16
+ context 'when the char does not respond to :position' do
17
+ it { subject.must_equal(false) }
18
+ end
19
+
20
+ context 'when the char responds to :position' do
21
+ let(:position) { mock }
22
+
23
+ before do
24
+ char.stubs(:position).returns(position)
25
+ position.stubs(:x).returns(x)
26
+ position.stubs(:y).returns(y)
27
+ end
28
+
29
+ context 'but the y value is not present' do
30
+ let(:x) { 2 }
31
+ let(:y) {}
32
+
33
+ it { subject.must_equal(false) }
34
+ end
35
+
36
+ context 'but the x value is not present' do
37
+ let(:x) {}
38
+ let(:y) { 5 }
39
+
40
+ it { subject.must_equal(false) }
41
+ end
42
+
43
+ context 'and both y and x values are present' do
44
+ let(:x) { 2 }
45
+ let(:y) { 5 }
46
+
47
+ it { subject.must_equal(true) }
48
+ end
49
+ end
50
+ end
51
+
52
+ describe '#store' do
53
+ let(:char) {}
54
+
55
+ subject { described.store(char) }
56
+ end
57
+
58
+ describe '#stores' do
59
+ let(:chars) {}
60
+
61
+ subject { described.stores(chars) }
62
+ end
63
+
64
+ describe '#write' do
65
+ subject { described.write }
66
+
67
+ context 'when logging is enabled' do
68
+ # before { Vedeu::Configuration.stubs(:log?).returns(true) }
69
+ # before { File.stubs(:write) }
70
+
71
+ # it {
72
+ # File.expects(:write)
73
+ # subject
74
+ # }
75
+ end
76
+
77
+ context 'when logging is not enabled' do
78
+ before { Vedeu::Configuration.stubs(:log?).returns(false) }
79
+
80
+ it { subject.must_equal(nil) }
81
+ end
82
+ end
83
+
84
+ describe '#reprocess' do
85
+ subject { described.reprocess }
86
+ end
87
+
88
+ describe '#reset' do
89
+ subject { described.reset }
90
+
91
+ it { subject.must_be_instance_of(Hash) }
92
+
93
+ it { subject.must_be_empty }
94
+ end
95
+
96
+ end # Content
97
+
98
+ end # Terminal
99
+
100
+ end # Vedeu