vedeu 0.6.9 → 0.6.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/lib/vedeu/all.rb +3 -3
  4. data/lib/vedeu/api/external.rb +194 -0
  5. data/lib/vedeu/api/internal.rb +173 -0
  6. data/lib/vedeu/application/controller.rb +3 -2
  7. data/lib/vedeu/bindings/application.rb +1 -1
  8. data/lib/vedeu/bindings/drb.rb +2 -3
  9. data/lib/vedeu/bindings/movement.rb +1 -1
  10. data/lib/vedeu/buffers/all.rb +0 -2
  11. data/lib/vedeu/colours/translator.rb +2 -1
  12. data/lib/vedeu/common.rb +4 -2
  13. data/lib/vedeu/configuration/api.rb +1 -1
  14. data/lib/vedeu/configuration/cli.rb +1 -1
  15. data/lib/vedeu/cursors/repository.rb +1 -1
  16. data/lib/vedeu/editor/insert.rb +12 -13
  17. data/lib/vedeu/geometry/position.rb +1 -1
  18. data/lib/vedeu/models/cell.rb +35 -21
  19. data/lib/vedeu/models/escape.rb +18 -1
  20. data/lib/vedeu/models/page.rb +20 -10
  21. data/lib/vedeu/models/row.rb +18 -8
  22. data/lib/vedeu/models/views/char.rb +9 -7
  23. data/lib/vedeu/models/views/view.rb +1 -1
  24. data/lib/vedeu/output/compressor.rb +22 -14
  25. data/lib/vedeu/output/output.rb +1 -10
  26. data/lib/vedeu/output/renderers/escape_sequence.rb +8 -4
  27. data/lib/vedeu/output/renderers/file.rb +7 -23
  28. data/lib/vedeu/output/renderers/html.rb +47 -26
  29. data/lib/vedeu/output/renderers/json.rb +11 -16
  30. data/lib/vedeu/output/renderers/null.rb +1 -1
  31. data/lib/vedeu/output/renderers/renderer_options.rb +2 -1
  32. data/lib/vedeu/output/renderers/terminal.rb +7 -15
  33. data/lib/vedeu/output/renderers/text.rb +1 -1
  34. data/lib/vedeu/output/viewport.rb +154 -143
  35. data/lib/vedeu/repositories/collection.rb +2 -2
  36. data/lib/vedeu/repositories/model.rb +25 -26
  37. data/lib/vedeu/repositories/registerable.rb +9 -8
  38. data/lib/vedeu/repositories/repository.rb +21 -16
  39. data/lib/vedeu/repositories/store.rb +6 -4
  40. data/lib/vedeu/runtime/bootstrap.rb +7 -5
  41. data/lib/vedeu/runtime/main_loop.rb +2 -0
  42. data/lib/vedeu/runtime/router.rb +155 -149
  43. data/lib/vedeu/templating/decoder.rb +8 -5
  44. data/lib/vedeu/templating/encoder.rb +6 -4
  45. data/lib/vedeu/templating/template.rb +2 -2
  46. data/lib/vedeu/templating/view_template.rb +8 -7
  47. data/lib/vedeu/terminal/buffer.rb +132 -0
  48. data/lib/vedeu/terminal/terminal.rb +0 -5
  49. data/lib/vedeu/version.rb +1 -1
  50. data/lib/vedeu.rb +2 -2
  51. data/out_ +50 -0
  52. data/test/lib/vedeu/api/external_test.rb +62 -0
  53. data/test/lib/vedeu/{internal_api_test.rb → api/internal_test.rb} +6 -2
  54. data/test/lib/vedeu/application/controller_test.rb +3 -3
  55. data/test/lib/vedeu/bindings/application_test.rb +2 -2
  56. data/test/lib/vedeu/models/cell_test.rb +48 -17
  57. data/test/lib/vedeu/models/escape_test.rb +29 -7
  58. data/test/lib/vedeu/models/page_test.rb +70 -50
  59. data/test/lib/vedeu/models/row_test.rb +40 -20
  60. data/test/lib/vedeu/output/compressor_test.rb +12 -12
  61. data/test/lib/vedeu/output/output_test.rb +17 -23
  62. data/test/lib/vedeu/output/renderers/escape_sequence_test.rb +15 -11
  63. data/test/lib/vedeu/output/renderers/html_test.rb +66 -68
  64. data/test/lib/vedeu/output/renderers/json_test.rb +36 -83
  65. data/test/lib/vedeu/output/renderers/terminal_test.rb +22 -2
  66. data/test/lib/vedeu/output/viewport_test.rb +201 -197
  67. data/test/lib/vedeu/runtime/router_test.rb +144 -140
  68. data/test/lib/vedeu/terminal/buffer_test.rb +307 -0
  69. data/test/support/examples/material_colours_app.rb +2 -2
  70. data/test/support/templates/html_renderer.vedeu +24 -0
  71. metadata +14 -17
  72. data/lib/vedeu/api.rb +0 -190
  73. data/lib/vedeu/buffers/virtual_buffer.rb +0 -136
  74. data/lib/vedeu/buffers/virtual_buffers.rb +0 -77
  75. data/lib/vedeu/internal_api.rb +0 -173
  76. data/lib/vedeu/terminal/content.rb +0 -88
  77. data/test/lib/vedeu/api_test.rb +0 -58
  78. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +0 -148
  79. data/test/lib/vedeu/buffers/virtual_buffers_test.rb +0 -73
  80. data/test/lib/vedeu/terminal/content_test.rb +0 -108
