vedeu 0.1.3 → 0.1.4
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/Guardfile +5 -0
- data/README.md +34 -0
- data/deps.md +13 -13
- data/lib/vedeu.rb +1 -1
- data/lib/vedeu/instrumentation.rb +1 -1
- data/lib/vedeu/models/geometry.rb +76 -0
- data/lib/vedeu/models/interface.rb +9 -21
- data/lib/vedeu/models/stream.rb +16 -4
- data/lib/vedeu/output/clear_interface.rb +4 -4
- data/lib/vedeu/{support/translator.rb → output/colour_translator.rb} +1 -1
- data/lib/vedeu/output/erb_parser.rb +11 -0
- data/lib/vedeu/output/raw_parser.rb +9 -1
- data/lib/vedeu/output/render_interface.rb +3 -3
- data/lib/vedeu/support/esc.rb +8 -6
- data/lib/vedeu/support/helpers.rb +39 -18
- data/lib/vedeu/support/interface_template.rb +42 -19
- data/test/lib/vedeu/models/composition_test.rb +27 -21
- data/test/lib/vedeu/models/geometry_test.rb +183 -0
- data/test/lib/vedeu/models/interface_test.rb +26 -59
- data/test/lib/vedeu/models/stream_test.rb +57 -7
- data/test/lib/vedeu/output/clear_interface_test.rb +8 -4
- data/test/lib/vedeu/{support/translator_test.rb → output/colour_translator_test.rb} +8 -8
- data/test/lib/vedeu/output/erb_parser_test.rb +158 -70
- data/test/lib/vedeu/output/render_interface_test.rb +4 -3
- data/test/lib/vedeu/support/esc_test.rb +10 -2
- data/test/lib/vedeu/support/helpers_test.rb +11 -4
- data/test/lib/vedeu/support/interface_template_test.rb +58 -34
- data/test/support/colours.rb +2 -2
- data/test/support/erb/line.erb +4 -0
- data/test/support/erb/line_2x.erb +10 -0
- data/test/support/erb/line_foreground.erb +4 -0
- data/test/support/erb/line_foreground_2x.erb +5 -0
- data/vedeu.gemspec +2 -1
- metadata +30 -8
- data/lib/vedeu/support/geometry.rb +0 -172
- data/test/lib/vedeu/support/geometry_test.rb +0 -408
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c4536e9fdde25f748de839f9a992e805b97f308
|
4
|
+
data.tar.gz: 0a951cfde4234e720dcbdf943bf6f91c2b95dc41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f92b9b9b3bdccb7a55df3aedddde6bd9ae67a88925c1c1584d274ebcdab52a98624377968ff91f8a1f61c854567cd363e848cb67d356665e4bf7be02b07ff8b2
|
7
|
+
data.tar.gz: 839cbdab1f3b684e35874975b2dc6c2052487edb94cdbef65aa12c72282ab679b711fac9dc11743a85849d1e817e4992143760509541e1adaac65cc3ed283d8e
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -58,6 +58,20 @@ Expect proper documentation soon!
|
|
58
58
|
end
|
59
59
|
|
60
60
|
|
61
|
+
### Building Views
|
62
|
+
|
63
|
+
Views with Vedeu are made up of simple building blocks. These blocks can be arranged in a multitude of ways which I hope is more than sufficient for your design needs.
|
64
|
+
|
65
|
+
- Interfaces (`Interface`) are made up of lines. (`Line`)
|
66
|
+
- Lines are made up of zero, one or multiple streams. (`Stream`)
|
67
|
+
- An interface, line or stream can have a colour (`colour`) attribute.
|
68
|
+
- An interface, line or stream can have a style (`style`) attribute.
|
69
|
+
- Interfaces have a position (`y`, `x`) on the screen, and a size. (`width`, `height`)
|
70
|
+
- Interfaces can be placed relative to each other based on their attributes. (`top`, `right`, `bottom`, `left`)
|
71
|
+
- Colours are defined in CSS-style values, i.e. `#ff0000` would be red.
|
72
|
+
- Styles are named. See the table below for supported styles.
|
73
|
+
|
74
|
+
|
61
75
|
### Some Terms
|
62
76
|
|
63
77
|
To understand how Vedeu works, you need to familiarise yourself with some terms.
|
@@ -133,6 +147,26 @@ Vedeu has a range of symbol styles which are compatible with most terminals whic
|
|
133
147
|
|
134
148
|
Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
|
135
149
|
|
150
|
+
| Style name | Escape Sequence |
|
151
|
+
|---------------|--------------------------|
|
152
|
+
| bg_reset | `\e[48;2;49m` |
|
153
|
+
| blink | `\e[5m` |
|
154
|
+
| blink_off | `\e[25m` |
|
155
|
+
| bold | `\e[1m` |
|
156
|
+
| bold_off | `\e[21m` |
|
157
|
+
| clear | `\e[2J` |
|
158
|
+
| colour_reset | `\e[38;2;39m\e[48;2;49m` |
|
159
|
+
| fg_reset | `\e[38;2;39m` |
|
160
|
+
| hide_cursor | `\e[?25l` |
|
161
|
+
| negative | `\e[7m` |
|
162
|
+
| positive | `\e[27m` |
|
163
|
+
| reset | `\e[0m` |
|
164
|
+
| normal | `\e[24m\e[21m\e[27m` |
|
165
|
+
| dim | `\e[2m` |
|
166
|
+
| show_cursor | `\e[?25h` |
|
167
|
+
| underline | `\e[4m` |
|
168
|
+
| underline_off | `\e[24m` |
|
169
|
+
|
136
170
|
|
137
171
|
### Templates
|
138
172
|
|
data/deps.md
CHANGED
@@ -26,7 +26,7 @@ Geometry
|
|
26
26
|
ERBParser
|
27
27
|
|
28
28
|
Esc
|
29
|
-
|
29
|
+
ColourTranslator
|
30
30
|
|
31
31
|
Events
|
32
32
|
|
@@ -113,7 +113,7 @@ Terminal
|
|
113
113
|
|
114
114
|
TextAdaptor
|
115
115
|
|
116
|
-
|
116
|
+
ColourTranslator
|
117
117
|
|
118
118
|
Wordwrap
|
119
119
|
|
@@ -140,7 +140,7 @@ Launcher
|
|
140
140
|
Queue
|
141
141
|
Terminal
|
142
142
|
Esc
|
143
|
-
|
143
|
+
ColourTranslator
|
144
144
|
Process
|
145
145
|
Parser
|
146
146
|
Composition
|
@@ -150,41 +150,41 @@ Launcher
|
|
150
150
|
ClearInterface
|
151
151
|
Colour
|
152
152
|
Esc
|
153
|
-
|
153
|
+
ColourTranslator
|
154
154
|
Geometry
|
155
155
|
Esc
|
156
|
-
|
156
|
+
ColourTranslator
|
157
157
|
Terminal
|
158
158
|
Esc
|
159
|
-
|
159
|
+
ColourTranslator
|
160
160
|
LineCollection
|
161
161
|
Collection
|
162
162
|
Line
|
163
163
|
Colour
|
164
164
|
Esc
|
165
|
-
|
165
|
+
ColourTranslator
|
166
166
|
StreamCollection
|
167
167
|
Collection
|
168
168
|
Stream
|
169
169
|
Colour
|
170
170
|
Esc
|
171
|
-
|
171
|
+
ColourTranslator
|
172
172
|
Style
|
173
173
|
Esc
|
174
|
-
|
174
|
+
ColourTranslator
|
175
175
|
Style
|
176
176
|
Esc
|
177
|
-
|
177
|
+
ColourTranslator
|
178
178
|
|
179
179
|
Queue
|
180
180
|
RenderInterface
|
181
181
|
ClearInterface
|
182
182
|
Style
|
183
183
|
Esc
|
184
|
-
|
184
|
+
ColourTranslator
|
185
185
|
Terminal
|
186
186
|
Esc
|
187
|
-
|
187
|
+
ColourTranslator
|
188
188
|
ERBParser
|
189
189
|
Template
|
190
190
|
RawParser
|
@@ -194,5 +194,5 @@ Launcher
|
|
194
194
|
Queue
|
195
195
|
Terminal
|
196
196
|
Esc
|
197
|
-
|
197
|
+
ColourTranslator
|
198
198
|
Configuration
|
data/lib/vedeu.rb
CHANGED
@@ -3,7 +3,7 @@ require 'vedeu/support/interface_template'
|
|
3
3
|
require 'vedeu/support/events'
|
4
4
|
require 'vedeu/support/interface_store'
|
5
5
|
|
6
|
-
require 'vedeu/
|
6
|
+
require 'vedeu/models/geometry'
|
7
7
|
require 'vedeu/support/menu'
|
8
8
|
require 'vedeu/output/view'
|
9
9
|
require 'vedeu/launcher'
|
@@ -70,7 +70,7 @@ module Vedeu
|
|
70
70
|
def defaults
|
71
71
|
{
|
72
72
|
event: 'call',
|
73
|
-
klass: /^Vedeu::(?!.*Instrumentation|Interface|Line|Stream|Style|Colour|Geometry|Terminal|Esc|
|
73
|
+
klass: /^Vedeu::(?!.*Instrumentation|Interface|Line|Stream|Style|Colour|Geometry|Terminal|Esc|ColourTranslator).*/
|
74
74
|
}
|
75
75
|
end
|
76
76
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require 'vedeu/support/esc'
|
4
|
+
require 'vedeu/support/terminal'
|
5
|
+
|
6
|
+
module Vedeu
|
7
|
+
class Geometry
|
8
|
+
include Virtus.model
|
9
|
+
|
10
|
+
attribute :y, Integer, default: 1
|
11
|
+
attribute :x, Integer, default: 1
|
12
|
+
attribute :width, Integer, default: Terminal.width
|
13
|
+
attribute :height, Integer, default: Terminal.height
|
14
|
+
attribute :centred, Boolean, default: false
|
15
|
+
|
16
|
+
def origin(index = 0)
|
17
|
+
Esc.set_position(virtual_y[index], left)
|
18
|
+
end
|
19
|
+
|
20
|
+
def top
|
21
|
+
if centred
|
22
|
+
centre_y - (height / 2)
|
23
|
+
else
|
24
|
+
y
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def left
|
29
|
+
if centred
|
30
|
+
centre_x - (width / 2)
|
31
|
+
else
|
32
|
+
x
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def bottom
|
37
|
+
top + height
|
38
|
+
end
|
39
|
+
|
40
|
+
def right
|
41
|
+
left + width
|
42
|
+
end
|
43
|
+
|
44
|
+
def position
|
45
|
+
{
|
46
|
+
y: top,
|
47
|
+
x: left,
|
48
|
+
height: height,
|
49
|
+
width: width,
|
50
|
+
centred: centred,
|
51
|
+
top: top,
|
52
|
+
bottom: bottom,
|
53
|
+
left: left,
|
54
|
+
right: right,
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def centre
|
61
|
+
@_centre ||= Terminal.centre
|
62
|
+
end
|
63
|
+
|
64
|
+
def centre_y
|
65
|
+
centre.first
|
66
|
+
end
|
67
|
+
|
68
|
+
def centre_x
|
69
|
+
centre.last
|
70
|
+
end
|
71
|
+
|
72
|
+
def virtual_y
|
73
|
+
@_virtual_y ||= (top..bottom).to_a
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -6,7 +6,7 @@ require 'vedeu/models/colour'
|
|
6
6
|
require 'vedeu/models/style'
|
7
7
|
require 'vedeu/output/clear_interface'
|
8
8
|
require 'vedeu/output/render_interface'
|
9
|
-
require 'vedeu/
|
9
|
+
require 'vedeu/models/geometry'
|
10
10
|
require 'vedeu/support/queue'
|
11
11
|
require 'vedeu/support/terminal'
|
12
12
|
|
@@ -17,18 +17,14 @@ module Vedeu
|
|
17
17
|
include Vedeu::Queue
|
18
18
|
include Virtus.model
|
19
19
|
|
20
|
-
attribute :name,
|
21
|
-
attribute :lines,
|
22
|
-
attribute :colour,
|
23
|
-
attribute :style,
|
24
|
-
attribute :
|
25
|
-
attribute :
|
26
|
-
attribute :
|
27
|
-
attribute :
|
28
|
-
attribute :current, String, default: ''
|
29
|
-
attribute :cursor, Boolean, default: true
|
30
|
-
attribute :centred, Boolean, default: false
|
31
|
-
attribute :delay, Float, default: 0
|
20
|
+
attribute :name, String
|
21
|
+
attribute :lines, LineCollection
|
22
|
+
attribute :colour, Colour, default: Colour.new
|
23
|
+
attribute :style, Style, default: ''
|
24
|
+
attribute :geometry, Geometry, default: Geometry.new
|
25
|
+
attribute :current, String, default: ''
|
26
|
+
attribute :cursor, Boolean, default: true
|
27
|
+
attribute :delay, Float, default: 0
|
32
28
|
|
33
29
|
def initialize(attributes = {})
|
34
30
|
super
|
@@ -46,14 +42,6 @@ module Vedeu
|
|
46
42
|
super(self.to_s)
|
47
43
|
end
|
48
44
|
|
49
|
-
def geometry
|
50
|
-
@_geometry ||= Geometry.new(attributes)
|
51
|
-
end
|
52
|
-
|
53
|
-
def origin(index = 0)
|
54
|
-
geometry.origin(index)
|
55
|
-
end
|
56
|
-
|
57
45
|
def refresh
|
58
46
|
if enqueued?
|
59
47
|
self.current = dequeue
|
data/lib/vedeu/models/stream.rb
CHANGED
@@ -7,12 +7,24 @@ module Vedeu
|
|
7
7
|
class Stream
|
8
8
|
include Virtus.model
|
9
9
|
|
10
|
-
attribute :colour, Colour,
|
11
|
-
attribute :style, Style,
|
12
|
-
attribute :text, String,
|
10
|
+
attribute :colour, Colour, default: Colour.new
|
11
|
+
attribute :style, Style, default: ''
|
12
|
+
attribute :text, String, default: ''
|
13
|
+
attribute :width, Integer
|
14
|
+
attribute :align, Symbol, default: :left # :centre, :right
|
13
15
|
|
14
16
|
def to_s(options = {})
|
15
|
-
|
17
|
+
if width
|
18
|
+
aligned = case align
|
19
|
+
when :left then text.ljust(width, ' ')
|
20
|
+
when :right then text.rjust(width, ' ')
|
21
|
+
when :centre then text.center(width, ' ')
|
22
|
+
end
|
23
|
+
|
24
|
+
[colour, style, aligned].join
|
25
|
+
else
|
26
|
+
[colour, style, text].join
|
27
|
+
end
|
16
28
|
end
|
17
29
|
end
|
18
30
|
end
|
@@ -10,9 +10,9 @@ module Vedeu
|
|
10
10
|
|
11
11
|
def clear
|
12
12
|
interface_lines.inject([colours]) do |line, index|
|
13
|
-
line << interface.origin(index)
|
14
|
-
line << ' ' * interface.width
|
15
|
-
line << interface.origin(index)
|
13
|
+
line << interface.geometry.origin(index)
|
14
|
+
line << ' ' * interface.geometry.width
|
15
|
+
line << interface.geometry.origin(index)
|
16
16
|
end.join
|
17
17
|
end
|
18
18
|
|
@@ -25,7 +25,7 @@ module Vedeu
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def interface_lines
|
28
|
-
interface.height.times
|
28
|
+
interface.geometry.height.times
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -12,6 +12,7 @@ module Vedeu
|
|
12
12
|
|
13
13
|
def initialize(object)
|
14
14
|
@object = object
|
15
|
+
@output = ''
|
15
16
|
end
|
16
17
|
|
17
18
|
def parse
|
@@ -29,6 +30,16 @@ module Vedeu
|
|
29
30
|
|
30
31
|
attr_reader :object
|
31
32
|
|
33
|
+
def capture(&block)
|
34
|
+
erbout = eval('_erbout', block.binding)
|
35
|
+
erbout_length = erbout.length
|
36
|
+
block.call
|
37
|
+
erbout_addition = erbout[erbout_length..-1]
|
38
|
+
erbout[erbout_length..-1] = ''
|
39
|
+
erbout_addition = erbout_addition.join if erbout_addition.is_a? Array
|
40
|
+
erbout_addition
|
41
|
+
end
|
42
|
+
|
32
43
|
def erb_output
|
33
44
|
ERB.new(template, nil, '-').result(get_binding)
|
34
45
|
end
|
@@ -22,11 +22,19 @@ module Vedeu
|
|
22
22
|
stringified_keys.map do |name, content|
|
23
23
|
{
|
24
24
|
name: name,
|
25
|
-
lines:
|
25
|
+
lines: lines(content)
|
26
26
|
}
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def lines(content)
|
31
|
+
if content.is_a?(Array) && content.first.is_a?(Hash)
|
32
|
+
content
|
33
|
+
else
|
34
|
+
TextAdaptor.adapt(content)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
30
38
|
def stringified_keys
|
31
39
|
attributes.inject({}) { |a, (k, v)| a[k.to_s] = v; a }
|
32
40
|
end
|
@@ -12,7 +12,7 @@ module Vedeu
|
|
12
12
|
out = [interface.clear]
|
13
13
|
processed_lines.each_with_index do |line, index|
|
14
14
|
if index + 1 <= height
|
15
|
-
out << interface.origin(index)
|
15
|
+
out << interface.geometry.origin(index)
|
16
16
|
out << line.to_s
|
17
17
|
end
|
18
18
|
end
|
@@ -61,11 +61,11 @@ module Vedeu
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def height
|
64
|
-
interface.height
|
64
|
+
interface.geometry.height
|
65
65
|
end
|
66
66
|
|
67
67
|
def width
|
68
|
-
interface.width
|
68
|
+
interface.geometry.width
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
data/lib/vedeu/support/esc.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
require 'vedeu/
|
1
|
+
require 'vedeu/output/colour_translator'
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
module Esc
|
5
5
|
extend self
|
6
6
|
|
7
|
-
def background_colour(value = '
|
8
|
-
return '' if value.empty?
|
7
|
+
def background_colour(value = '')
|
8
|
+
return '' if value.nil? || value.empty?
|
9
9
|
|
10
10
|
["\e[48;5;", colour_translator(value), 'm'].join
|
11
11
|
end
|
12
12
|
|
13
|
-
def foreground_colour(value = '
|
14
|
-
return '' if value.empty?
|
13
|
+
def foreground_colour(value = '')
|
14
|
+
return '' if value.nil? || value.empty?
|
15
15
|
|
16
16
|
["\e[38;5;", colour_translator(value), 'm'].join
|
17
17
|
end
|
@@ -25,12 +25,14 @@ module Vedeu
|
|
25
25
|
|
26
26
|
def string(value = '')
|
27
27
|
case value
|
28
|
+
when 'bg_reset' then "\e[48;2;49m"
|
28
29
|
when 'blink' then "\e[5m"
|
29
30
|
when 'blink_off' then "\e[25m"
|
30
31
|
when 'bold' then "\e[1m"
|
31
32
|
when 'bold_off' then "\e[21m"
|
32
33
|
when 'clear' then "\e[2J"
|
33
34
|
when 'colour_reset' then "\e[38;2;39m\e[48;2;49m"
|
35
|
+
when 'fg_reset' then "\e[38;2;39m"
|
34
36
|
when 'hide_cursor' then "\e[?25l"
|
35
37
|
when 'negative' then "\e[7m"
|
36
38
|
when 'positive' then "\e[27m"
|
@@ -48,7 +50,7 @@ module Vedeu
|
|
48
50
|
private
|
49
51
|
|
50
52
|
def colour_translator(value)
|
51
|
-
|
53
|
+
ColourTranslator.translate(value)
|
52
54
|
end
|
53
55
|
end
|
54
56
|
end
|