vedeu 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vedeu.rb +1 -1
- data/lib/vedeu/all.rb +2 -0
- data/lib/vedeu/buffers/buffer.rb +0 -11
- data/lib/vedeu/configuration/api.rb +4 -6
- data/lib/vedeu/configuration/cli.rb +1 -3
- data/lib/vedeu/configuration/configuration.rb +15 -0
- data/lib/vedeu/cursor/cursor.rb +2 -9
- data/lib/vedeu/cursor/move_cursor.rb +7 -9
- data/lib/vedeu/cursor/toggle_cursor.rb +2 -2
- data/lib/vedeu/debug.rb +3 -0
- data/lib/vedeu/distributed/test_application.rb +4 -8
- data/lib/vedeu/dsl/components/keymap.rb +1 -3
- data/lib/vedeu/dsl/composition.rb +2 -2
- data/lib/vedeu/dsl/interface.rb +2 -2
- data/lib/vedeu/dsl/shared/text.rb +2 -2
- data/lib/vedeu/events/event.rb +1 -1
- data/lib/vedeu/geometry/all.rb +10 -0
- data/lib/vedeu/{support → geometry}/bounding_area.rb +1 -0
- data/lib/vedeu/{support → geometry}/content_geometry.rb +0 -7
- data/lib/vedeu/{support → geometry}/coordinate.rb +0 -14
- data/lib/vedeu/{support → geometry}/grid.rb +0 -0
- data/lib/vedeu/{support → geometry}/limit.rb +0 -0
- data/lib/vedeu/{support → geometry}/position.rb +3 -5
- data/lib/vedeu/{support → geometry}/position_validator.rb +2 -0
- data/lib/vedeu/input/input.rb +1 -1
- data/lib/vedeu/input/key.rb +0 -13
- data/lib/vedeu/input/keymap.rb +1 -1
- data/lib/vedeu/models/focus.rb +2 -2
- data/lib/vedeu/models/geometry.rb +4 -51
- data/lib/vedeu/models/menu.rb +1 -1
- data/lib/vedeu/models/model.rb +1 -1
- data/lib/vedeu/models/view/char.rb +2 -9
- data/lib/vedeu/models/view/composition.rb +3 -10
- data/lib/vedeu/models/view/interface.rb +5 -13
- data/lib/vedeu/models/view/line.rb +3 -10
- data/lib/vedeu/models/view/stream.rb +18 -11
- data/lib/vedeu/output/background.rb +6 -21
- data/lib/vedeu/output/border.rb +26 -17
- data/lib/vedeu/output/colour.rb +1 -1
- data/lib/vedeu/output/foreground.rb +6 -21
- data/lib/vedeu/output/html_renderer.rb +3 -9
- data/lib/vedeu/output/output.rb +38 -11
- data/lib/vedeu/output/style.rb +1 -1
- data/lib/vedeu/output/translator.rb +45 -15
- data/lib/vedeu/output/viewport.rb +1 -1
- data/lib/vedeu/output/virtual_buffer.rb +2 -2
- data/lib/vedeu/output/wordwrap.rb +1 -1
- data/lib/vedeu/repositories/all.rb +9 -9
- data/lib/vedeu/repositories/repository.rb +0 -7
- data/lib/vedeu/support/all.rb +1 -7
- data/lib/vedeu/support/esc.rb +33 -11
- data/lib/vedeu/support/template.rb +39 -0
- data/lib/vedeu/support/terminal.rb +3 -3
- data/lib/vedeu/support/text.rb +1 -1
- data/lib/vedeu/support/trace.rb +4 -4
- data/lib/vedeu/support/visible.rb +2 -7
- data/test/lib/vedeu/buffers/buffer_test.rb +0 -6
- data/test/lib/vedeu/cursor/cursor_test.rb +0 -6
- data/test/lib/vedeu/{support → geometry}/bounding_area_test.rb +0 -0
- data/test/lib/vedeu/{support → geometry}/content_geometry_test.rb +0 -6
- data/test/lib/vedeu/{support → geometry}/coordinate_test.rb +0 -8
- data/test/lib/vedeu/{support → geometry}/grid_test.rb +0 -0
- data/test/lib/vedeu/{support → geometry}/limit_test.rb +0 -0
- data/test/lib/vedeu/{support → geometry}/position_test.rb +8 -6
- data/test/lib/vedeu/{support → geometry}/position_validator_test.rb +0 -0
- data/test/lib/vedeu/input/key_test.rb +0 -12
- data/test/lib/vedeu/models/geometry_test.rb +0 -47
- data/test/lib/vedeu/models/view/char_test.rb +5 -9
- data/test/lib/vedeu/models/view/composition_test.rb +2 -8
- data/test/lib/vedeu/models/view/interface_test.rb +2 -8
- data/test/lib/vedeu/models/view/line_test.rb +0 -6
- data/test/lib/vedeu/models/view/stream_test.rb +0 -6
- data/test/lib/vedeu/output/border_test.rb +2 -2
- data/test/lib/vedeu/output/html_renderer_test.rb +0 -1
- data/test/lib/vedeu/output/output_test.rb +39 -0
- data/test/lib/vedeu/repositories/repository_test.rb +0 -6
- data/test/lib/vedeu/support/template_test.rb +24 -0
- data/test/lib/vedeu/support/visible_test.rb +0 -6
- data/test/support/helpers/model_test_class.rb +1 -1
- data/vedeu.gemspec +1 -1
- metadata +27 -23
@@ -13,34 +13,19 @@ module Vedeu
|
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
# Returns an escape sequence for a named foreground colour.
|
17
|
-
#
|
18
|
-
# Valid names are: `:black`, `:red`, `:green`, `:yellow`, `:blue`,
|
19
|
-
# `:magenta`, `:cyan`, `:white` and `:default`.
|
20
|
-
#
|
21
16
|
# @return [String]
|
22
|
-
def
|
23
|
-
|
17
|
+
def named_codes
|
18
|
+
Esc.foreground_codes[colour]
|
24
19
|
end
|
25
20
|
|
26
|
-
# Returns an escape sequence.
|
27
|
-
#
|
28
21
|
# @return [String]
|
29
|
-
def
|
30
|
-
|
22
|
+
def numbered_prefix
|
23
|
+
"\e[38;5;"
|
31
24
|
end
|
32
25
|
|
33
|
-
# Returns an escape sequence.
|
34
|
-
#
|
35
26
|
# @return [String]
|
36
|
-
def
|
37
|
-
|
38
|
-
sprintf("\e[38;2;%s;%s;%sm", *css_to_rgb)
|
39
|
-
|
40
|
-
else
|
41
|
-
numbered
|
42
|
-
|
43
|
-
end
|
27
|
+
def rgb_prefix
|
28
|
+
"\e[38;2;%s;%s;%sm"
|
44
29
|
end
|
45
30
|
|
46
31
|
end # Foreground
|
@@ -12,12 +12,11 @@ module Vedeu
|
|
12
12
|
# @return [Vedeu::HTMLRenderer]
|
13
13
|
def initialize(output)
|
14
14
|
@output = output
|
15
|
-
@object = self
|
16
15
|
end
|
17
16
|
|
18
17
|
# @return [String]
|
19
18
|
def render
|
20
|
-
|
19
|
+
Template.parse(self, template)
|
21
20
|
end
|
22
21
|
|
23
22
|
# @param path [String]
|
@@ -48,8 +47,8 @@ module Vedeu
|
|
48
47
|
|
49
48
|
attr_reader :output
|
50
49
|
|
51
|
-
def
|
52
|
-
|
50
|
+
def template
|
51
|
+
File.dirname(__FILE__) + '/templates/html_renderer.vedeu'
|
53
52
|
end
|
54
53
|
|
55
54
|
# @return [String]
|
@@ -62,11 +61,6 @@ module Vedeu
|
|
62
61
|
@timestamp ||= Time.now.to_i
|
63
62
|
end
|
64
63
|
|
65
|
-
# @return [String]
|
66
|
-
def read(filename)
|
67
|
-
File.read(File.dirname(__FILE__) + '/templates/' + filename)
|
68
|
-
end
|
69
|
-
|
70
64
|
end # HTMLRenderer
|
71
65
|
|
72
66
|
end # Vedeu
|
data/lib/vedeu/output/output.rb
CHANGED
@@ -73,8 +73,8 @@ module Vedeu
|
|
73
73
|
viewport.each_with_index do |line, iy|
|
74
74
|
row = []
|
75
75
|
line.each_with_index do |char, ix|
|
76
|
-
row << if char.is_a?(Vedeu::Char)
|
77
|
-
char.position =
|
76
|
+
row << if char.is_a?(Vedeu::Char) && char.position.nil?
|
77
|
+
char.position = origin(iy, ix)
|
78
78
|
char
|
79
79
|
|
80
80
|
else
|
@@ -89,14 +89,7 @@ module Vedeu
|
|
89
89
|
|
90
90
|
# @return [void]
|
91
91
|
def viewport
|
92
|
-
@
|
93
|
-
end
|
94
|
-
|
95
|
-
# @param iy [Fixnum]
|
96
|
-
# @param ix [Fixnum]
|
97
|
-
# @return [Vedeu::Position]
|
98
|
-
def position(iy, ix)
|
99
|
-
interface.origin(iy, ix)
|
92
|
+
@viewport ||= Vedeu::Viewport.new(interface).render
|
100
93
|
end
|
101
94
|
|
102
95
|
# @param value [String]
|
@@ -107,7 +100,41 @@ module Vedeu
|
|
107
100
|
Vedeu::Char.new({ value: value,
|
108
101
|
colour: interface.colour,
|
109
102
|
style: interface.style,
|
110
|
-
position:
|
103
|
+
position: origin(iy, ix) })
|
104
|
+
end
|
105
|
+
|
106
|
+
# Returns the position of the cursor at the top-left coordinate, relative to
|
107
|
+
# the interface's position.
|
108
|
+
#
|
109
|
+
# @param y_index [Fixnum]
|
110
|
+
# @param x_index [Fixnum]
|
111
|
+
# @return [Vedeu::Position]
|
112
|
+
def origin(y_index = 0, x_index = 0)
|
113
|
+
Vedeu::Position.new(virtual_y[y_index], virtual_x[x_index])
|
114
|
+
end
|
115
|
+
|
116
|
+
# Provides a virtual y position within the interface's dimensions.
|
117
|
+
#
|
118
|
+
# @example
|
119
|
+
# # top = 3
|
120
|
+
# # bottom = 6
|
121
|
+
# # virtual_y # => [3, 4, 5]
|
122
|
+
#
|
123
|
+
# @return [Array]
|
124
|
+
def virtual_y
|
125
|
+
@virtual_y ||= (interface.top...interface.bottom).to_a
|
126
|
+
end
|
127
|
+
|
128
|
+
# Provides a virtual x position within the interface's dimensions.
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# # left = 9
|
132
|
+
# # right = 13
|
133
|
+
# # virtual_x # => [9, 10, 11, 12]
|
134
|
+
#
|
135
|
+
# @return [Array]
|
136
|
+
def virtual_x
|
137
|
+
@virtual_x ||= (interface.left...interface.right).to_a
|
111
138
|
end
|
112
139
|
|
113
140
|
end # Output
|
data/lib/vedeu/output/style.rb
CHANGED
@@ -38,7 +38,7 @@ module Vedeu
|
|
38
38
|
def to_s
|
39
39
|
return '' unless defined_value?(value)
|
40
40
|
|
41
|
-
@
|
41
|
+
@sequences ||= Array(value).flatten.map { |v| Esc.string(v) }.join
|
42
42
|
end
|
43
43
|
alias_method :escape_sequences, :to_s
|
44
44
|
|
@@ -91,11 +91,14 @@ module Vedeu
|
|
91
91
|
colour.is_a?(Symbol) && valid_name?
|
92
92
|
end
|
93
93
|
|
94
|
-
#
|
95
|
-
#
|
96
|
-
# @
|
94
|
+
# Returns an escape sequence for a named background colour.
|
95
|
+
#
|
96
|
+
# @note
|
97
|
+
# Valid names can be found at {Vedeu::Esc#codes}
|
98
|
+
#
|
99
|
+
# @return [String]
|
97
100
|
def named
|
98
|
-
|
101
|
+
["\e[", named_codes, 'm'].join
|
99
102
|
end
|
100
103
|
|
101
104
|
# Returns a boolean indicating whether the colour provided is a valid named
|
@@ -114,11 +117,24 @@ module Vedeu
|
|
114
117
|
colour.is_a?(Fixnum) && valid_range?
|
115
118
|
end
|
116
119
|
|
117
|
-
#
|
118
|
-
#
|
119
|
-
# @return [
|
120
|
+
# Returns an escape sequence.
|
121
|
+
#
|
122
|
+
# @return [String]
|
120
123
|
def numbered
|
121
|
-
|
124
|
+
[numbered_prefix, css_to_numbered, 'm'].join
|
125
|
+
end
|
126
|
+
|
127
|
+
# Returns an escape sequence.
|
128
|
+
#
|
129
|
+
# @return [String]
|
130
|
+
def rgb
|
131
|
+
if Configuration.colour_mode == 16777216
|
132
|
+
sprintf(rgb_prefix, *css_to_rgb)
|
133
|
+
|
134
|
+
else
|
135
|
+
numbered
|
136
|
+
|
137
|
+
end
|
122
138
|
end
|
123
139
|
|
124
140
|
# Returns a boolean indicating whether the numbered colour is within the
|
@@ -136,13 +152,6 @@ module Vedeu
|
|
136
152
|
colour.is_a?(String) && valid_rgb?
|
137
153
|
end
|
138
154
|
|
139
|
-
# @raise [NotImplemented] Subclasses of this class must implement this
|
140
|
-
# method.
|
141
|
-
# @return [NotImplemented]
|
142
|
-
def rgb
|
143
|
-
fail NotImplemented, 'Subclasses implement this.'
|
144
|
-
end
|
145
|
-
|
146
155
|
# Returns a boolean indicated whether the colour is a valid HTML/CSS colour.
|
147
156
|
#
|
148
157
|
# @return [Boolean]
|
@@ -201,6 +210,27 @@ module Vedeu
|
|
201
210
|
(css_to_rgb[2] / 51) * 1
|
202
211
|
end
|
203
212
|
|
213
|
+
# @raise [NotImplemented] Subclasses of this class must implement this
|
214
|
+
# method.
|
215
|
+
# @return [Exception]
|
216
|
+
def named_codes
|
217
|
+
fail NotImplemented, 'Subclasses implement this.'
|
218
|
+
end
|
219
|
+
|
220
|
+
# @raise [NotImplemented] Subclasses of this class must implement this
|
221
|
+
# method.
|
222
|
+
# @return [NotImplemented]
|
223
|
+
def numbered_prefix
|
224
|
+
fail NotImplemented, 'Subclasses implement this.'
|
225
|
+
end
|
226
|
+
|
227
|
+
# @raise [NotImplemented] Subclasses of this class must implement this
|
228
|
+
# method.
|
229
|
+
# @return [NotImplemented]
|
230
|
+
def rgb_prefix
|
231
|
+
fail NotImplemented, 'Subclasses implement this.'
|
232
|
+
end
|
233
|
+
|
204
234
|
end # Translator
|
205
235
|
|
206
236
|
end # Vedeu
|
@@ -31,7 +31,7 @@ module Vedeu
|
|
31
31
|
#
|
32
32
|
# @return [Array]
|
33
33
|
def clear
|
34
|
-
@
|
34
|
+
@storage = in_memory
|
35
35
|
end
|
36
36
|
alias_method :reset, :clear
|
37
37
|
|
@@ -41,7 +41,7 @@ module Vedeu
|
|
41
41
|
#
|
42
42
|
# @return [Array]
|
43
43
|
def storage
|
44
|
-
@
|
44
|
+
@storage ||= in_memory
|
45
45
|
end
|
46
46
|
|
47
47
|
# Returns an empty collection ready for the storing of virtual buffers.
|
@@ -9,7 +9,7 @@ module Vedeu
|
|
9
9
|
|
10
10
|
# @return [Vedeu::Borders]
|
11
11
|
def self.borders
|
12
|
-
@
|
12
|
+
@borders ||= Vedeu::Borders.new(Vedeu::Border)
|
13
13
|
end
|
14
14
|
|
15
15
|
end # Borders
|
@@ -20,7 +20,7 @@ module Vedeu
|
|
20
20
|
|
21
21
|
# @return [Vedeu::Buffers]
|
22
22
|
def self.buffers
|
23
|
-
@
|
23
|
+
@buffers ||= Vedeu::Buffers.new(Vedeu::Buffer)
|
24
24
|
end
|
25
25
|
|
26
26
|
end # Buffers
|
@@ -31,7 +31,7 @@ module Vedeu
|
|
31
31
|
|
32
32
|
# @return [Vedeu::Cursors]
|
33
33
|
def self.cursors
|
34
|
-
@
|
34
|
+
@cursors ||= Vedeu::Cursors.new(Vedeu::Cursor)
|
35
35
|
end
|
36
36
|
|
37
37
|
# @return [Vedeu::Cursor]
|
@@ -47,7 +47,7 @@ module Vedeu
|
|
47
47
|
|
48
48
|
# @return [Vedeu::Events]
|
49
49
|
def self.events
|
50
|
-
@
|
50
|
+
@events ||= Vedeu::Events.new(Vedeu::Model::Collection)
|
51
51
|
end
|
52
52
|
|
53
53
|
end # Events
|
@@ -59,7 +59,7 @@ module Vedeu
|
|
59
59
|
|
60
60
|
# @return [Vedeu::Geometries]
|
61
61
|
def self.geometries
|
62
|
-
@
|
62
|
+
@geometries ||= Vedeu::Geometries.new(Vedeu::Geometry)
|
63
63
|
end
|
64
64
|
|
65
65
|
end # Geometries
|
@@ -70,7 +70,7 @@ module Vedeu
|
|
70
70
|
|
71
71
|
# @return [Vedeu::Groups]
|
72
72
|
def self.groups
|
73
|
-
@
|
73
|
+
@groups ||= Vedeu::Groups.new(Vedeu::Group)
|
74
74
|
end
|
75
75
|
|
76
76
|
end # Groups
|
@@ -81,7 +81,7 @@ module Vedeu
|
|
81
81
|
|
82
82
|
# @return [Vedeu::InterfacesRepository]
|
83
83
|
def self.interfaces
|
84
|
-
@
|
84
|
+
@interfaces ||= Vedeu::InterfacesRepository.new(Vedeu::Interface)
|
85
85
|
end
|
86
86
|
|
87
87
|
end # InterfacesRepository
|
@@ -92,7 +92,7 @@ module Vedeu
|
|
92
92
|
|
93
93
|
# @return [Vedeu::Keymaps]
|
94
94
|
def self.keymaps
|
95
|
-
@
|
95
|
+
@keymaps ||= Vedeu::Keymaps.new(Vedeu::Keymap)
|
96
96
|
end
|
97
97
|
|
98
98
|
end # Keymaps
|
@@ -103,7 +103,7 @@ module Vedeu
|
|
103
103
|
|
104
104
|
# @return [Vedeu::Menus]
|
105
105
|
def self.menus
|
106
|
-
@
|
106
|
+
@menus ||= Vedeu::Menus.new(Vedeu::Menu)
|
107
107
|
end
|
108
108
|
|
109
109
|
end # Menus
|
data/lib/vedeu/support/all.rb
CHANGED
@@ -1,18 +1,12 @@
|
|
1
|
-
require 'vedeu/support/bounding_area'
|
2
1
|
require 'vedeu/support/coercions'
|
3
2
|
require 'vedeu/support/common'
|
4
3
|
require 'vedeu/support/console'
|
5
|
-
require 'vedeu/support/content_geometry'
|
6
|
-
require 'vedeu/support/coordinate'
|
7
4
|
require 'vedeu/support/esc'
|
8
|
-
require 'vedeu/support/grid'
|
9
|
-
require 'vedeu/support/limit'
|
10
5
|
require 'vedeu/support/log'
|
11
|
-
require 'vedeu/support/position'
|
12
|
-
require 'vedeu/support/position_validator'
|
13
6
|
require 'vedeu/support/read'
|
14
7
|
require 'vedeu/support/refresh'
|
15
8
|
require 'vedeu/support/sentence'
|
9
|
+
require 'vedeu/support/template'
|
16
10
|
require 'vedeu/support/terminal'
|
17
11
|
require 'vedeu/support/text'
|
18
12
|
require 'vedeu/support/trace'
|
data/lib/vedeu/support/esc.rb
CHANGED
@@ -9,7 +9,38 @@ module Vedeu
|
|
9
9
|
|
10
10
|
extend self
|
11
11
|
|
12
|
-
# Produces the foreground named colour escape sequence hash.
|
12
|
+
# Produces the foreground named colour escape sequence hash. The background
|
13
|
+
# escape sequences are also generated from this by adding 10 to the values.
|
14
|
+
# This hash gives rise to methods you can call directly on `Esc` to produce
|
15
|
+
# the desired colours:
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# Esc.red # => "\e[31m"
|
19
|
+
#
|
20
|
+
# Esc.red { 'some text' } # => "\e[31msome text\e[39m"
|
21
|
+
#
|
22
|
+
# Esc.on_blue # => "\e[44m"
|
23
|
+
#
|
24
|
+
# Esc.on_blue { 'some text' } # => "\e[44msome text\e[49m"
|
25
|
+
#
|
26
|
+
# # Valid names:
|
27
|
+
# :black
|
28
|
+
# :red
|
29
|
+
# :green
|
30
|
+
# :yellow
|
31
|
+
# :blue
|
32
|
+
# :magenta
|
33
|
+
# :cyan
|
34
|
+
# :light_grey
|
35
|
+
# :default
|
36
|
+
# :dark_grey
|
37
|
+
# :light_red
|
38
|
+
# :light_green
|
39
|
+
# :light_yellow
|
40
|
+
# :light_blue
|
41
|
+
# :light_magenta
|
42
|
+
# :light_cyan
|
43
|
+
# :white
|
13
44
|
#
|
14
45
|
# @return [Hash]
|
15
46
|
def codes
|
@@ -40,21 +71,12 @@ module Vedeu
|
|
40
71
|
#
|
41
72
|
# @return [Hash]
|
42
73
|
def background_codes
|
43
|
-
Esc.codes.inject({}) { |h, (k, v)| h.merge(k => v + 10) }
|
74
|
+
Esc.codes.inject({}) { |h, (k, v)| h.merge!(k => v + 10) }
|
44
75
|
end
|
45
76
|
|
46
77
|
# Dynamically creates methods for each terminal named colour. When a block
|
47
78
|
# is given, then the colour is reset to 'default' once the block is called.
|
48
79
|
#
|
49
|
-
# @example
|
50
|
-
# Esc.red # => "\e[31m"
|
51
|
-
#
|
52
|
-
# Esc.red { 'some text' } # => "\e[31msome text\e[39m"
|
53
|
-
#
|
54
|
-
# Esc.on_blue # => "\e[44m"
|
55
|
-
#
|
56
|
-
# Esc.on_blue { 'some text' } # => "\e[44msome text\e[49m"
|
57
|
-
#
|
58
80
|
# @return [String]
|
59
81
|
foreground_codes.each do |key, code|
|
60
82
|
define_method(key) do |&blk|
|