vedeu 0.4.29 → 0.4.30
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +57 -38
- data/README.md +10 -110
- data/docs/getting_started.md +9 -0
- data/lib/vedeu/all.rb +1 -1
- data/lib/vedeu/api.rb +6 -5
- data/lib/vedeu/buffers/display_buffer.rb +1 -1
- data/lib/vedeu/configuration/api.rb +1 -1
- data/lib/vedeu/cursor/move.rb +2 -2
- data/lib/vedeu/debug.rb +3 -1
- data/lib/vedeu/dsl/all.rb +15 -9
- data/lib/vedeu/dsl/{components/border.rb → border.rb} +0 -3
- data/lib/vedeu/dsl/composition.rb +33 -0
- data/lib/vedeu/dsl/{components/geometry.rb → geometry.rb} +18 -0
- data/lib/vedeu/dsl/interface.rb +2 -2
- data/lib/vedeu/dsl/{components/keymap.rb → keymap.rb} +2 -4
- data/lib/vedeu/dsl/{components/menu.rb → menu.rb} +0 -0
- data/lib/vedeu/dsl/{shared/presentation.rb → presentation.rb} +0 -0
- data/lib/vedeu/dsl/{shared/text.rb → text.rb} +0 -0
- data/lib/vedeu/dsl/{shared/use.rb → use.rb} +0 -0
- data/lib/vedeu/events/event.rb +11 -53
- data/lib/vedeu/geometry/area.rb +1 -2
- data/lib/vedeu/geometry/coordinate.rb +1 -1
- data/lib/vedeu/geometry/geometry.rb +0 -12
- data/lib/vedeu/geometry/position_validator.rb +1 -1
- data/lib/vedeu/input/keymap.rb +1 -1
- data/lib/vedeu/models/interface.rb +1 -0
- data/lib/vedeu/models/panel.rb +2 -0
- data/lib/vedeu/null/geometry.rb +3 -2
- data/lib/vedeu/output/border.rb +6 -6
- data/lib/vedeu/output/clear.rb +4 -4
- data/lib/vedeu/output/compressor.rb +10 -4
- data/lib/vedeu/output/html_char.rb +4 -4
- data/lib/vedeu/output/refresh.rb +3 -3
- data/lib/vedeu/output/renderers/file.rb +1 -1
- data/lib/vedeu/output/renderers/terminal.rb +2 -2
- data/lib/vedeu/output/renderers/text.rb +1 -1
- data/lib/vedeu/output/style.rb +1 -1
- data/lib/vedeu/output/translator.rb +0 -8
- data/lib/vedeu/output/viewport.rb +1 -1
- data/lib/vedeu/repositories/all.rb +1 -1
- data/lib/vedeu/repositories/repository.rb +1 -1
- data/lib/vedeu/support/common.rb +1 -1
- data/lib/vedeu/support/template.rb +1 -1
- data/lib/vedeu/support/timer.rb +11 -14
- data/lib/vedeu/templating/all.rb +9 -0
- data/lib/vedeu/templating/helpers.rb +9 -3
- data/lib/vedeu/templating/preprocessor.rb +4 -1
- data/lib/vedeu/version.rb +3 -0
- data/test/lib/vedeu/api_test.rb +38 -297
- data/test/lib/vedeu/buffers/display_buffer_test.rb +1 -0
- data/test/lib/vedeu/dsl/{components/border_test.rb → border_test.rb} +0 -0
- data/test/lib/vedeu/dsl/{components/geometry_test.rb → geometry_test.rb} +0 -0
- data/test/lib/vedeu/dsl/{components/keymap_test.rb → keymap_test.rb} +0 -0
- data/test/lib/vedeu/dsl/{components/menu_test.rb → menu_test.rb} +0 -0
- data/test/lib/vedeu/dsl/{shared/presentation_test.rb → presentation_test.rb} +0 -0
- data/test/lib/vedeu/dsl/{shared/text_test.rb → text_test.rb} +0 -0
- data/test/lib/vedeu/dsl/{shared/use_test.rb → use_test.rb} +0 -0
- data/test/lib/vedeu/dsl/view_test.rb +2 -0
- data/test/lib/vedeu/main_loop_test.rb +0 -3
- data/test/lib/vedeu/output/background_test.rb +18 -22
- data/test/lib/vedeu/output/compressor_test.rb +4 -0
- data/test/lib/vedeu/output/foreground_test.rb +13 -17
- data/test/lib/vedeu/repositories/repositories/borders_test.rb +2 -1
- data/test/lib/vedeu/repositories/repositories/buffers_test.rb +5 -1
- data/test/lib/vedeu/repositories/repositories/geometries_test.rb +2 -0
- data/test/lib/vedeu/support/common_test.rb +2 -2
- data/test/lib/vedeu/support/timer_test.rb +4 -6
- data/test/test_helper.rb +22 -0
- data/vedeu.gemspec +3 -1
- metadata +24 -25
- data/lib/vedeu/dsl/components/all.rb +0 -4
- data/lib/vedeu/dsl/shared/all.rb +0 -3
@@ -9,18 +9,6 @@ module Vedeu
|
|
9
9
|
# Calculates and provides interface geometry determined by both the client's
|
10
10
|
# requirements and the terminal's current viewing area.
|
11
11
|
#
|
12
|
-
# Geometry for Vedeu, as the same for ANSI terminals, has the origin at
|
13
|
-
# top-left, y = 1, x = 1. The 'y' coordinate is deliberately first.
|
14
|
-
#
|
15
|
-
# x north xn # north: y - 1
|
16
|
-
# y +--------------+ # top: y
|
17
|
-
# | top | # west: x - 1
|
18
|
-
# | | # left: x
|
19
|
-
# west | left right | east # right: xn
|
20
|
-
# | | # east: xn + 1
|
21
|
-
# | bottom | # bottom: yn
|
22
|
-
# yn +--------------+ # south: yn + 1
|
23
|
-
# south
|
24
12
|
class Geometry
|
25
13
|
|
26
14
|
extend Forwardable
|
data/lib/vedeu/input/keymap.rb
CHANGED
data/lib/vedeu/models/panel.rb
CHANGED
data/lib/vedeu/null/geometry.rb
CHANGED
@@ -23,7 +23,7 @@ module Vedeu
|
|
23
23
|
:height,
|
24
24
|
:width
|
25
25
|
|
26
|
-
# @!attribute [rw]
|
26
|
+
# @!attribute [rw] maximised
|
27
27
|
# @return [Boolean]
|
28
28
|
attr_accessor :maximised
|
29
29
|
|
@@ -36,7 +36,8 @@ module Vedeu
|
|
36
36
|
# @param name [String|NilClass]
|
37
37
|
# @return [Vedeu::Null::Geometry]
|
38
38
|
def initialize(name = nil)
|
39
|
-
@name
|
39
|
+
@name = name
|
40
|
+
@maximised = false
|
40
41
|
end
|
41
42
|
|
42
43
|
# @return [FalseClass]
|
data/lib/vedeu/output/border.rb
CHANGED
@@ -120,22 +120,22 @@ module Vedeu
|
|
120
120
|
|
121
121
|
# @return [Fixnum]
|
122
122
|
def bx
|
123
|
-
(enabled? && left?) ? x + 1 : x
|
123
|
+
@bx ||= (enabled? && left?) ? x + 1 : x
|
124
124
|
end
|
125
125
|
|
126
126
|
# @return [Fixnum]
|
127
127
|
def bxn
|
128
|
-
(enabled? && right?) ? xn - 1 : xn
|
128
|
+
@bxn ||= (enabled? && right?) ? xn - 1 : xn
|
129
129
|
end
|
130
130
|
|
131
131
|
# @return [Fixnum]
|
132
132
|
def by
|
133
|
-
(enabled? && top?) ? y + 1 : y
|
133
|
+
@by ||= (enabled? && top?) ? y + 1 : y
|
134
134
|
end
|
135
135
|
|
136
136
|
# @return [Fixnum]
|
137
137
|
def byn
|
138
|
-
(enabled? && bottom?) ? yn - 1 : yn
|
138
|
+
@byn ||= (enabled? && bottom?) ? yn - 1 : yn
|
139
139
|
end
|
140
140
|
|
141
141
|
# Returns the width of the interface determined by whether a left, right,
|
@@ -159,7 +159,7 @@ module Vedeu
|
|
159
159
|
return [] unless visible?
|
160
160
|
return [] unless enabled?
|
161
161
|
|
162
|
-
Vedeu
|
162
|
+
Vedeu.timer("Rendering border: #{name}") do
|
163
163
|
out = [top, bottom]
|
164
164
|
|
165
165
|
height.times do |y|
|
@@ -300,7 +300,7 @@ module Vedeu
|
|
300
300
|
#
|
301
301
|
# @return [Boolean]
|
302
302
|
def title?
|
303
|
-
|
303
|
+
present?(title)
|
304
304
|
end
|
305
305
|
|
306
306
|
# @param value [String]
|
data/lib/vedeu/output/clear.rb
CHANGED
@@ -76,7 +76,7 @@ module Vedeu
|
|
76
76
|
# @return [Array<Array<Vedeu::Char>>]
|
77
77
|
def clear
|
78
78
|
if visible?
|
79
|
-
Vedeu
|
79
|
+
Vedeu.timer("Clearing: #{name}") do
|
80
80
|
y, x = *position
|
81
81
|
|
82
82
|
@clear ||= Array.new(height) do |iy|
|
@@ -84,7 +84,7 @@ module Vedeu
|
|
84
84
|
Vedeu::Char.new(value: ' ',
|
85
85
|
colour: clear_colour,
|
86
86
|
style: style,
|
87
|
-
position: [y + iy, x + ix])
|
87
|
+
position: Vedeu::Position[y + iy, x + ix])
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -111,7 +111,7 @@ module Vedeu
|
|
111
111
|
|
112
112
|
private
|
113
113
|
|
114
|
-
# @
|
114
|
+
# @see Vedeu::Borders#by_name
|
115
115
|
def border
|
116
116
|
@border ||= Vedeu.borders.by_name(name)
|
117
117
|
end
|
@@ -143,7 +143,7 @@ module Vedeu
|
|
143
143
|
}
|
144
144
|
end
|
145
145
|
|
146
|
-
# @
|
146
|
+
# @see Vedeu::Geometries#by_name
|
147
147
|
def geometry
|
148
148
|
@geometry ||= Vedeu.geometries.by_name(name)
|
149
149
|
end
|
@@ -5,6 +5,12 @@ module Vedeu
|
|
5
5
|
# sequence, resulting in a smaller payload being sent to the renderer.
|
6
6
|
class Compressor
|
7
7
|
|
8
|
+
# @param output [Array<Array<Vedeu::Char>>]
|
9
|
+
# @return [String]
|
10
|
+
def self.render(output)
|
11
|
+
new(output).render
|
12
|
+
end
|
13
|
+
|
8
14
|
# @param output [Array<Array<Vedeu::Char>>]
|
9
15
|
# @return [Vedeu::Compressor]
|
10
16
|
def initialize(output)
|
@@ -16,14 +22,14 @@ module Vedeu
|
|
16
22
|
# @note Takes approximately ~70ms for 2100 chars. (2015-05-24)
|
17
23
|
# @return [String]
|
18
24
|
def render
|
19
|
-
|
20
|
-
|
25
|
+
out = ''
|
26
|
+
Array(output).flatten.each do |char|
|
21
27
|
out << char.position.to_s
|
22
28
|
out << colour_for(char)
|
23
29
|
out << style_for(char)
|
24
30
|
out << char.value
|
25
|
-
|
26
|
-
|
31
|
+
end
|
32
|
+
out
|
27
33
|
end
|
28
34
|
|
29
35
|
protected
|
@@ -36,7 +36,7 @@ module Vedeu
|
|
36
36
|
|
37
37
|
# @return [String]
|
38
38
|
def td_style
|
39
|
-
return '' unless border ||
|
39
|
+
return '' unless border || present?(value)
|
40
40
|
|
41
41
|
" style='" \
|
42
42
|
"background:#{bg};" \
|
@@ -47,7 +47,7 @@ module Vedeu
|
|
47
47
|
|
48
48
|
# @return [String]
|
49
49
|
def td_value
|
50
|
-
return ' ' if border || !
|
50
|
+
return ' ' if border || !present?(value)
|
51
51
|
|
52
52
|
value
|
53
53
|
end
|
@@ -102,10 +102,10 @@ module Vedeu
|
|
102
102
|
type_to_html = char.send(type).send(:to_html)
|
103
103
|
parent_type_to_html = char.send(parent_type).send(:to_html)
|
104
104
|
|
105
|
-
if
|
105
|
+
if present?(type_to_html)
|
106
106
|
type_to_html
|
107
107
|
|
108
|
-
elsif
|
108
|
+
elsif present?(parent_type_to_html)
|
109
109
|
parent_type_to_html
|
110
110
|
|
111
111
|
else
|
data/lib/vedeu/output/refresh.rb
CHANGED
@@ -12,7 +12,7 @@ module Vedeu
|
|
12
12
|
def all
|
13
13
|
message = 'Refreshing all interfaces'
|
14
14
|
|
15
|
-
Vedeu
|
15
|
+
Vedeu.timer(message) do
|
16
16
|
Vedeu.interfaces.zindexed.each { |model| by_name(model.name) }
|
17
17
|
end
|
18
18
|
end
|
@@ -32,7 +32,7 @@ module Vedeu
|
|
32
32
|
def by_group(group_name)
|
33
33
|
message = "Refreshing group: '#{group_name}'"
|
34
34
|
|
35
|
-
Vedeu
|
35
|
+
Vedeu.timer(message) do
|
36
36
|
Vedeu.groups.find!(group_name).members.each { |name|
|
37
37
|
Vedeu.interfaces.by_name(name)
|
38
38
|
}.sort { |a, b| a.zindex <=> b.zindex }.each { |name| by_name(name) }
|
@@ -47,7 +47,7 @@ module Vedeu
|
|
47
47
|
def by_name(name)
|
48
48
|
message = "Refreshing interface: '#{name}'"
|
49
49
|
|
50
|
-
Vedeu
|
50
|
+
Vedeu.timer(message) { Vedeu.buffers.by_name(name).render }
|
51
51
|
end
|
52
52
|
|
53
53
|
end # Refresh
|
data/lib/vedeu/output/style.rb
CHANGED
@@ -44,14 +44,6 @@ module Vedeu
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
# Convert a CSS/HTML colour string into a terminal escape sequence.
|
48
|
-
#
|
49
|
-
# @param colour [Fixnum|String|Symbol]
|
50
|
-
# @return [String]
|
51
|
-
def self.escape_sequence(colour = '')
|
52
|
-
new(colour).escape_sequence
|
53
|
-
end
|
54
|
-
|
55
47
|
# Return a new instance of Vedeu::Translator.
|
56
48
|
#
|
57
49
|
# @param colour [Fixnum|String|Symbol]
|
@@ -156,7 +156,7 @@ module Vedeu
|
|
156
156
|
# @return [void] The model instance which was stored.
|
157
157
|
def store(model)
|
158
158
|
fail MissingRequired, "Cannot store model '#{model.class}' without a " \
|
159
|
-
'name attribute.' unless
|
159
|
+
'name attribute.' unless present?(model.name)
|
160
160
|
|
161
161
|
log_store(model)
|
162
162
|
|
data/lib/vedeu/support/common.rb
CHANGED
@@ -8,7 +8,7 @@ module Vedeu
|
|
8
8
|
#
|
9
9
|
# @param variable [String|Symbol|Array|Fixnum] The variable to check.
|
10
10
|
# @return [Boolean]
|
11
|
-
def
|
11
|
+
def present?(variable)
|
12
12
|
return true if variable.is_a?(Fixnum)
|
13
13
|
return true unless variable.nil? || variable.empty?
|
14
14
|
|
data/lib/vedeu/support/timer.rb
CHANGED
@@ -3,19 +3,20 @@ module Vedeu
|
|
3
3
|
# Measure the duration. Used for debugging.
|
4
4
|
class Timer
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
class << self
|
7
|
+
|
8
|
+
# @param message [String]
|
9
|
+
# @param block [Proc]
|
10
|
+
# @return [void]
|
11
|
+
def timer(message = '', &block)
|
12
|
+
new(message).measure(&block)
|
13
|
+
end
|
14
|
+
|
12
15
|
end
|
13
16
|
|
14
|
-
# @param type [Symbol]
|
15
17
|
# @param message [String]
|
16
18
|
# @return [Vedeu::Timer]
|
17
|
-
def initialize(
|
18
|
-
@type = type
|
19
|
+
def initialize(message = '')
|
19
20
|
@message = message
|
20
21
|
@started = Time.now.to_f
|
21
22
|
end
|
@@ -27,7 +28,7 @@ module Vedeu
|
|
27
28
|
|
28
29
|
elapsed = ((Time.now.to_f - started) * 1000).to_i
|
29
30
|
|
30
|
-
Vedeu.log(type:
|
31
|
+
Vedeu.log(type: :timer, message: "#{message} took #{elapsed}ms.")
|
31
32
|
|
32
33
|
work
|
33
34
|
end
|
@@ -42,10 +43,6 @@ module Vedeu
|
|
42
43
|
# @return [String]
|
43
44
|
attr_reader :message
|
44
45
|
|
45
|
-
# @!attribute [r] type
|
46
|
-
# @return [Symbol]
|
47
|
-
attr_reader :type
|
48
|
-
|
49
46
|
end # Timer
|
50
47
|
|
51
48
|
end # Vedeu
|
data/lib/vedeu/templating/all.rb
CHANGED
@@ -2,8 +2,14 @@ module Vedeu
|
|
2
2
|
|
3
3
|
module Templating
|
4
4
|
|
5
|
+
# Provide helpers to be used with your Vedeu templates.
|
5
6
|
module Helpers
|
6
7
|
|
8
|
+
# @example
|
9
|
+
# Roses are {{ background('#ff0000', 'red') }},
|
10
|
+
# violets are {{ bg('#0000ff', 'blue') }},
|
11
|
+
# {{ background('#00ff00'), 'The test suite is all green!' }}
|
12
|
+
#
|
7
13
|
# @param value [String] The HTML/CSS colour.
|
8
14
|
# @param block [Proc]
|
9
15
|
# @return [Vedeu::Stream]
|
@@ -25,7 +31,7 @@ module Vedeu
|
|
25
31
|
|
26
32
|
# @example
|
27
33
|
# Roses are {{ foreground('#ff0000', 'red') }},
|
28
|
-
# violets are {{ fg('#0000ff', 'blue') }}
|
34
|
+
# violets are {{ fg('#0000ff', 'blue') }},
|
29
35
|
# {{ foreground('#00ff00'), 'The test suite is all green!' }}
|
30
36
|
#
|
31
37
|
# @param value [String] The HTML/CSS colour.
|
@@ -39,7 +45,7 @@ module Vedeu
|
|
39
45
|
|
40
46
|
private
|
41
47
|
|
42
|
-
# @
|
48
|
+
# @see Vedeu::Templating::Helpers#colours
|
43
49
|
def define_colour(attributes = {})
|
44
50
|
attributes.delete_if do |k, v|
|
45
51
|
[:background, :foreground].include?(k) == false || v.nil? || v.empty?
|
@@ -48,7 +54,7 @@ module Vedeu
|
|
48
54
|
Vedeu::Colour.new(attributes)
|
49
55
|
end
|
50
56
|
|
51
|
-
# @
|
57
|
+
# @see Vedeu::Templating::Helpers#colours
|
52
58
|
def define_stream(attributes = {}, &block)
|
53
59
|
fail InvalidSyntax, 'block not given' unless block_given?
|
54
60
|
|
@@ -11,7 +11,7 @@ module Vedeu
|
|
11
11
|
#
|
12
12
|
# process
|
13
13
|
# converts JSON streams into line/stream objects with correct attributes
|
14
|
-
|
14
|
+
#
|
15
15
|
# Pre-processes a template, to convert all lines and lines with directives
|
16
16
|
# into Vedeu::Streams.
|
17
17
|
class Preprocessor
|
@@ -52,6 +52,9 @@ module Vedeu
|
|
52
52
|
|
53
53
|
# Return a pattern to remove directive markers and spaces.
|
54
54
|
#
|
55
|
+
# @example
|
56
|
+
# line containing {{ or }}
|
57
|
+
#
|
55
58
|
# @return [Regexp]
|
56
59
|
def markers
|
57
60
|
/({{\s*|\s*}})/
|