vedeu 0.4.14 → 0.4.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/README.md +47 -35
- data/docs/views.md +1 -1
- data/examples/material_colours_app.rb +0 -5
- data/lib/vedeu/cursor/cursor.rb +4 -5
- data/lib/vedeu/cursor/move.rb +52 -84
- data/lib/vedeu/cursor/refresh_cursor.rb +12 -18
- data/lib/vedeu/debug.rb +3 -1
- data/lib/vedeu/geometry/area.rb +0 -2
- data/lib/vedeu/geometry/coordinate.rb +10 -0
- data/lib/vedeu/geometry/dimension.rb +34 -18
- data/lib/vedeu/geometry/null_geometry.rb +10 -1
- data/lib/vedeu/geometry/position.rb +1 -1
- data/lib/vedeu/geometry/position_validator.rb +2 -2
- data/lib/vedeu/input/mapper.rb +4 -18
- data/lib/vedeu/main_loop.rb +1 -3
- data/lib/vedeu/models/cell.rb +11 -17
- data/lib/vedeu/models/interface.rb +0 -7
- data/lib/vedeu/output/border.rb +34 -61
- data/lib/vedeu/output/clear.rb +39 -14
- data/lib/vedeu/output/colour.rb +15 -15
- data/lib/vedeu/output/esc.rb +1 -1
- data/lib/vedeu/output/html_char.rb +18 -24
- data/lib/vedeu/output/null_border.rb +14 -10
- data/lib/vedeu/output/presentation.rb +32 -8
- data/lib/vedeu/output/renderers/all.rb +1 -0
- data/lib/vedeu/output/renderers/text_renderer.rb +40 -0
- data/lib/vedeu/output/translator.rb +2 -4
- data/lib/vedeu/output/viewport.rb +22 -13
- data/lib/vedeu/output/virtual_terminal.rb +0 -1
- data/lib/vedeu/repositories/repositories/borders.rb +3 -4
- data/lib/vedeu/repositories/repositories/cursors.rb +13 -1
- data/lib/vedeu/repositories/repositories/geometries.rb +1 -1
- data/lib/vedeu/support/all.rb +1 -0
- data/lib/vedeu/support/options.rb +65 -0
- data/lib/vedeu/support/terminal.rb +3 -5
- data/test/lib/vedeu/cursor/cursor_test.rb +0 -5
- data/test/lib/vedeu/cursor/move_test.rb +87 -92
- data/test/lib/vedeu/geometry/null_geometry_test.rb +3 -1
- data/test/lib/vedeu/models/cell_test.rb +13 -16
- data/test/lib/vedeu/models/interface_test.rb +0 -17
- data/test/lib/vedeu/output/border_test.rb +0 -22
- data/test/lib/vedeu/output/clear_test.rb +4 -2
- data/test/lib/vedeu/output/null_border_test.rb +8 -4
- data/test/lib/vedeu/output/renderers/text_renderer_test.rb +24 -0
- data/test/lib/vedeu/repositories/repositories/borders_test.rb +1 -13
- data/test/lib/vedeu/support/options_test.rb +70 -0
- data/vedeu.gemspec +1 -1
- metadata +8 -2
@@ -5,6 +5,12 @@ module Vedeu
|
|
5
5
|
#
|
6
6
|
class RefreshCursor
|
7
7
|
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators :border,
|
11
|
+
:height,
|
12
|
+
:width
|
13
|
+
|
8
14
|
# @param (see #initialize)
|
9
15
|
def self.render(name = Vedeu.focus)
|
10
16
|
new(name).render
|
@@ -35,7 +41,7 @@ module Vedeu
|
|
35
41
|
|
36
42
|
# @return [Boolean]
|
37
43
|
def refresh_view?
|
38
|
-
new_cursor.ox >=
|
44
|
+
new_cursor.ox >= width || new_cursor.oy >= height
|
39
45
|
end
|
40
46
|
|
41
47
|
# @return [Vedeu::Cursor]
|
@@ -53,29 +59,17 @@ module Vedeu
|
|
53
59
|
|
54
60
|
# @return [Vedeu::PositionValidator]
|
55
61
|
def validated_position
|
56
|
-
@position ||= Vedeu::PositionValidator.validate(
|
57
|
-
cursor.x,
|
58
|
-
cursor.y)
|
62
|
+
@position ||= Vedeu::PositionValidator.validate(name, cursor.x, cursor.y)
|
59
63
|
end
|
60
64
|
|
61
65
|
# @return [Vedeu::Cursor]
|
62
66
|
def cursor
|
63
|
-
@cursor ||= Vedeu.cursors.
|
64
|
-
end
|
65
|
-
|
66
|
-
# @return [Fixnum]
|
67
|
-
def interface_height
|
68
|
-
interface.border.height
|
69
|
-
end
|
70
|
-
|
71
|
-
# @return [Fixnum]
|
72
|
-
def interface_width
|
73
|
-
interface.border.width
|
67
|
+
@cursor ||= Vedeu.cursors.by_name(name)
|
74
68
|
end
|
75
69
|
|
76
|
-
# @return
|
77
|
-
def
|
78
|
-
@
|
70
|
+
# @return (see Vedeu::Borders#by_name)
|
71
|
+
def border
|
72
|
+
@border ||= Vedeu.borders.by_name(name)
|
79
73
|
end
|
80
74
|
|
81
75
|
end # RefreshCursor
|
data/lib/vedeu/debug.rb
CHANGED
@@ -6,7 +6,9 @@ module Vedeu
|
|
6
6
|
#
|
7
7
|
# @param filename [String]
|
8
8
|
# @param block [Proc]
|
9
|
-
def self.debug(filename = 'profile.html'
|
9
|
+
def self.debug(filename = 'profile.html')
|
10
|
+
return nil unless block_given?
|
11
|
+
|
10
12
|
require 'ruby-prof'
|
11
13
|
|
12
14
|
RubyProf.measure_mode = RubyProf::WALL_TIME
|
data/lib/vedeu/geometry/area.rb
CHANGED
@@ -244,6 +244,16 @@ module Vedeu
|
|
244
244
|
(y...yn).to_a
|
245
245
|
end
|
246
246
|
|
247
|
+
private
|
248
|
+
|
249
|
+
# @!attribute [r] name
|
250
|
+
# @return [String]
|
251
|
+
attr_reader :name
|
252
|
+
|
253
|
+
def border
|
254
|
+
@border ||= Vedeu.borders.by_name(name)
|
255
|
+
end
|
256
|
+
|
247
257
|
end # Coordinate
|
248
258
|
|
249
259
|
end # Vedeu
|
@@ -63,26 +63,10 @@ module Vedeu
|
|
63
63
|
# @return [Array<Fixnum>]
|
64
64
|
def dimension
|
65
65
|
@dimension ||= if centred? && length?
|
66
|
-
[
|
67
|
-
(default / 2) + (length / 2)]
|
68
|
-
|
69
|
-
elsif d && dn
|
70
|
-
[d, dn]
|
71
|
-
|
72
|
-
elsif d && d_dn
|
73
|
-
[d, ((d + d_dn) - 1)]
|
74
|
-
|
75
|
-
elsif d_dn
|
76
|
-
[1, d_dn]
|
77
|
-
|
78
|
-
elsif d
|
79
|
-
[d, default]
|
80
|
-
|
81
|
-
elsif dn
|
82
|
-
[1, dn]
|
66
|
+
[centred_d, centred_dn]
|
83
67
|
|
84
68
|
else
|
85
|
-
[
|
69
|
+
[_d, _dn]
|
86
70
|
|
87
71
|
end
|
88
72
|
end
|
@@ -111,6 +95,38 @@ module Vedeu
|
|
111
95
|
options[:centred]
|
112
96
|
end
|
113
97
|
|
98
|
+
# @return [Fixnum]
|
99
|
+
def centred_d
|
100
|
+
(default / 2) - (length / 2)
|
101
|
+
end
|
102
|
+
|
103
|
+
# @return [Fixnum]
|
104
|
+
def centred_dn
|
105
|
+
(default / 2) + (length / 2)
|
106
|
+
end
|
107
|
+
|
108
|
+
# @return [Fixnum]
|
109
|
+
def _d
|
110
|
+
d || 1
|
111
|
+
end
|
112
|
+
|
113
|
+
# @return [Fixnum]
|
114
|
+
def _dn
|
115
|
+
if dn
|
116
|
+
dn
|
117
|
+
|
118
|
+
elsif d.nil? && d_dn
|
119
|
+
d_dn
|
120
|
+
|
121
|
+
elsif d && d_dn
|
122
|
+
(d + d_dn) - 1
|
123
|
+
|
124
|
+
else
|
125
|
+
default
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
114
130
|
# @return [Hash<Symbol => Boolean>]
|
115
131
|
def options
|
116
132
|
defaults.merge!(@options)
|
@@ -26,8 +26,17 @@ module Vedeu
|
|
26
26
|
:bottom_left,
|
27
27
|
:bottom_right
|
28
28
|
|
29
|
+
# @!attribute [r] name
|
30
|
+
# @return [String|NilClass]
|
31
|
+
attr_reader :name
|
32
|
+
|
33
|
+
# Returns a new instance of Vedeu::NullGeometry.
|
34
|
+
#
|
35
|
+
# @param name [String|NilClass]
|
29
36
|
# @return [Vedeu::NullGeometry]
|
30
|
-
def initialize
|
37
|
+
def initialize(name = nil)
|
38
|
+
@name = name
|
39
|
+
end
|
31
40
|
|
32
41
|
# @return [FalseClass]
|
33
42
|
def centred
|
@@ -112,12 +112,12 @@ module Vedeu
|
|
112
112
|
self
|
113
113
|
end
|
114
114
|
|
115
|
-
# @return
|
115
|
+
# @return (see Vedeu::Borders#by_name)
|
116
116
|
def border
|
117
117
|
@border ||= Vedeu.borders.by_name(name)
|
118
118
|
end
|
119
119
|
|
120
|
-
# @return
|
120
|
+
# @return (see Vedeu::Geometries#by_name)
|
121
121
|
def geometry
|
122
122
|
@geometry ||= Vedeu.geometries.by_name(name)
|
123
123
|
end
|
data/lib/vedeu/input/mapper.rb
CHANGED
@@ -48,9 +48,9 @@ module Vedeu
|
|
48
48
|
|
49
49
|
return true if key_defined? && keymap.use(key)
|
50
50
|
|
51
|
-
return true if global_key? && keymap(
|
51
|
+
return true if global_key? && keymap('_global_').use(key)
|
52
52
|
|
53
|
-
return true if system_key? && keymap(
|
53
|
+
return true if system_key? && keymap('_system_').use(key)
|
54
54
|
|
55
55
|
false
|
56
56
|
end
|
@@ -79,14 +79,14 @@ module Vedeu
|
|
79
79
|
#
|
80
80
|
# @return [Boolean]
|
81
81
|
def global_key?
|
82
|
-
key_defined?(
|
82
|
+
key_defined?('_global_')
|
83
83
|
end
|
84
84
|
|
85
85
|
# Is the key a system key?
|
86
86
|
#
|
87
87
|
# @return [Boolean]
|
88
88
|
def system_key?
|
89
|
-
key_defined?(
|
89
|
+
key_defined?('_system_')
|
90
90
|
end
|
91
91
|
|
92
92
|
# Is the key defined in the named keymap?
|
@@ -122,20 +122,6 @@ module Vedeu
|
|
122
122
|
end
|
123
123
|
alias_method :interface, :name
|
124
124
|
|
125
|
-
# Return the name of the global keymap.
|
126
|
-
#
|
127
|
-
# @return [String]
|
128
|
-
def global
|
129
|
-
'_global_'
|
130
|
-
end
|
131
|
-
|
132
|
-
# Return the name of the system keymap.
|
133
|
-
#
|
134
|
-
# @return [String]
|
135
|
-
def system
|
136
|
-
'_system_'
|
137
|
-
end
|
138
|
-
|
139
125
|
end # Mapper
|
140
126
|
|
141
127
|
end # Vedeu
|
data/lib/vedeu/main_loop.rb
CHANGED
@@ -17,7 +17,7 @@ module Vedeu
|
|
17
17
|
#
|
18
18
|
# @param block [Proc]
|
19
19
|
# @return [void]
|
20
|
-
def self.start!
|
20
|
+
def self.start!
|
21
21
|
@started = true
|
22
22
|
@loop = true
|
23
23
|
|
@@ -37,8 +37,6 @@ module Vedeu
|
|
37
37
|
@loop = false
|
38
38
|
end
|
39
39
|
|
40
|
-
private
|
41
|
-
|
42
40
|
# Check the application has started and we wish to continue running.
|
43
41
|
#
|
44
42
|
# @raise [VedeuInterrupt] When we wish to terminate the running application.
|
data/lib/vedeu/models/cell.rb
CHANGED
@@ -4,13 +4,9 @@ module Vedeu
|
|
4
4
|
#
|
5
5
|
class Cell
|
6
6
|
|
7
|
-
# @!attribute [r]
|
7
|
+
# @!attribute [r] colour
|
8
8
|
# @return [NilClass|String]
|
9
|
-
attr_reader :
|
10
|
-
|
11
|
-
# @!attribute [r] foreground
|
12
|
-
# @return [NilClass|String]
|
13
|
-
attr_reader :foreground
|
9
|
+
attr_reader :colour
|
14
10
|
|
15
11
|
# @!attribute [r] style
|
16
12
|
# @return [NilClass|Array<Symbol|String>|Symbol|String]
|
@@ -32,28 +28,26 @@ module Vedeu
|
|
32
28
|
#
|
33
29
|
# @param attributes [Hash<Symbol => Array<Symbol|String>,
|
34
30
|
# Fixnum, String, Symbol]
|
35
|
-
# @option attributes
|
36
|
-
# @option attributes foreground [NilClass|String]
|
31
|
+
# @option attributes colour [NilClass|String]
|
37
32
|
# @option attributes style [NilClass|Array<Symbol|String>|Symbol|String]
|
38
33
|
# @option attributes value [NilClass|String]
|
39
34
|
# @option attributes x [NilClass|Fixnum]
|
40
35
|
# @option attributes y [NilClass|Fixnum]
|
41
36
|
# @return [Vedeu::Cell]
|
42
37
|
def initialize(attributes = {})
|
43
|
-
@
|
44
|
-
@
|
45
|
-
@
|
46
|
-
@
|
47
|
-
@
|
48
|
-
@y = attributes[:y]
|
38
|
+
@colour = attributes[:colour]
|
39
|
+
@style = attributes[:style]
|
40
|
+
@value = attributes[:value]
|
41
|
+
@x = attributes[:x]
|
42
|
+
@y = attributes[:y]
|
49
43
|
end
|
50
44
|
|
51
45
|
# @param other [Vedeu::Cell]
|
52
46
|
# @return [Boolean]
|
53
47
|
def eql?(other)
|
54
|
-
self.class == other.class &&
|
55
|
-
|
56
|
-
|
48
|
+
self.class == other.class && colour == other.colour &&
|
49
|
+
style == other.style && value == other.value && x == other.x &&
|
50
|
+
y == other.y
|
57
51
|
end
|
58
52
|
alias_method :==, :eql?
|
59
53
|
|
@@ -114,13 +114,6 @@ module Vedeu
|
|
114
114
|
}
|
115
115
|
end
|
116
116
|
|
117
|
-
# Returns a boolean indicating whether the interface has a border.
|
118
|
-
#
|
119
|
-
# @return [Boolean]
|
120
|
-
def border?
|
121
|
-
Vedeu.borders.registered?(name)
|
122
|
-
end
|
123
|
-
|
124
117
|
# Returns the border object belonging to the interface.
|
125
118
|
#
|
126
119
|
# @return [Vedeu::Border|NilClass]
|
data/lib/vedeu/output/border.rb
CHANGED
@@ -13,8 +13,18 @@ module Vedeu
|
|
13
13
|
#
|
14
14
|
class Border
|
15
15
|
|
16
|
+
extend Forwardable
|
16
17
|
include Vedeu::Common
|
17
18
|
include Vedeu::Model
|
19
|
+
include Vedeu::Presentation
|
20
|
+
|
21
|
+
def_delegators :geometry,
|
22
|
+
:x,
|
23
|
+
:xn,
|
24
|
+
:y,
|
25
|
+
:yn
|
26
|
+
|
27
|
+
def_delegators :interface, :visible?
|
18
28
|
|
19
29
|
# @!attribute [rw] attributes
|
20
30
|
# @return [Hash]
|
@@ -91,7 +101,7 @@ module Vedeu
|
|
91
101
|
# @option attributes bottom_left [String] The bottom left border character.
|
92
102
|
# @option attributes bottom_right [String] The bottom right border
|
93
103
|
# character.
|
94
|
-
# @option attributes colour []
|
104
|
+
# @option attributes colour [Hash]
|
95
105
|
# @option attributes enabled [Boolean] Indicate whether the border is to be
|
96
106
|
# shown for this interface.
|
97
107
|
# @option attributes horizontal [String] The horizontal border character.
|
@@ -127,37 +137,29 @@ module Vedeu
|
|
127
137
|
@horizontal = @attributes[:horizontal]
|
128
138
|
@vertical = @attributes[:vertical]
|
129
139
|
@name = @attributes[:name]
|
130
|
-
@colour = @attributes[:colour]
|
131
140
|
@repository = Vedeu.borders
|
141
|
+
@colour = @attributes[:colour]
|
132
142
|
@style = @attributes[:style]
|
133
143
|
end
|
134
144
|
|
135
145
|
# @return [Fixnum]
|
136
146
|
def bx
|
137
|
-
|
138
|
-
|
139
|
-
geometry.x + bo
|
147
|
+
(enabled? && left?) ? x + 1 : x
|
140
148
|
end
|
141
149
|
|
142
150
|
# @return [Fixnum]
|
143
151
|
def bxn
|
144
|
-
|
145
|
-
|
146
|
-
geometry.xn - bo
|
152
|
+
(enabled? && right?) ? xn - 1 : xn
|
147
153
|
end
|
148
154
|
|
149
155
|
# @return [Fixnum]
|
150
156
|
def by
|
151
|
-
|
152
|
-
|
153
|
-
geometry.y + bo
|
157
|
+
(enabled? && top?) ? y + 1 : y
|
154
158
|
end
|
155
159
|
|
156
160
|
# @return [Fixnum]
|
157
161
|
def byn
|
158
|
-
|
159
|
-
|
160
|
-
geometry.yn - bo
|
162
|
+
(enabled? && bottom?) ? yn - 1 : yn
|
161
163
|
end
|
162
164
|
|
163
165
|
# Returns the width of the interface determined by whether a left, right,
|
@@ -176,21 +178,9 @@ module Vedeu
|
|
176
178
|
(by..byn).size
|
177
179
|
end
|
178
180
|
|
179
|
-
# @return [Vedeu::Colour]
|
180
|
-
def colour
|
181
|
-
Vedeu::Colour.coerce(@colour)
|
182
|
-
end
|
183
|
-
|
184
|
-
# Set the border colour.
|
185
|
-
#
|
186
|
-
# @return [Vedeu::Colour]
|
187
|
-
def colour=(value)
|
188
|
-
@colour = Vedeu::Colour.coerce(value)
|
189
|
-
end
|
190
|
-
|
191
181
|
# @return [Array<Array<Vedeu::Char>>]
|
192
182
|
def render
|
193
|
-
return [] unless
|
183
|
+
return [] unless visible?
|
194
184
|
return [] unless enabled?
|
195
185
|
|
196
186
|
out = [top, bottom]
|
@@ -202,16 +192,9 @@ module Vedeu
|
|
202
192
|
out.flatten
|
203
193
|
end
|
204
194
|
|
205
|
-
# @return [
|
206
|
-
def
|
207
|
-
Vedeu::
|
208
|
-
end
|
209
|
-
|
210
|
-
# Set the border style.
|
211
|
-
#
|
212
|
-
# @return [Vedeu::Style]
|
213
|
-
def style=(value)
|
214
|
-
@style = Vedeu::Style.coerce(value)
|
195
|
+
# @return [String]
|
196
|
+
def to_s
|
197
|
+
Vedeu::TextRenderer.render(render)
|
215
198
|
end
|
216
199
|
|
217
200
|
# Renders the bottom border for the interface.
|
@@ -267,9 +250,7 @@ module Vedeu
|
|
267
250
|
out << titlebar
|
268
251
|
|
269
252
|
else
|
270
|
-
|
271
|
-
out << border(horizontal, prefix_horizontal, nil, ix)
|
272
|
-
end
|
253
|
+
out << horizontal_border(prefix_horizontal)
|
273
254
|
|
274
255
|
end
|
275
256
|
|
@@ -277,10 +258,11 @@ module Vedeu
|
|
277
258
|
out
|
278
259
|
end
|
279
260
|
|
261
|
+
# @param position [Symbol] Either :top_horizontal, or :bottom_horizontal.
|
280
262
|
# @return [Array<Vedeu::Char>]
|
281
|
-
def horizontal_border
|
263
|
+
def horizontal_border(position)
|
282
264
|
width.times.inject([]) do |a, ix|
|
283
|
-
a << border(horizontal,
|
265
|
+
a << border(horizontal, position, nil, ix)
|
284
266
|
a
|
285
267
|
end
|
286
268
|
end
|
@@ -290,7 +272,7 @@ module Vedeu
|
|
290
272
|
#
|
291
273
|
# @return [Array<Vedeu::Char>]
|
292
274
|
def titlebar
|
293
|
-
horizontal_border.each_with_index do |char, index|
|
275
|
+
horizontal_border(:top_horizontal).each_with_index do |char, index|
|
294
276
|
if index >= 1 && index <= title_characters.size
|
295
277
|
char.border = nil
|
296
278
|
char.value = title_characters[(index - 1)]
|
@@ -359,8 +341,7 @@ module Vedeu
|
|
359
341
|
|
360
342
|
# @return [Vedeu::Geometry]
|
361
343
|
def geometry
|
362
|
-
|
363
|
-
interface.geometry
|
344
|
+
@geometry ||= Vedeu.geometries.by_name(name)
|
364
345
|
end
|
365
346
|
|
366
347
|
# @return [Vedeu::Interface]
|
@@ -402,22 +383,14 @@ module Vedeu
|
|
402
383
|
# @return [Vedeu::Position]
|
403
384
|
def position(name, iy = 0, ix = 0)
|
404
385
|
case name
|
405
|
-
when :top_horizontal
|
406
|
-
|
407
|
-
|
408
|
-
when :
|
409
|
-
|
410
|
-
|
411
|
-
when :
|
412
|
-
|
413
|
-
|
414
|
-
when :right_vertical
|
415
|
-
Vedeu::Position[(by + iy), geometry.xn]
|
416
|
-
|
417
|
-
when :bottom_left then geometry.bottom_left
|
418
|
-
when :bottom_right then geometry.bottom_right
|
419
|
-
when :top_left then geometry.top_left
|
420
|
-
when :top_right then geometry.top_right
|
386
|
+
when :top_horizontal then Vedeu::Position[y, (bx + ix)]
|
387
|
+
when :bottom_horizontal then Vedeu::Position[yn, (bx + ix)]
|
388
|
+
when :left_vertical then Vedeu::Position[(by + iy), x]
|
389
|
+
when :right_vertical then Vedeu::Position[(by + iy), xn]
|
390
|
+
when :bottom_left then geometry.bottom_left
|
391
|
+
when :bottom_right then geometry.bottom_right
|
392
|
+
when :top_left then geometry.top_left
|
393
|
+
when :top_right then geometry.top_right
|
421
394
|
end
|
422
395
|
end
|
423
396
|
|