@@ -1,88 +0,0 @@
1
- module Vedeu
2
-
3
- module Terminal
4
-
5
- # A permanent copy of the terminal output.
6
- #
7
- module Content
8
-
9
- include Vedeu::Common
10
- extend self
11
-
12
- # @param char [Vedeu::Views::Char]
13
- # @return [Boolean]
14
- def valid?(char)
15
- char.respond_to?(:position) &&
16
- present?(char.position.y) &&
17
- present?(char.position.x)
18
- end
19
-
20
- # @param char [Vedeu::Views::Char]
21
- # @return [Vedeu::Views::Char]
22
- def store(char)
23
- # value = {}
24
- # value[:background] = char.background.to_s if char.background
25
- # value[:foreground] = char.foreground.to_s if char.foreground
26
- # value[:style] = char.style.to_s if char.style
27
- # value[:value] = char.value if char.value
28
- # value[:x] = char.position.x if char.position.x
29
- # value[:y] = char.position.y if char.position.y
30
-
31
- storage[char.position.y][char.position.x] = char.value if valid?(char)
32
-
33
- char
34
- end
35
-
36
- # @param chars [Array<Vedeu::Views::Char>]
37
- # @return [Array<Vedeu::Views::Char>]
38
- def stores(chars)
39
- Array(chars).flatten.map { |char| store(char) }
40
- end
41
-
42
- # @return [Hash<String => String>|NilClass]
43
- def write
44
- filename = "/tmp/vedeu/content_#{Time.now.to_f}"
45
-
46
- File.write(filename, storage.inspect) if Vedeu::Configuration.log?
47
- end
48
-
49
- # @return [Array<String>]
50
- def reprocess
51
- out = []
52
- storage.each do |y, line|
53
- line.each do |x, value|
54
- out << Vedeu::Views::Char.new(position: [y, x], value: value).to_s
55
- end
56
- end
57
-
58
- Vedeu::Terminal.clear
59
-
60
- Vedeu::Terminal.output(out.join)
61
- end
62
-
63
- # @return [Hash]
64
- def reset
65
- @storage = in_memory
66
- end
67
-
68
- private
69
-
70
- # Returns an empty collection ready for the storing terminal content.
71
- #
72
- # @return [Hash]
73
- def in_memory
74
- Hash.new { |h, k| h[k] = {} }
75
- end
76
-
77
- # Access to the storage for this repository.
78
- #
79
- # @return [Array]
80
- def storage
81
- @storage ||= in_memory
82
- end
83
-
84
- end # Content
85
-
86
- end # Terminal
87
-
88
- end # Vedeu
@@ -1,58 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- describe API do
6
-
7
- it { Vedeu.must_respond_to(:bind) }
8
- it { Vedeu.must_respond_to(:bind_alias) }
9
- it { Vedeu.must_respond_to(:border) }
10
- it { Vedeu.must_respond_to(:bound?) }
11
- it { Vedeu.must_respond_to(:clear) }
12
- it { Vedeu.must_respond_to(:clear_by_group) }
13
- it { Vedeu.must_respond_to(:clear_by_name) }
14
- it { Vedeu.must_respond_to(:configuration) }
15
- it { Vedeu.must_respond_to(:configure) }
16
- it { Vedeu.must_respond_to(:cursor) }
17
- it { Vedeu.must_respond_to(:drb_restart) }
18
- it { Vedeu.must_respond_to(:drb_start) }
19
- it { Vedeu.must_respond_to(:drb_status) }
20
- it { Vedeu.must_respond_to(:drb_stop) }
21
- it { Vedeu.must_respond_to(:events) }
22
- it { Vedeu.must_respond_to(:exit) }
23
- it { Vedeu.must_respond_to(:focus) }
24
- it { Vedeu.must_respond_to(:focus_by_name) }
25
- it { Vedeu.must_respond_to(:focus_next) }
26
- it { Vedeu.must_respond_to(:focus_previous) }
27
- it { Vedeu.must_respond_to(:focussed?) }
28
- it { Vedeu.must_respond_to(:geometry) }
29
- it { Vedeu.must_respond_to(:goto) }
30
- it { Vedeu.must_respond_to(:group) }
31
- it { Vedeu.must_respond_to(:height) }
32
- it { Vedeu.must_respond_to(:hide_cursor) }
33
- it { Vedeu.must_respond_to(:hide_group) }
34
- it { Vedeu.must_respond_to(:hide_interface) }
35
- it { Vedeu.must_respond_to(:interface) }
36
- it { Vedeu.must_respond_to(:keymap) }
37
- it { Vedeu.must_respond_to(:keypress) }
38
- it { Vedeu.must_respond_to(:log) }
39
- it { Vedeu.must_respond_to(:log_stderr) }
40
- it { Vedeu.must_respond_to(:log_stdout) }
41
- it { Vedeu.must_respond_to(:menu) }
42
- it { Vedeu.must_respond_to(:render) }
43
- it { Vedeu.must_respond_to(:renders) }
44
- it { Vedeu.must_respond_to(:show_cursor) }
45
- it { Vedeu.must_respond_to(:show_group) }
46
- it { Vedeu.must_respond_to(:show_interface) }
47
- it { Vedeu.must_respond_to(:toggle_cursor) }
48
- it { Vedeu.must_respond_to(:toggle_group) }
49
- it { Vedeu.must_respond_to(:toggle_interface) }
50
- it { Vedeu.must_respond_to(:trigger) }
51
- it { Vedeu.must_respond_to(:unbind) }
52
- it { Vedeu.must_respond_to(:unbind_alias) }
53
- it { Vedeu.must_respond_to(:views) }
54
- it { Vedeu.must_respond_to(:width) }
55
-
56
- end # API
57
-
58
- end # Vedeu
@@ -1,148 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- module Buffers
6
-
7
- describe VirtualBuffer do
8
-
9
- let(:described) { Vedeu::Buffers::VirtualBuffer }
10
- let(:instance) { described.new(height, width, renderer) }
11
- let(:height) { 3 }
12
- let(:width) { 3 }
13
- let(:renderer) { Vedeu::Renderers::HTML.new }
14
-
15
- describe '#initialize' do
16
- it { instance.must_be_instance_of(described) }
17
- it { instance.instance_variable_get('@height').must_equal(3) }
18
- it { instance.instance_variable_get('@width').must_equal(3) }
19
- it { instance.instance_variable_get('@renderer').must_equal(renderer) }
20
- end
21
-
22
- describe 'accessors' do
23
- it { instance.must_respond_to(:renderer) }
24
- it { instance.must_respond_to(:renderer=) }
25
- it { instance.must_respond_to(:height) }
26
- it { instance.must_respond_to(:width) }
27
- end
28
-
29
- describe '.output' do
30
- let(:data) {}
31
-
32
- before do
33
- Vedeu.stubs(:width).returns(3)
34
- Vedeu.stubs(:height).returns(3)
35
- end
36
-
37
- subject { described.output(data) }
38
-
39
- it { subject.must_be_instance_of(Array) }
40
- end
41
-
42
- describe '#cells' do
43
- before do
44
- Vedeu.stubs(:width).returns(3)
45
- Vedeu.stubs(:height).returns(3)
46
- end
47
-
48
- subject { instance.cells }
49
-
50
- it { subject.must_be_instance_of(Array) }
51
- it { subject.size.must_equal(3) }
52
- it { subject.flatten.size.must_equal(9) }
53
- end
54
-
55
- describe '#read' do
56
- subject { instance.read(y, x) }
57
-
58
- context 'when x is out of bounds' do
59
- let(:y) { 1 }
60
- let(:x) { 5 }
61
-
62
- it { subject.must_equal([]) }
63
- end
64
-
65
- context 'when y is out of bounds' do
66
- let(:y) { 5 }
67
- let(:x) { 1 }
68
-
69
- it { subject.must_equal([]) }
70
- end
71
-
72
- context 'when both x and y are out of bounds' do
73
- let(:y) { 5 }
74
- let(:x) { 5 }
75
-
76
- it { subject.must_equal([]) }
77
- end
78
-
79
- context 'when x and y are in bounds' do
80
- let(:y) { 0 }
81
- let(:x) { 2 }
82
-
83
- it { subject.must_be_instance_of(Vedeu::Models::Cell) }
84
- end
85
- end
86
-
87
- describe '#output' do
88
- it { instance.must_respond_to(:output) }
89
- end
90
-
91
- describe '#render' do
92
- before do
93
- Vedeu.stubs(:width).returns(3)
94
- Vedeu.stubs(:height).returns(3)
95
- end
96
-
97
- subject { instance.render }
98
-
99
- it { subject.must_be_instance_of(String) }
100
- end
101
-
102
- describe '#reset' do
103
- subject { instance.reset }
104
-
105
- it { subject.must_be_instance_of(Array) }
106
-
107
- it { instance.must_respond_to(:clear) }
108
- end
109
-
110
- describe '#write' do
111
- let(:data) { Vedeu::Views::Char.new(value: 'a') }
112
-
113
- subject { instance.write(y, x, data) }
114
-
115
- context 'when x is out of bounds' do
116
- let(:y) { 1 }
117
- let(:x) { 5 }
118
-
119
- it { subject.must_equal(false) }
120
- end
121
-
122
- context 'when y is out of bounds' do
123
- let(:y) { 5 }
124
- let(:x) { 1 }
125
-
126
- it { subject.must_equal(false) }
127
- end
128
-
129
- context 'when both x and y are out of bounds' do
130
- let(:y) { 5 }
131
- let(:x) { 5 }
132
-
133
- it { subject.must_equal(false) }
134
- end
135
-
136
- context 'when x and y are in bounds' do
137
- let(:y) { 0 }
138
- let(:x) { 2 }
139
-
140
- it { subject.must_equal(true) }
141
- end
142
- end
143
-
144
- end # VirtualBuffer
145
-
146
- end # Buffers
147
-
148
- end # Vedeu
@@ -1,73 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- module Buffers
6
-
7
- describe VirtualBuffers do
8
-
9
- let(:described) { Vedeu::Buffers::VirtualBuffers }
10
-
11
- before { described.clear }
12
-
13
- describe '#retrieve' do
14
- subject { described.retrieve }
15
-
16
- context 'when no buffers are stored' do
17
- it { subject.must_be_instance_of(NilClass) }
18
- end
19
-
20
- context 'when buffers are stored' do
21
- let(:buffer) { [[Vedeu::Views::Char.new]] }
22
-
23
- before { described.store(buffer) }
24
-
25
- it { subject.must_be_instance_of(Array) }
26
-
27
- it { subject.must_equal(buffer) }
28
-
29
- it 'removes the stored buffer from the storage' do
30
- described.size.must_equal(1)
31
- subject
32
- described.size.must_equal(0)
33
- end
34
- end
35
- end
36
-
37
- describe '#store' do
38
- let(:data) { :data }
39
-
40
- subject { described.store(data) }
41
-
42
- it { subject.must_be_instance_of(Array) }
43
-
44
- it { subject.must_equal([:data]) }
45
-
46
- it 'adds the buffer (data) to the storage' do
47
- described.size.must_equal(0)
48
- subject
49
- described.size.must_equal(1)
50
- end
51
- end
52
-
53
- describe '#size' do
54
- subject { described.size }
55
-
56
- it { subject.must_be_instance_of(Fixnum) }
57
- end
58
-
59
- describe '#clear' do
60
- subject { described.clear }
61
-
62
- it { subject.must_be_instance_of(Array) }
63
-
64
- it { subject.must_be_empty }
65
-
66
- it { described.must_respond_to(:reset) }
67
- end
68
-
69
- end # VirtualBuffers
70
-
71
- end # Buffers
72
-
73
- end # Vedeu
@@ -1,108 +0,0 @@
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
-
57
- it { subject.must_equal(char) }
58
- end
59
-
60
- describe '#stores' do
61
- let(:chars) {}
62
-
63
- subject { described.stores(chars) }
64
-
65
- it { subject.must_equal([]) }
66
- end
67
-
68
- describe '#write' do
69
- subject { described.write }
70
-
71
- context 'when logging is enabled' do
72
- # before { Vedeu::Configuration.stubs(:log?).returns(true) }
73
- # before { File.stubs(:write) }
74
-
75
- # it {
76
- # File.expects(:write)
77
- # subject
78
- # }
79
- end
80
-
81
- context 'when logging is not enabled' do
82
- before { Vedeu::Configuration.stubs(:log?).returns(false) }
83
-
84
- it { subject.must_equal(nil) }
85
- end
86
- end
87
-
88
- describe '#reprocess' do
89
- before { Vedeu::Terminal.stubs(:clear) }
90
-
91
- subject { described.reprocess }
92
-
93
- it { subject.must_equal(['']) }
94
- end
95
-
96
- describe '#reset' do
97
- subject { described.reset }
98
-
99
- it { subject.must_be_instance_of(Hash) }
100
-
101
- it { subject.must_be_empty }
102
- end
103
-
104
- end # Content
105
-
106
- end # Terminal
107
-
108
- end # Vedeu