vedeu 0.6.9 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/lib/vedeu/all.rb +3 -3
- data/lib/vedeu/api/external.rb +194 -0
- data/lib/vedeu/api/internal.rb +173 -0
- data/lib/vedeu/application/controller.rb +3 -2
- data/lib/vedeu/bindings/application.rb +1 -1
- data/lib/vedeu/bindings/drb.rb +2 -3
- data/lib/vedeu/bindings/movement.rb +1 -1
- data/lib/vedeu/buffers/all.rb +0 -2
- data/lib/vedeu/colours/translator.rb +2 -1
- data/lib/vedeu/common.rb +4 -2
- data/lib/vedeu/configuration/api.rb +1 -1
- data/lib/vedeu/configuration/cli.rb +1 -1
- data/lib/vedeu/cursors/repository.rb +1 -1
- data/lib/vedeu/editor/insert.rb +12 -13
- data/lib/vedeu/geometry/position.rb +1 -1
- data/lib/vedeu/models/cell.rb +35 -21
- data/lib/vedeu/models/escape.rb +18 -1
- data/lib/vedeu/models/page.rb +20 -10
- data/lib/vedeu/models/row.rb +18 -8
- data/lib/vedeu/models/views/char.rb +9 -7
- data/lib/vedeu/models/views/view.rb +1 -1
- data/lib/vedeu/output/compressor.rb +22 -14
- data/lib/vedeu/output/output.rb +1 -10
- data/lib/vedeu/output/renderers/escape_sequence.rb +8 -4
- data/lib/vedeu/output/renderers/file.rb +7 -23
- data/lib/vedeu/output/renderers/html.rb +47 -26
- data/lib/vedeu/output/renderers/json.rb +11 -16
- data/lib/vedeu/output/renderers/null.rb +1 -1
- data/lib/vedeu/output/renderers/renderer_options.rb +2 -1
- data/lib/vedeu/output/renderers/terminal.rb +7 -15
- data/lib/vedeu/output/renderers/text.rb +1 -1
- data/lib/vedeu/output/viewport.rb +154 -143
- data/lib/vedeu/repositories/collection.rb +2 -2
- data/lib/vedeu/repositories/model.rb +25 -26
- data/lib/vedeu/repositories/registerable.rb +9 -8
- data/lib/vedeu/repositories/repository.rb +21 -16
- data/lib/vedeu/repositories/store.rb +6 -4
- data/lib/vedeu/runtime/bootstrap.rb +7 -5
- data/lib/vedeu/runtime/main_loop.rb +2 -0
- data/lib/vedeu/runtime/router.rb +155 -149
- data/lib/vedeu/templating/decoder.rb +8 -5
- data/lib/vedeu/templating/encoder.rb +6 -4
- data/lib/vedeu/templating/template.rb +2 -2
- data/lib/vedeu/templating/view_template.rb +8 -7
- data/lib/vedeu/terminal/buffer.rb +132 -0
- data/lib/vedeu/terminal/terminal.rb +0 -5
- data/lib/vedeu/version.rb +1 -1
- data/lib/vedeu.rb +2 -2
- data/out_ +50 -0
- data/test/lib/vedeu/api/external_test.rb +62 -0
- data/test/lib/vedeu/{internal_api_test.rb → api/internal_test.rb} +6 -2
- data/test/lib/vedeu/application/controller_test.rb +3 -3
- data/test/lib/vedeu/bindings/application_test.rb +2 -2
- data/test/lib/vedeu/models/cell_test.rb +48 -17
- data/test/lib/vedeu/models/escape_test.rb +29 -7
- data/test/lib/vedeu/models/page_test.rb +70 -50
- data/test/lib/vedeu/models/row_test.rb +40 -20
- data/test/lib/vedeu/output/compressor_test.rb +12 -12
- data/test/lib/vedeu/output/output_test.rb +17 -23
- data/test/lib/vedeu/output/renderers/escape_sequence_test.rb +15 -11
- data/test/lib/vedeu/output/renderers/html_test.rb +66 -68
- data/test/lib/vedeu/output/renderers/json_test.rb +36 -83
- data/test/lib/vedeu/output/renderers/terminal_test.rb +22 -2
- data/test/lib/vedeu/output/viewport_test.rb +201 -197
- data/test/lib/vedeu/runtime/router_test.rb +144 -140
- data/test/lib/vedeu/terminal/buffer_test.rb +307 -0
- data/test/support/examples/material_colours_app.rb +2 -2
- data/test/support/templates/html_renderer.vedeu +24 -0
- metadata +14 -17
- data/lib/vedeu/api.rb +0 -190
- data/lib/vedeu/buffers/virtual_buffer.rb +0 -136
- data/lib/vedeu/buffers/virtual_buffers.rb +0 -77
- data/lib/vedeu/internal_api.rb +0 -173
- data/lib/vedeu/terminal/content.rb +0 -88
- data/test/lib/vedeu/api_test.rb +0 -58
- data/test/lib/vedeu/buffers/virtual_buffer_test.rb +0 -148
- data/test/lib/vedeu/buffers/virtual_buffers_test.rb +0 -73
- data/test/lib/vedeu/terminal/content_test.rb +0 -108
data/lib/vedeu/runtime/router.rb
CHANGED
|
@@ -1,184 +1,190 @@
|
|
|
1
1
|
module Vedeu
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
module Router
|
|
3
|
+
module Runtime
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
extend self
|
|
10
|
-
|
|
11
|
-
# Registers a controller with the given controller name for the client
|
|
12
|
-
# application.
|
|
5
|
+
# Stores all client application controllers with their respective
|
|
6
|
+
# actions.
|
|
13
7
|
#
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
module Router
|
|
9
|
+
|
|
10
|
+
include Vedeu::Common
|
|
11
|
+
|
|
12
|
+
extend self
|
|
13
|
+
|
|
14
|
+
# Registers a controller with the given controller name for the
|
|
15
|
+
# client application.
|
|
16
|
+
#
|
|
17
|
+
# @param controller [Symbol]
|
|
18
|
+
# @param klass [String]
|
|
19
|
+
# @raise [Vedeu::Error::MissingRequired] When the controller
|
|
20
|
+
# name is not given.
|
|
21
|
+
# @return [void]
|
|
22
|
+
def add_controller(controller, klass)
|
|
23
|
+
unless present?(controller)
|
|
24
|
+
fail Vedeu::Error::MissingRequired,
|
|
25
|
+
'Cannot store controller without a name attribute.'
|
|
26
|
+
end
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
Vedeu.log(type: :create,
|
|
29
|
+
message: "Controller: ':#{controller}'")
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
if registered?(controller)
|
|
32
|
+
storage[controller].merge!(klass: klass)
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
else
|
|
35
|
+
storage.store(controller, klass: klass, actions: [])
|
|
36
|
+
|
|
37
|
+
end
|
|
33
38
|
|
|
39
|
+
storage
|
|
34
40
|
end
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
# Registers an action to the given controller name for the
|
|
43
|
+
# client application.
|
|
44
|
+
#
|
|
45
|
+
# @param controller [Symbol]
|
|
46
|
+
# @param action [Symbol]
|
|
47
|
+
# @raise [Vedeu::Error::MissingRequired] When the controller
|
|
48
|
+
# name or action name is not given.
|
|
49
|
+
# @return [void]
|
|
50
|
+
def add_action(controller, action)
|
|
51
|
+
if present?(controller) && present?(action)
|
|
52
|
+
Vedeu.log(type: :create,
|
|
53
|
+
message: "Action: ':#{action}' (for ':#{controller}')")
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
#
|
|
42
|
-
# @param controller [Symbol]
|
|
43
|
-
# @param action [Symbol]
|
|
44
|
-
# @raise [Vedeu::Error::MissingRequired] When the controller name or action
|
|
45
|
-
# name is not given.
|
|
46
|
-
# @return [void]
|
|
47
|
-
def add_action(controller, action)
|
|
48
|
-
if present?(controller) && present?(action)
|
|
49
|
-
Vedeu.log(type: :create,
|
|
50
|
-
message: "Action: ':#{action}' (for ':#{controller}')")
|
|
55
|
+
if registered?(controller)
|
|
56
|
+
storage[controller][:actions] << action
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
else
|
|
59
|
+
add_controller(controller, '')
|
|
60
|
+
add_action(controller, action)
|
|
54
61
|
|
|
55
|
-
|
|
56
|
-
add_controller(controller, '')
|
|
57
|
-
add_action(controller, action)
|
|
62
|
+
end
|
|
58
63
|
|
|
59
|
-
|
|
64
|
+
storage
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
else
|
|
67
|
+
fail Vedeu::Error::MissingRequired,
|
|
68
|
+
'Cannot store action without a controller or name attribute.'
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
'Cannot store action without a controller or name attribute.'
|
|
70
|
+
end
|
|
71
|
+
end
|
|
66
72
|
|
|
73
|
+
# Instruct Vedeu to load the client application controller
|
|
74
|
+
# action with parameters.
|
|
75
|
+
#
|
|
76
|
+
# @example
|
|
77
|
+
# Vedeu.goto(controller, action, args)
|
|
78
|
+
#
|
|
79
|
+
# @param controller [Symbol]
|
|
80
|
+
# @param action [Symbol]
|
|
81
|
+
# @param args [void]
|
|
82
|
+
# @raise [Vedeu::Error::ModelNotFound] When the controller is
|
|
83
|
+
# not registered.
|
|
84
|
+
# @return [void]
|
|
85
|
+
def goto(controller, action, **args)
|
|
86
|
+
Vedeu.log(type: :debug,
|
|
87
|
+
message: "Routing: #{controller} #{action}")
|
|
88
|
+
|
|
89
|
+
route(controller, action, args) if action_defined?(action, controller)
|
|
90
|
+
end
|
|
91
|
+
alias_method :action, :goto
|
|
92
|
+
|
|
93
|
+
# Returns a boolean indicating whether the given controller name
|
|
94
|
+
# is already registered.
|
|
95
|
+
#
|
|
96
|
+
# @param controller [Symbol]
|
|
97
|
+
# @return [Boolean]
|
|
98
|
+
def registered?(controller)
|
|
99
|
+
storage.key?(controller)
|
|
67
100
|
end
|
|
68
|
-
end
|
|
69
101
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
# @param action [Symbol]
|
|
78
|
-
# @param args [void]
|
|
79
|
-
# @raise [Vedeu::Error::ModelNotFound] When the controller is not
|
|
80
|
-
# registered.
|
|
81
|
-
# @return [void]
|
|
82
|
-
def goto(controller, action, **args)
|
|
83
|
-
Vedeu.log(type: :debug,
|
|
84
|
-
message: "Routing: #{controller} #{action}")
|
|
85
|
-
|
|
86
|
-
route(controller, action, args) if action_defined?(action, controller)
|
|
87
|
-
end
|
|
88
|
-
alias_method :action, :goto
|
|
89
|
-
|
|
90
|
-
# Returns a boolean indicating whether the given controller name is already
|
|
91
|
-
# registered.
|
|
92
|
-
#
|
|
93
|
-
# @param controller [Symbol]
|
|
94
|
-
# @return [Boolean]
|
|
95
|
-
def registered?(controller)
|
|
96
|
-
storage.key?(controller)
|
|
97
|
-
end
|
|
102
|
+
# Removes all stored controllers with their respective actions.
|
|
103
|
+
#
|
|
104
|
+
# @return [Hash<void>]
|
|
105
|
+
def reset!
|
|
106
|
+
@storage = in_memory
|
|
107
|
+
end
|
|
108
|
+
alias_method :reset, :reset!
|
|
98
109
|
|
|
99
|
-
|
|
100
|
-
#
|
|
101
|
-
# @return [Hash<void>]
|
|
102
|
-
def reset!
|
|
103
|
-
@storage = in_memory
|
|
104
|
-
end
|
|
105
|
-
alias_method :reset, :reset!
|
|
110
|
+
private
|
|
106
111
|
|
|
107
|
-
|
|
112
|
+
# Returns a boolean indicating whether the given action name is
|
|
113
|
+
# defined for the given controller.
|
|
114
|
+
#
|
|
115
|
+
# @param action [Symbol]
|
|
116
|
+
# @param controller [Symbol]
|
|
117
|
+
# @return [Boolean]
|
|
118
|
+
def action_defined?(action, controller)
|
|
119
|
+
if registered?(controller)
|
|
120
|
+
return true if storage[controller][:actions].include?(action)
|
|
108
121
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
#
|
|
112
|
-
# @param action [Symbol]
|
|
113
|
-
# @param controller [Symbol]
|
|
114
|
-
# @return [Boolean]
|
|
115
|
-
def action_defined?(action, controller)
|
|
116
|
-
if registered?(controller)
|
|
117
|
-
return true if storage[controller][:actions].include?(action)
|
|
122
|
+
fail Vedeu::Error::ActionNotFound,
|
|
123
|
+
"#{action} is not registered for #{controller}."
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
else
|
|
126
|
+
fail Vedeu::Error::ControllerNotFound,
|
|
127
|
+
"#{controller} is not registered."
|
|
121
128
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
"#{controller} is not registered."
|
|
129
|
+
end
|
|
130
|
+
end
|
|
125
131
|
|
|
132
|
+
# Instantiate the given controller by name, the call the action
|
|
133
|
+
# (method) with any given arguments.
|
|
134
|
+
#
|
|
135
|
+
# @param controller [Symbol]
|
|
136
|
+
# @param action [Symbol]
|
|
137
|
+
# @param args [Symbol]
|
|
138
|
+
# @return [void]
|
|
139
|
+
def route(controller, action, **args)
|
|
140
|
+
klass = Object.const_get(klass_for(controller)).new(**args)
|
|
141
|
+
klass.send(action)
|
|
126
142
|
end
|
|
127
|
-
end
|
|
128
143
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
klass.send(action)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
# Fetch the class for the controller by name.
|
|
142
|
-
#
|
|
143
|
-
# @param controller [Symbol]
|
|
144
|
-
# @raise [Vedeu::Error::MissingRequired] When the given controller name does
|
|
145
|
-
# not have a class defined.
|
|
146
|
-
# @return [String]
|
|
147
|
-
def klass_for(controller)
|
|
148
|
-
if registered?(controller) && klass_defined?(controller)
|
|
149
|
-
storage[controller][:klass]
|
|
150
|
-
|
|
151
|
-
else
|
|
152
|
-
fail Vedeu::Error::MissingRequired,
|
|
153
|
-
"Cannot route to #{controller} as no class defined."
|
|
144
|
+
# Fetch the class for the controller by name.
|
|
145
|
+
#
|
|
146
|
+
# @param controller [Symbol]
|
|
147
|
+
# @raise [Vedeu::Error::MissingRequired] When the given
|
|
148
|
+
# controller name does not have a class defined.
|
|
149
|
+
# @return [String]
|
|
150
|
+
def klass_for(controller)
|
|
151
|
+
if registered?(controller) && klass_defined?(controller)
|
|
152
|
+
storage[controller][:klass]
|
|
154
153
|
|
|
154
|
+
else
|
|
155
|
+
fail Vedeu::Error::MissingRequired,
|
|
156
|
+
"Cannot route to #{controller} as no class defined."
|
|
157
|
+
|
|
158
|
+
end
|
|
155
159
|
end
|
|
156
|
-
end
|
|
157
160
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
# Returns a boolean indicating whether the given controller name
|
|
162
|
+
# has a class defined.
|
|
163
|
+
#
|
|
164
|
+
# @param controller [Symbol]
|
|
165
|
+
# @return [Boolean]
|
|
166
|
+
def klass_defined?(controller)
|
|
167
|
+
present?(storage[controller][:klass])
|
|
168
|
+
end
|
|
166
169
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
170
|
+
# Returns all the stored controllers and their respective
|
|
171
|
+
# actions.
|
|
172
|
+
#
|
|
173
|
+
# @return [Hash<Symbol => Hash<Symbol => String|Array<Symbol>>>]
|
|
174
|
+
def storage
|
|
175
|
+
@storage ||= in_memory
|
|
176
|
+
end
|
|
173
177
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
178
|
+
# Returns an empty collection ready for the storing of client
|
|
179
|
+
# application controllers and actions.
|
|
180
|
+
#
|
|
181
|
+
# @return [Hash<void>]
|
|
182
|
+
def in_memory
|
|
183
|
+
{}
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
end # Router
|
|
181
187
|
|
|
182
|
-
end #
|
|
188
|
+
end # Runtime
|
|
183
189
|
|
|
184
190
|
end # Vedeu
|
|
@@ -2,7 +2,8 @@ module Vedeu
|
|
|
2
2
|
|
|
3
3
|
module Templating
|
|
4
4
|
|
|
5
|
-
# Converts an encoded string back into an object or collection of
|
|
5
|
+
# Converts an encoded string back into an object or collection of
|
|
6
|
+
# objects.
|
|
6
7
|
#
|
|
7
8
|
class Decoder
|
|
8
9
|
|
|
@@ -20,7 +21,8 @@ module Vedeu
|
|
|
20
21
|
@data = data
|
|
21
22
|
end
|
|
22
23
|
|
|
23
|
-
# Converts an encoded string back into an object or collection
|
|
24
|
+
# Converts an encoded string back into an object or collection
|
|
25
|
+
# of objects.
|
|
24
26
|
#
|
|
25
27
|
# @return [Object]
|
|
26
28
|
def process
|
|
@@ -35,7 +37,8 @@ module Vedeu
|
|
|
35
37
|
|
|
36
38
|
private
|
|
37
39
|
|
|
38
|
-
# Convert the marshalled object or objects back into an
|
|
40
|
+
# Convert the marshalled object or objects back into an
|
|
41
|
+
# object(s).
|
|
39
42
|
#
|
|
40
43
|
# @return [Object]
|
|
41
44
|
def demarshal
|
|
@@ -49,8 +52,8 @@ module Vedeu
|
|
|
49
52
|
Zlib::Inflate.inflate(decode64)
|
|
50
53
|
end
|
|
51
54
|
|
|
52
|
-
# Decode the Base64 string into a compressed, marshalled object
|
|
53
|
-
# objects.
|
|
55
|
+
# Decode the Base64 string into a compressed, marshalled object
|
|
56
|
+
# or objects.
|
|
54
57
|
#
|
|
55
58
|
# @return [String]
|
|
56
59
|
def decode64
|
|
@@ -2,7 +2,8 @@ module Vedeu
|
|
|
2
2
|
|
|
3
3
|
module Templating
|
|
4
4
|
|
|
5
|
-
# Converts an object or collection of objects into an encoded
|
|
5
|
+
# Converts an object or collection of objects into an encoded
|
|
6
|
+
# String.
|
|
6
7
|
#
|
|
7
8
|
class Encoder
|
|
8
9
|
|
|
@@ -20,7 +21,8 @@ module Vedeu
|
|
|
20
21
|
@data = data
|
|
21
22
|
end
|
|
22
23
|
|
|
23
|
-
# Converts an object or collection of objects into an encoded
|
|
24
|
+
# Converts an object or collection of objects into an encoded
|
|
25
|
+
# String.
|
|
24
26
|
#
|
|
25
27
|
# @return [String]
|
|
26
28
|
def process
|
|
@@ -42,8 +44,8 @@ module Vedeu
|
|
|
42
44
|
"{{#{encode64}}}"
|
|
43
45
|
end
|
|
44
46
|
|
|
45
|
-
# Encode the compressed, marshalled object or objects into a
|
|
46
|
-
# string.
|
|
47
|
+
# Encode the compressed, marshalled object or objects into a
|
|
48
|
+
# Base64 string.
|
|
47
49
|
#
|
|
48
50
|
# @return [String]
|
|
49
51
|
def encode64
|
|
@@ -47,8 +47,8 @@ module Vedeu
|
|
|
47
47
|
File.read(path)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
# @raise [Vedeu::Error::MissingRequired] When the path is empty
|
|
51
|
-
# not exist.
|
|
50
|
+
# @raise [Vedeu::Error::MissingRequired] When the path is empty
|
|
51
|
+
# or does not exist.
|
|
52
52
|
# @return [String]
|
|
53
53
|
def path
|
|
54
54
|
fail Vedeu::Error::MissingRequired,
|
|
@@ -2,7 +2,8 @@ module Vedeu
|
|
|
2
2
|
|
|
3
3
|
module Templating
|
|
4
4
|
|
|
5
|
-
# Extend Template to provide client application view specific
|
|
5
|
+
# Extend Template to provide client application view specific
|
|
6
|
+
# parsing.
|
|
6
7
|
#
|
|
7
8
|
class ViewTemplate < Template
|
|
8
9
|
|
|
@@ -48,8 +49,8 @@ module Vedeu
|
|
|
48
49
|
|
|
49
50
|
private
|
|
50
51
|
|
|
51
|
-
# Return the interface colours if a name option is set,
|
|
52
|
-
# default colours.
|
|
52
|
+
# Return the interface colours if a name option is set,
|
|
53
|
+
# otherwise use the default colours.
|
|
53
54
|
#
|
|
54
55
|
# @return [Vedeu::Colours::Colour|Hash<Symbol => Symbol>]
|
|
55
56
|
def default_colour
|
|
@@ -65,8 +66,8 @@ module Vedeu
|
|
|
65
66
|
end
|
|
66
67
|
end
|
|
67
68
|
|
|
68
|
-
# Return the interface style(s) if a name option is set,
|
|
69
|
-
# default style.
|
|
69
|
+
# Return the interface style(s) if a name option is set,
|
|
70
|
+
# otherwise use the default style.
|
|
70
71
|
#
|
|
71
72
|
# @return [Symbol]
|
|
72
73
|
def default_style
|
|
@@ -95,8 +96,8 @@ module Vedeu
|
|
|
95
96
|
line.split(/({{\s*[^}]+\s*}})/)
|
|
96
97
|
end
|
|
97
98
|
|
|
98
|
-
# Convert the content into an array of strings without the line
|
|
99
|
-
# character.
|
|
99
|
+
# Convert the content into an array of strings without the line
|
|
100
|
+
# ending character.
|
|
100
101
|
#
|
|
101
102
|
# @return [Array<String>]
|
|
102
103
|
def lines
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
module Vedeu
|
|
2
|
+
|
|
3
|
+
module Terminal
|
|
4
|
+
|
|
5
|
+
# All output will be written to this singleton, and #render will be called
|
|
6
|
+
# at the end of each run of {Vedeu::MainLoop}; effectively rendering this
|
|
7
|
+
# buffer to each registered renderer. This buffer is not cleared after this
|
|
8
|
+
# action though, as subsequent actions will modify the contents. This means
|
|
9
|
+
# that individual parts of Vedeu can write content here at various points
|
|
10
|
+
# and only at the end of each run of {Vedeu::MainLoop} will it be actually
|
|
11
|
+
# output 'somewhere'.
|
|
12
|
+
#
|
|
13
|
+
module Buffer
|
|
14
|
+
|
|
15
|
+
extend self
|
|
16
|
+
|
|
17
|
+
# Return a grid of {Vedeu::Models::Cell} objects defined by the
|
|
18
|
+
# height and width of this virtual terminal.
|
|
19
|
+
#
|
|
20
|
+
# @return [Array<Array<Vedeu::Models::Cell>>]
|
|
21
|
+
def buffer
|
|
22
|
+
@output ||= empty_buffer.dup
|
|
23
|
+
end
|
|
24
|
+
alias_method :cells, :buffer
|
|
25
|
+
|
|
26
|
+
# @return [Array<Array<Vedeu::Models::Cell>>]
|
|
27
|
+
def empty_buffer
|
|
28
|
+
Array.new(Vedeu.height) do |y|
|
|
29
|
+
Array.new(Vedeu.width) do |x|
|
|
30
|
+
Vedeu::Models::Cell.new(position: [y + 1, x + 1])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @return [Vedeu::Models::Page]
|
|
36
|
+
def output
|
|
37
|
+
Vedeu::Models::Page.coerce(buffer)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Read a single cell from the virtual terminal.
|
|
41
|
+
#
|
|
42
|
+
# @note
|
|
43
|
+
# Given two actual coordinates (y, x) e.g. (1, 1)
|
|
44
|
+
# Convert to coordinate indices (cy, cx) e.g. (0, 0)
|
|
45
|
+
# Fetch the row at cy and return the cell from cx
|
|
46
|
+
#
|
|
47
|
+
# @param y [Fixnum] The row/line coordinate.
|
|
48
|
+
# @param x [Fixnum] The column/character coordinate.
|
|
49
|
+
# @return [Vedeu::Views::Char]
|
|
50
|
+
def read(y, x)
|
|
51
|
+
cy, cx = Vedeu::Geometry::Position[y, x].as_indices
|
|
52
|
+
|
|
53
|
+
row = fetch(cells, cy)
|
|
54
|
+
cell = fetch(row, cx)
|
|
55
|
+
|
|
56
|
+
cell
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Send the cells to the renderer and return the rendered result.
|
|
60
|
+
#
|
|
61
|
+
# @return [String|void] Most likely to be a String.
|
|
62
|
+
def render
|
|
63
|
+
Vedeu.renderers.render(output) if Vedeu.ready?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Removes all content from the virtual terminal; effectively
|
|
67
|
+
# clearing it.
|
|
68
|
+
#
|
|
69
|
+
# @return [Array<Array<Vedeu::Models::Cell>>]
|
|
70
|
+
def reset
|
|
71
|
+
@output = empty_buffer
|
|
72
|
+
end
|
|
73
|
+
alias_method :clear, :reset
|
|
74
|
+
|
|
75
|
+
# Write a collection of cells to the virtual terminal.
|
|
76
|
+
#
|
|
77
|
+
# @param value [Array<Array<Vedeu::Views::Char>>]
|
|
78
|
+
# @return [Array<Array<Vedeu::Views::Char>>]
|
|
79
|
+
def write(value)
|
|
80
|
+
values = Array(value).flatten
|
|
81
|
+
|
|
82
|
+
values.each do |v|
|
|
83
|
+
buffer[v.position.y][v.position.x] = v if valid_position?(v)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
self
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
|
|
91
|
+
# @param from [Array] An Array of rows, or an Array of cells.
|
|
92
|
+
# @param which [Fixnum] A Fixnum representing the index; the row
|
|
93
|
+
# number or the cell number for a row.
|
|
94
|
+
# @return [Array<Vedeu::Views::Char>|Array]
|
|
95
|
+
def fetch(from, which)
|
|
96
|
+
from[which] || []
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Returns a boolean indicating the value has a position
|
|
100
|
+
# attribute.
|
|
101
|
+
#
|
|
102
|
+
# @param value [void]
|
|
103
|
+
# @return [Boolean]
|
|
104
|
+
def position?(value)
|
|
105
|
+
value.respond_to?(:position) &&
|
|
106
|
+
value.position.is_a?(Vedeu::Geometry::Position)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Returns a boolean indicating the value has a position
|
|
110
|
+
# attribute and is within the terminal boundary.
|
|
111
|
+
#
|
|
112
|
+
# @param value [void]
|
|
113
|
+
# @return [Boolean]
|
|
114
|
+
def valid_position?(value)
|
|
115
|
+
position?(value) && within_terminal_boundary?(value)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Returns a boolean indicating the position of the value object
|
|
119
|
+
# is valid for this terminal.
|
|
120
|
+
#
|
|
121
|
+
# @param value [void]
|
|
122
|
+
# @return [Boolean]
|
|
123
|
+
def within_terminal_boundary?(value)
|
|
124
|
+
value.position.y > 0 && value.position.y <= Vedeu.height &&
|
|
125
|
+
value.position.x > 0 && value.position.x <= Vedeu.width
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
end # Buffer
|
|
129
|
+
|
|
130
|
+
end # Terminal
|
|
131
|
+
|
|
132
|
+
end # Vedeu
|
data/lib/vedeu/version.rb
CHANGED
data/lib/vedeu.rb
CHANGED
data/out_
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<head>
|
|
3
|
+
<style type='text/css'>
|
|
4
|
+
body {
|
|
5
|
+
background:#000;
|
|
6
|
+
}
|
|
7
|
+
td {
|
|
8
|
+
border:1px #171717 solid;
|
|
9
|
+
font-size:12px;
|
|
10
|
+
font-family:monospace;
|
|
11
|
+
height:18px;
|
|
12
|
+
margin:1px;
|
|
13
|
+
text-align:center;
|
|
14
|
+
vertical-align:center;
|
|
15
|
+
width:18px;
|
|
16
|
+
}
|
|
17
|
+
</style>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<table>
|
|
21
|
+
<tr>
|
|
22
|
+
|
|
23
|
+
</tr>
|
|
24
|
+
<tr>
|
|
25
|
+
|
|
26
|
+
</tr>
|
|
27
|
+
<tr>
|
|
28
|
+
|
|
29
|
+
</tr>
|
|
30
|
+
<tr>
|
|
31
|
+
|
|
32
|
+
</tr>
|
|
33
|
+
<tr>
|
|
34
|
+
|
|
35
|
+
</tr>
|
|
36
|
+
<tr>
|
|
37
|
+
|
|
38
|
+
</tr>
|
|
39
|
+
<tr>
|
|
40
|
+
|
|
41
|
+
</tr>
|
|
42
|
+
<tr>
|
|
43
|
+
|
|
44
|
+
</tr>
|
|
45
|
+
<tr>
|
|
46
|
+
|
|
47
|
+
</tr>
|
|
48
|
+
</table>
|
|
49
|
+
</body>
|
|
50
|
+
</html>
|