vedeu 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/vedeu +0 -3
- data/examples/borders_app.rb +0 -3
- data/examples/colours_app.rb +0 -3
- data/examples/configuration_app.rb +0 -3
- data/examples/cursor_app.rb +0 -3
- data/examples/focus_app.rb +0 -3
- data/examples/geometry_app.rb +0 -3
- data/examples/lines_app.rb +0 -3
- data/examples/view_templates_app/template.erb +1 -0
- data/examples/view_templates_app/view_templates_app.rb +82 -0
- data/lib/vedeu/all.rb +0 -1
- data/lib/vedeu/application.rb +7 -6
- data/lib/vedeu/bindings.rb +8 -8
- data/lib/vedeu/buffers/buffer.rb +14 -4
- data/lib/vedeu/buffers/display_buffer.rb +2 -2
- data/lib/vedeu/configuration/cli.rb +7 -1
- data/lib/vedeu/configuration/configuration.rb +4 -2
- data/lib/vedeu/cursor/all.rb +1 -1
- data/lib/vedeu/cursor/cursor.rb +29 -2
- data/lib/vedeu/cursor/move_cursor.rb +20 -6
- data/lib/vedeu/cursor/toggle_cursor.rb +2 -0
- data/lib/vedeu/distributed/client.rb +2 -0
- data/lib/vedeu/distributed/server.rb +3 -1
- data/lib/vedeu/distributed/subprocess.rb +6 -1
- data/lib/vedeu/distributed/test_application.rb +32 -9
- data/lib/vedeu/distributed/uri.rb +7 -1
- data/lib/vedeu/dsl/components/border.rb +2 -0
- data/lib/vedeu/dsl/components/geometry.rb +2 -0
- data/lib/vedeu/dsl/components/keymap.rb +2 -0
- data/lib/vedeu/dsl/components/menu.rb +3 -1
- data/lib/vedeu/dsl/composition.rb +31 -2
- data/lib/vedeu/dsl/group.rb +2 -0
- data/lib/vedeu/dsl/interface.rb +3 -1
- data/lib/vedeu/dsl/line.rb +2 -0
- data/lib/vedeu/dsl/shared/style.rb +1 -1
- data/lib/vedeu/dsl/shared/text.rb +1 -2
- data/lib/vedeu/dsl/stream.rb +2 -0
- data/lib/vedeu/dsl/view.rb +1 -1
- data/lib/vedeu/events/all.rb +1 -1
- data/lib/vedeu/events/event.rb +26 -10
- data/lib/vedeu/events/trigger.rb +11 -3
- data/lib/vedeu/geometry/all.rb +2 -0
- data/lib/vedeu/geometry/bounding_area.rb +7 -2
- data/lib/vedeu/geometry/content_geometry.rb +2 -0
- data/lib/vedeu/geometry/coordinate.rb +15 -6
- data/lib/vedeu/geometry/grid.rb +3 -1
- data/lib/vedeu/geometry/index_position.rb +77 -0
- data/lib/vedeu/geometry/limit.rb +15 -1
- data/lib/vedeu/geometry/position.rb +7 -2
- data/lib/vedeu/{output → geometry}/position_index.rb +12 -2
- data/lib/vedeu/geometry/position_validator.rb +9 -1
- data/lib/vedeu/input/all.rb +0 -1
- data/lib/vedeu/input/input.rb +2 -0
- data/lib/vedeu/input/keymap.rb +5 -3
- data/lib/vedeu/input/mapper.rb +7 -1
- data/lib/vedeu/launcher.rb +1 -1
- data/lib/vedeu/models/all.rb +6 -3
- data/lib/vedeu/models/char.rb +157 -0
- data/lib/vedeu/models/{view/composition.rb → composition.rb} +1 -4
- data/lib/vedeu/models/geometry.rb +36 -12
- data/lib/vedeu/models/group.rb +7 -3
- data/lib/vedeu/models/{view/interface.rb → interface.rb} +26 -10
- data/lib/vedeu/models/{view/line.rb → line.rb} +8 -4
- data/lib/vedeu/models/menu.rb +11 -3
- data/lib/vedeu/models/{view/stream.rb → stream.rb} +9 -4
- data/lib/vedeu/output/all.rb +3 -2
- data/lib/vedeu/output/background.rb +2 -2
- data/lib/vedeu/output/border.rb +65 -22
- data/lib/vedeu/output/char_builder.rb +36 -0
- data/lib/vedeu/output/clear.rb +62 -0
- data/lib/vedeu/output/colour.rb +15 -7
- data/lib/vedeu/output/compositor.rb +3 -1
- data/lib/vedeu/output/esc.rb +2 -2
- data/lib/vedeu/output/foreground.rb +2 -2
- data/lib/vedeu/output/html_char.rb +2 -0
- data/lib/vedeu/output/html_renderer.rb +6 -3
- data/lib/vedeu/output/output.rb +20 -92
- data/lib/vedeu/output/presentation.rb +21 -21
- data/lib/vedeu/output/renderer.rb +2 -0
- data/lib/vedeu/output/style.rb +4 -2
- data/lib/vedeu/output/text.rb +7 -1
- data/lib/vedeu/output/translator.rb +4 -2
- data/lib/vedeu/output/viewport.rb +4 -2
- data/lib/vedeu/output/virtual_buffer.rb +11 -1
- data/lib/vedeu/output/virtual_terminal.rb +34 -11
- data/lib/vedeu/output/wordwrap.rb +31 -20
- data/lib/vedeu/repositories/all.rb +3 -0
- data/lib/vedeu/repositories/collection.rb +83 -0
- data/lib/vedeu/repositories/collections.rb +35 -0
- data/lib/vedeu/{models → repositories}/model.rb +2 -0
- data/lib/vedeu/repositories/repository.rb +7 -1
- data/lib/vedeu/support/log.rb +1 -1
- data/lib/vedeu/support/sentence.rb +7 -1
- data/lib/vedeu/support/template.rb +14 -2
- data/lib/vedeu/support/terminal.rb +6 -6
- data/lib/vedeu/support/trace.rb +4 -4
- data/lib/vedeu/support/visible.rb +4 -4
- data/test/lib/vedeu/dsl/composition_test.rb +23 -0
- data/test/lib/vedeu/geometry/index_position_test.rb +121 -0
- data/test/lib/vedeu/{output → geometry}/position_index_test.rb +6 -0
- data/test/lib/vedeu/input/keymap_test.rb +2 -2
- data/test/lib/vedeu/models/{view/char_test.rb → char_test.rb} +31 -15
- data/test/lib/vedeu/models/{view/composition_test.rb → composition_test.rb} +0 -0
- data/test/lib/vedeu/models/{view/interface_test.rb → interface_test.rb} +0 -0
- data/test/lib/vedeu/models/line_test.rb +156 -0
- data/test/lib/vedeu/models/{view/stream_test.rb → stream_test.rb} +1 -16
- data/test/lib/vedeu/output/char_builder_test.rb +50 -0
- data/test/lib/vedeu/output/clear_test.rb +26 -0
- data/test/lib/vedeu/output/compositor_test.rb +0 -10
- data/test/lib/vedeu/output/html_renderer_test.rb +8 -3
- data/test/lib/vedeu/output/output_test.rb +0 -39
- data/test/lib/vedeu/output/viewport_test.rb +10 -66
- data/test/lib/vedeu/output/virtual_buffer_test.rb +18 -2
- data/test/lib/vedeu/output/virtual_terminal_test.rb +3 -14
- data/test/lib/vedeu/output/wordwrap_test.rb +8 -15
- data/test/lib/vedeu/repositories/collection_test.rb +108 -0
- data/test/lib/vedeu/repositories/collections_test.rb +71 -0
- data/test/lib/vedeu/{models → repositories}/model_test.rb +0 -0
- data/test/lib/vedeu/support/template_test.rb +21 -1
- data/test/support/helpers/model_test_class.rb +1 -1
- data/test/test_helper.rb +0 -1
- data/vedeu.gemspec +1 -1
- metadata +40 -44
- data/lib/vedeu/events/events.rb +0 -10
- data/lib/vedeu/input/keys.rb +0 -10
- data/lib/vedeu/models/collection.rb +0 -81
- data/lib/vedeu/models/view/all.rb +0 -12
- data/lib/vedeu/models/view/char.rb +0 -99
- data/lib/vedeu/models/view/chars.rb +0 -10
- data/lib/vedeu/models/view/interfaces.rb +0 -10
- data/lib/vedeu/models/view/lines.rb +0 -10
- data/lib/vedeu/models/view/streams.rb +0 -10
- data/lib/vedeu/output/index_position.rb +0 -35
- data/test/lib/vedeu/models/collection_test.rb +0 -112
- data/test/lib/vedeu/models/view/chars_test.rb +0 -16
- data/test/lib/vedeu/models/view/interfaces_test.rb +0 -16
- data/test/lib/vedeu/models/view/line_test.rb +0 -214
- data/test/lib/vedeu/models/view/lines_test.rb +0 -16
- data/test/lib/vedeu/models/view/streams_test.rb +0 -16
- data/test/lib/vedeu/output/index_position_test.rb +0 -64
@@ -0,0 +1,62 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Clears the area defined by an interface.
|
4
|
+
#
|
5
|
+
class Clear
|
6
|
+
|
7
|
+
include Vedeu::CharBuilder
|
8
|
+
|
9
|
+
# Clears the area defined by the interface.
|
10
|
+
#
|
11
|
+
# @return [Array|String]
|
12
|
+
# @see #initialize
|
13
|
+
def self.clear(interface)
|
14
|
+
new(interface).write
|
15
|
+
end
|
16
|
+
|
17
|
+
# Return a new instance of Output.
|
18
|
+
#
|
19
|
+
# @param interface [Interface]
|
20
|
+
# @return [Output]
|
21
|
+
def initialize(interface)
|
22
|
+
@interface = interface
|
23
|
+
end
|
24
|
+
|
25
|
+
# For each visible line of the interface, set the foreground and background
|
26
|
+
# colours to those specified when the interface was defined, then starting
|
27
|
+
# write space characters over the area which the interface occupies.
|
28
|
+
#
|
29
|
+
# @return [Array<Array<Vedeu::Char>>]
|
30
|
+
def clear
|
31
|
+
out = interface.height.times.inject([]) do |row, iy|
|
32
|
+
row << interface.width.times.inject([]) do |column, ix|
|
33
|
+
column << char_builder(' ', iy, ix)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Clear the view and send to the terminal.
|
39
|
+
#
|
40
|
+
# @return [Array]
|
41
|
+
def write
|
42
|
+
Vedeu.log(type: :output, message: "Clearing: '#{interface.name}'")
|
43
|
+
|
44
|
+
if Vedeu::Configuration.drb?
|
45
|
+
Vedeu.trigger(:_drb_store_output_, clear)
|
46
|
+
|
47
|
+
Vedeu::HTMLRenderer.to_file(Vedeu::VirtualBuffer.retrieve)
|
48
|
+
end
|
49
|
+
|
50
|
+
Vedeu::Terminal.output(Vedeu::Renderer.render(clear))
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# @!attribute [r] interface
|
56
|
+
# @return [Interface]
|
57
|
+
attr_reader :interface
|
58
|
+
|
59
|
+
end # Clear
|
60
|
+
|
61
|
+
end # Vedeu
|
62
|
+
|
data/lib/vedeu/output/colour.rb
CHANGED
@@ -10,9 +10,17 @@ module Vedeu
|
|
10
10
|
|
11
11
|
include Vedeu::Coercions
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# @!attribute [r] attributes
|
14
|
+
# @return [Hash]
|
15
|
+
attr_reader :attributes
|
16
|
+
|
17
|
+
# @!attribute [r] background
|
18
|
+
# @return [Background|String]
|
19
|
+
attr_reader :background
|
20
|
+
|
21
|
+
# @!attribute [r] foreground
|
22
|
+
# @return [Foreground|String]
|
23
|
+
attr_reader :foreground
|
16
24
|
|
17
25
|
# Returns a new instance of Colour.
|
18
26
|
#
|
@@ -23,8 +31,8 @@ module Vedeu
|
|
23
31
|
def initialize(attributes = {})
|
24
32
|
@attributes = defaults.merge!(attributes)
|
25
33
|
|
26
|
-
@background = Background.coerce(@attributes[:background])
|
27
|
-
@foreground = Foreground.coerce(@attributes[:foreground])
|
34
|
+
@background = Vedeu::Background.coerce(@attributes[:background])
|
35
|
+
@foreground = Vedeu::Foreground.coerce(@attributes[:foreground])
|
28
36
|
end
|
29
37
|
|
30
38
|
# Converts the value into a Vedeu::Foreground.
|
@@ -32,7 +40,7 @@ module Vedeu
|
|
32
40
|
# @param value [String]
|
33
41
|
# @return [String]
|
34
42
|
def foreground=(value)
|
35
|
-
@foreground = Foreground.coerce(value)
|
43
|
+
@foreground = Vedeu::Foreground.coerce(value)
|
36
44
|
end
|
37
45
|
|
38
46
|
# Converts the value into a Vedeu::Background.
|
@@ -40,7 +48,7 @@ module Vedeu
|
|
40
48
|
# @param value [String]
|
41
49
|
# @return [String]
|
42
50
|
def background=(value)
|
43
|
-
@background = Background.coerce(value)
|
51
|
+
@background = Vedeu::Background.coerce(value)
|
44
52
|
end
|
45
53
|
|
46
54
|
# Returns both or either of the converted attributes into a single escape
|
@@ -34,12 +34,14 @@ module Vedeu
|
|
34
34
|
view.colour = interface.colour unless view.colour
|
35
35
|
view.style = interface.style unless view.style
|
36
36
|
|
37
|
-
Output.render(view)
|
37
|
+
Vedeu::Output.render(view)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
+
# @!attribute [r] name
|
44
|
+
# @return [String]
|
43
45
|
attr_reader :name
|
44
46
|
|
45
47
|
# @return [Vedeu::Interface]
|
data/lib/vedeu/output/esc.rb
CHANGED
@@ -69,7 +69,7 @@ module Vedeu
|
|
69
69
|
#
|
70
70
|
# @return [Hash]
|
71
71
|
def background_codes
|
72
|
-
Esc.codes.inject({}) { |h, (k, v)| h.merge!(k => v + 10) }
|
72
|
+
Vedeu::Esc.codes.inject({}) { |h, (k, v)| h.merge!(k => v + 10) }
|
73
73
|
end
|
74
74
|
|
75
75
|
# Dynamically creates methods for each terminal named colour. When a block
|
@@ -183,7 +183,7 @@ module Vedeu
|
|
183
183
|
|
184
184
|
# @return [String]
|
185
185
|
def clear_last_line
|
186
|
-
Vedeu::Position.new((Terminal.height - 1), 1).to_s { clear_line }
|
186
|
+
Vedeu::Position.new((Vedeu::Terminal.height - 1), 1).to_s { clear_line }
|
187
187
|
end
|
188
188
|
|
189
189
|
# @return [String]
|
@@ -7,13 +7,13 @@ module Vedeu
|
|
7
7
|
# The class represents one half (the other, can be found at
|
8
8
|
# {Vedeu::Background}) of a terminal colour escape sequence.
|
9
9
|
#
|
10
|
-
class Foreground < Translator
|
10
|
+
class Foreground < Vedeu::Translator
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
14
|
# @return [String]
|
15
15
|
def named_codes
|
16
|
-
Esc.foreground_codes[colour]
|
16
|
+
Vedeu::Esc.foreground_codes[colour]
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [String]
|
@@ -11,9 +11,10 @@ module Vedeu
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# @param output [Array<Array<Vedeu::Char>>]
|
14
|
+
# @param path [String]
|
14
15
|
# @return [String]
|
15
|
-
def self.to_file(output)
|
16
|
-
new(output).to_file
|
16
|
+
def self.to_file(output, path = nil)
|
17
|
+
new(output).to_file(path)
|
17
18
|
end
|
18
19
|
|
19
20
|
# @param output [Array<Array<Vedeu::Char>>]
|
@@ -24,7 +25,7 @@ module Vedeu
|
|
24
25
|
|
25
26
|
# @return [String]
|
26
27
|
def render
|
27
|
-
Template.parse(self, template)
|
28
|
+
Vedeu::Template.parse(self, template)
|
28
29
|
end
|
29
30
|
|
30
31
|
# Writes the parsed template to a file (at the given path) and returns the
|
@@ -56,6 +57,8 @@ module Vedeu
|
|
56
57
|
|
57
58
|
private
|
58
59
|
|
60
|
+
# @!attribute [r] output
|
61
|
+
# @return [Array<Array<Vedeu::Char>>]
|
59
62
|
attr_reader :output
|
60
63
|
|
61
64
|
# @return [String]
|
data/lib/vedeu/output/output.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
require 'vedeu/output/clear'
|
2
|
+
require 'vedeu/output/html_renderer'
|
3
|
+
require 'vedeu/output/renderer'
|
4
|
+
require 'vedeu/output/viewport'
|
5
|
+
require 'vedeu/output/virtual_buffer'
|
6
|
+
require 'vedeu/support/terminal'
|
7
|
+
|
1
8
|
module Vedeu
|
2
9
|
|
3
10
|
# Sends the interface to the terminal or output device.
|
4
11
|
#
|
5
12
|
class Output
|
6
13
|
|
7
|
-
|
8
|
-
#
|
9
|
-
# @return [Array|String]
|
10
|
-
# @see #initialize
|
11
|
-
def self.clear(interface)
|
12
|
-
new(interface).clear
|
13
|
-
end
|
14
|
+
include Vedeu::CharBuilder
|
14
15
|
|
15
16
|
# Writes content (the provided interface object with associated lines,
|
16
17
|
# streams, colours and styles) to the area defined by the interface.
|
@@ -29,19 +30,6 @@ module Vedeu
|
|
29
30
|
@interface = interface
|
30
31
|
end
|
31
32
|
|
32
|
-
# Clear the view and send to the terminal.
|
33
|
-
#
|
34
|
-
# @return [Array]
|
35
|
-
def clear
|
36
|
-
if Vedeu::Configuration.drb?
|
37
|
-
Vedeu.trigger(:_drb_store_output_, virtual_clear)
|
38
|
-
|
39
|
-
HTMLRenderer.to_file(VirtualBuffer.retrieve)
|
40
|
-
end
|
41
|
-
|
42
|
-
Terminal.output(Renderer.render(virtual_clear))
|
43
|
-
end
|
44
|
-
|
45
33
|
# Send the view to the terminal.
|
46
34
|
#
|
47
35
|
# @return [Array]
|
@@ -49,38 +37,18 @@ module Vedeu
|
|
49
37
|
if Vedeu::Configuration.drb?
|
50
38
|
Vedeu.trigger(:_drb_store_output_, virtual_view)
|
51
39
|
|
52
|
-
HTMLRenderer.to_file(VirtualBuffer.retrieve)
|
40
|
+
Vedeu::HTMLRenderer.to_file(Vedeu::VirtualBuffer.retrieve)
|
53
41
|
end
|
54
42
|
|
55
|
-
Terminal.output(Renderer.render(virtual_view, interface.cursor))
|
43
|
+
Vedeu::Terminal.output(Vedeu::Renderer.render(virtual_view, interface.cursor))
|
56
44
|
end
|
57
45
|
|
58
46
|
private
|
59
47
|
|
48
|
+
# @!attribute [r] interface
|
49
|
+
# @return [Interface]
|
60
50
|
attr_reader :interface
|
61
51
|
|
62
|
-
# For each visible line of the interface, set the foreground and background
|
63
|
-
# colours to those specified when the interface was defined, then starting
|
64
|
-
# write space characters over the area which the interface occupies.
|
65
|
-
#
|
66
|
-
# @note
|
67
|
-
# omg!
|
68
|
-
#
|
69
|
-
# @return [Array<Array<Vedeu::Char>>]
|
70
|
-
def virtual_clear
|
71
|
-
Vedeu.log(type: :output, message: "Clearing: '#{interface.name}'")
|
72
|
-
|
73
|
-
out = []
|
74
|
-
interface.height.times do |iy|
|
75
|
-
row = []
|
76
|
-
interface.width.times do |ix|
|
77
|
-
row << char_builder(' ', iy, ix)
|
78
|
-
end
|
79
|
-
out << row
|
80
|
-
end
|
81
|
-
out
|
82
|
-
end
|
83
|
-
|
84
52
|
# Builds up a virtual view; a grid of Vedeu::Char objects- each one holding
|
85
53
|
# one character along with its colour, style and position attributes.
|
86
54
|
#
|
@@ -89,19 +57,19 @@ module Vedeu
|
|
89
57
|
#
|
90
58
|
# @return [Array<Array<Vedeu::Char>>]
|
91
59
|
def virtual_view
|
92
|
-
out = [
|
60
|
+
out = [ clear_area_first! ]
|
93
61
|
|
94
62
|
Vedeu.log(type: :output, message: "Rendering: '#{interface.name}'")
|
95
63
|
|
96
64
|
viewport.each_with_index do |line, iy|
|
97
65
|
row = []
|
98
66
|
line.each_with_index do |char, ix|
|
99
|
-
row << if char.
|
67
|
+
row << if char.x != ix || char.y != iy
|
100
68
|
char.position = origin(iy, ix)
|
101
69
|
char
|
102
70
|
|
103
71
|
else
|
104
|
-
|
72
|
+
char
|
105
73
|
|
106
74
|
end
|
107
75
|
end
|
@@ -110,56 +78,16 @@ module Vedeu
|
|
110
78
|
out
|
111
79
|
end
|
112
80
|
|
81
|
+
# @return [Array<Array<Vedeu::Char>>]
|
82
|
+
def clear_area_first!
|
83
|
+
Vedeu::Clear.new(interface).clear
|
84
|
+
end
|
85
|
+
|
113
86
|
# @return [void]
|
114
87
|
def viewport
|
115
88
|
@viewport ||= Vedeu::Viewport.new(interface).render
|
116
89
|
end
|
117
90
|
|
118
|
-
# @param value [String]
|
119
|
-
# @param iy [Fixnum]
|
120
|
-
# @param ix [Fixnum]
|
121
|
-
# @return [Vedeu::Char]
|
122
|
-
def char_builder(value, iy, ix)
|
123
|
-
Vedeu::Char.new({ value: value,
|
124
|
-
colour: interface.colour,
|
125
|
-
style: interface.style,
|
126
|
-
position: origin(iy, ix) })
|
127
|
-
end
|
128
|
-
|
129
|
-
# Returns the position of the cursor at the top-left coordinate, relative to
|
130
|
-
# the interface's position.
|
131
|
-
#
|
132
|
-
# @param y_index [Fixnum]
|
133
|
-
# @param x_index [Fixnum]
|
134
|
-
# @return [Vedeu::Position]
|
135
|
-
def origin(y_index = 0, x_index = 0)
|
136
|
-
Vedeu::Position.new(virtual_y[y_index], virtual_x[x_index])
|
137
|
-
end
|
138
|
-
|
139
|
-
# Provides a virtual y position within the interface's dimensions.
|
140
|
-
#
|
141
|
-
# @example
|
142
|
-
# # top = 3
|
143
|
-
# # bottom = 6
|
144
|
-
# # virtual_y # => [3, 4, 5]
|
145
|
-
#
|
146
|
-
# @return [Array]
|
147
|
-
def virtual_y
|
148
|
-
@virtual_y ||= (interface.top...interface.bottom).to_a
|
149
|
-
end
|
150
|
-
|
151
|
-
# Provides a virtual x position within the interface's dimensions.
|
152
|
-
#
|
153
|
-
# @example
|
154
|
-
# # left = 9
|
155
|
-
# # right = 13
|
156
|
-
# # virtual_x # => [9, 10, 11, 12]
|
157
|
-
#
|
158
|
-
# @return [Array]
|
159
|
-
def virtual_x
|
160
|
-
@virtual_x ||= (interface.left...interface.right).to_a
|
161
|
-
end
|
162
|
-
|
163
91
|
end # Output
|
164
92
|
|
165
93
|
end # Vedeu
|
@@ -12,6 +12,16 @@ module Vedeu
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
# @return [Vedeu::Colour]
|
16
|
+
def colour
|
17
|
+
@colour ||= Vedeu::Colour.coerce(@colour)
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Vedeu::Colour]
|
21
|
+
def colour=(value)
|
22
|
+
@colour = Vedeu::Colour.coerce(value)
|
23
|
+
end
|
24
|
+
|
15
25
|
# @return [Vedeu::Foreground|NilClass]
|
16
26
|
def foreground
|
17
27
|
if colour
|
@@ -26,6 +36,11 @@ module Vedeu
|
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
39
|
+
# @return [String|NilClass]
|
40
|
+
def parent_colour
|
41
|
+
parent.colour if parent
|
42
|
+
end
|
43
|
+
|
29
44
|
# @return [Vedeu::Foreground|NilClass]
|
30
45
|
def parent_foreground
|
31
46
|
if parent_colour
|
@@ -33,19 +48,14 @@ module Vedeu
|
|
33
48
|
end
|
34
49
|
end
|
35
50
|
|
36
|
-
# @return [
|
37
|
-
def
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
# @return [Vedeu::Colour]
|
42
|
-
def colour=(value)
|
43
|
-
@colour = Vedeu::Colour.coerce(value)
|
51
|
+
# @return [String|NilClass]
|
52
|
+
def parent_style
|
53
|
+
parent.style if parent
|
44
54
|
end
|
45
55
|
|
46
56
|
# @return [Vedeu::Style]
|
47
57
|
def style
|
48
|
-
Vedeu::Style.coerce(@style)
|
58
|
+
@style ||= Vedeu::Style.coerce(@style)
|
49
59
|
end
|
50
60
|
|
51
61
|
# @return [Vedeu::Style]
|
@@ -64,20 +74,10 @@ module Vedeu
|
|
64
74
|
|
65
75
|
private
|
66
76
|
|
67
|
-
# @return [String|NilClass]
|
68
|
-
def parent_colour
|
69
|
-
parent.colour if parent
|
70
|
-
end
|
71
|
-
|
72
|
-
# @return [String|NilClass]
|
73
|
-
def parent_style
|
74
|
-
parent.style if parent
|
75
|
-
end
|
76
|
-
|
77
77
|
# @return [String]
|
78
78
|
def render_border
|
79
79
|
if self.respond_to?(:border) && !border.nil?
|
80
|
-
Esc.border { yield }
|
80
|
+
Vedeu::Esc.border { yield }
|
81
81
|
|
82
82
|
else
|
83
83
|
yield
|
@@ -100,7 +100,7 @@ module Vedeu
|
|
100
100
|
|
101
101
|
# @return [String]
|
102
102
|
def render_position
|
103
|
-
if self.respond_to?(:position) && position.is_a?(Position)
|
103
|
+
if self.respond_to?(:position) && self.position.is_a?(Vedeu::Position)
|
104
104
|
position.to_s { yield }
|
105
105
|
|
106
106
|
else
|
data/lib/vedeu/output/style.rb
CHANGED
@@ -11,9 +11,11 @@ module Vedeu
|
|
11
11
|
include Vedeu::Common
|
12
12
|
include Vedeu::Coercions
|
13
13
|
|
14
|
+
# @!attribute [rw] value
|
15
|
+
# @return [String|Symbol]
|
14
16
|
attr_accessor :value
|
15
17
|
|
16
|
-
# Return a new instance of Style.
|
18
|
+
# Return a new instance of Vedeu::Style.
|
17
19
|
#
|
18
20
|
# @param value [Array|Array<String>|Array<Symbol>|String|Symbol]
|
19
21
|
# The style value or a collection of values.
|
@@ -37,7 +39,7 @@ module Vedeu
|
|
37
39
|
def to_s
|
38
40
|
return '' unless defined_value?(value)
|
39
41
|
|
40
|
-
@sequences ||= Array(value).flatten.map { |v| Esc.string(v) }.join
|
42
|
+
@sequences ||= Array(value).flatten.map { |v| Vedeu::Esc.string(v) }.join
|
41
43
|
end
|
42
44
|
alias_method :escape_sequences, :to_s
|
43
45
|
|
data/lib/vedeu/output/text.rb
CHANGED
@@ -41,7 +41,13 @@ module Vedeu
|
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
-
|
44
|
+
# @!attribute [r] value
|
45
|
+
# @return [String]
|
46
|
+
attr_reader :value
|
47
|
+
|
48
|
+
# @!attribute [r] options
|
49
|
+
# @return [Hash]
|
50
|
+
attr_reader :options
|
45
51
|
|
46
52
|
# @return [Symbol] One of :align, :centre, :center, :left, :right, :text
|
47
53
|
def anchor
|
@@ -25,6 +25,8 @@ module Vedeu
|
|
25
25
|
|
26
26
|
include Vedeu::Coercions
|
27
27
|
|
28
|
+
# @!attribute [r] colour
|
29
|
+
# @return [String]
|
28
30
|
attr_reader :colour
|
29
31
|
alias_method :value, :colour
|
30
32
|
|
@@ -104,7 +106,7 @@ module Vedeu
|
|
104
106
|
#
|
105
107
|
# @return [Boolean]
|
106
108
|
def valid_name?
|
107
|
-
Esc.codes.keys.include?(colour)
|
109
|
+
Vedeu::Esc.codes.keys.include?(colour)
|
108
110
|
end
|
109
111
|
|
110
112
|
# Returns a boolean indicating whether the colour provided is a terminal
|
@@ -140,7 +142,7 @@ module Vedeu
|
|
140
142
|
#
|
141
143
|
# @return [String]
|
142
144
|
def rgb
|
143
|
-
if Configuration.colour_mode == 16777216
|
145
|
+
if Vedeu::Configuration.colour_mode == 16777216
|
144
146
|
sprintf(rgb_prefix, *css_to_rgb)
|
145
147
|
|
146
148
|
else
|
@@ -65,6 +65,8 @@ module Vedeu
|
|
65
65
|
|
66
66
|
private
|
67
67
|
|
68
|
+
# @!attribute [r] interface
|
69
|
+
# @return [Vedeu::Interface]
|
68
70
|
attr_reader :interface
|
69
71
|
|
70
72
|
# Returns the visible content for the interface.
|
@@ -78,7 +80,7 @@ module Vedeu
|
|
78
80
|
def show
|
79
81
|
return [] unless lines?
|
80
82
|
|
81
|
-
padded_lines.map { |line| padded_columns(line) }
|
83
|
+
padded_lines.map { |line| padded_columns(line) }
|
82
84
|
end
|
83
85
|
|
84
86
|
# Returns the lines, padded where necessary for the viewport.
|
@@ -112,7 +114,7 @@ module Vedeu
|
|
112
114
|
|
113
115
|
return visible unless size < dim
|
114
116
|
|
115
|
-
visible + [
|
117
|
+
visible + [Vedeu::Char.new({ value: ' ' })] * (dim - size)
|
116
118
|
end
|
117
119
|
|
118
120
|
# Using the current cursor's y position, return a range of visible lines.
|
@@ -1,6 +1,16 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
# Store and retrieve
|
3
|
+
# Store and retrieve {Vedeu::VirtualTerminal} objects.
|
4
|
+
#
|
5
|
+
# Each {Vedeu::VirtualTerminal} object is a copy of the current terminal
|
6
|
+
# including content but not as String objects but {Vedeu::Char} objects. Using
|
7
|
+
# {Vedeu::Char} objects means that we can store the data used to make up the
|
8
|
+
# displayed character, complete with its colour, position and style.
|
9
|
+
#
|
10
|
+
# Once a {Vedeu::Char} has been converted to a String, it is tricky to
|
11
|
+
# separate the escape sequences and string data. By deferring this conversion
|
12
|
+
# we can display the {Vedeu::Char} in multiple ways (e.g. HTML) or in multiple
|
13
|
+
# formats (e.g. JSON), and render/use that in an appropriate way.
|
4
14
|
#
|
5
15
|
module VirtualBuffer
|
6
16
|
|
@@ -1,23 +1,34 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
# Represents a {Vedeu::Terminal} view.
|
3
|
+
# Represents a {Vedeu::Terminal} view as a grid of {Vedeu::Cell} objects.
|
4
4
|
#
|
5
5
|
class VirtualTerminal
|
6
6
|
|
7
|
+
# @!attribute [rw] renderer
|
8
|
+
# @return [void]
|
7
9
|
attr_accessor :renderer
|
8
|
-
|
10
|
+
|
11
|
+
# @!attribute [r] height
|
12
|
+
# @return [Fixnum]
|
13
|
+
attr_reader :height
|
14
|
+
|
15
|
+
# @!attribute [r] width
|
16
|
+
# @return [Fixnum]
|
17
|
+
attr_reader :width
|
9
18
|
|
10
19
|
# @param height [Fixnum]
|
11
20
|
# @param width [Fixnum]
|
12
21
|
# @param renderer [Object|HTMLRenderer] An object responding to .render.
|
13
22
|
# @return [Vedeu::VirtualTerminal]
|
14
|
-
def initialize(height, width, renderer = HTMLRenderer)
|
15
|
-
@cell_height, @cell_width = Vedeu::PositionIndex[height, width]
|
23
|
+
def initialize(height, width, renderer = Vedeu::HTMLRenderer)
|
16
24
|
@height = height
|
17
25
|
@width = width
|
18
26
|
@renderer = renderer
|
19
27
|
end
|
20
28
|
|
29
|
+
# Return a grid of {Vedeu::Char} objects defined by the height and width of
|
30
|
+
# this virtual terminal.
|
31
|
+
#
|
21
32
|
# @return [Array<Array<Vedeu::Char>>]
|
22
33
|
def cells
|
23
34
|
@cells ||= new_virtual_terminal
|
@@ -25,6 +36,11 @@ module Vedeu
|
|
25
36
|
|
26
37
|
# Read a single cell from the virtual terminal.
|
27
38
|
#
|
39
|
+
# @note
|
40
|
+
# Given two actual coordinates (y, x) e.g. (1, 1)
|
41
|
+
# Convert to coordinate indices (cy, cx) e.g. (0, 0)
|
42
|
+
# Fetch the row at cy and return the cell from cx
|
43
|
+
#
|
28
44
|
# @param y [Fixnum]
|
29
45
|
# @param x [Fixnum]
|
30
46
|
# @return [Vedeu::Char]
|
@@ -49,7 +65,9 @@ module Vedeu
|
|
49
65
|
cells
|
50
66
|
end
|
51
67
|
|
52
|
-
#
|
68
|
+
# Send the cells to the renderer and return the rendered result.
|
69
|
+
#
|
70
|
+
# @return [String|void] Most likely to be a String.
|
53
71
|
def render
|
54
72
|
renderer.render(cells)
|
55
73
|
end
|
@@ -64,15 +82,18 @@ module Vedeu
|
|
64
82
|
|
65
83
|
# Write a single cell to the virtual terminal.
|
66
84
|
#
|
85
|
+
# @note
|
86
|
+
# If the position (y, x) is nil; we're out of bounds.
|
87
|
+
# Otherwise, write the data to (cy, cx).
|
88
|
+
#
|
67
89
|
# @param y [Fixnum]
|
68
90
|
# @param x [Fixnum]
|
69
91
|
# @param data [Vedeu::Char]
|
70
92
|
# @return [Vedeu::Char]
|
71
93
|
def write(y, x, data)
|
72
|
-
|
73
|
-
|
74
|
-
return false unless read(cy, cx).is_a?(Vedeu::Char)
|
94
|
+
return false unless read(y, x).is_a?(Vedeu::Char)
|
75
95
|
|
96
|
+
cy, cx = Vedeu::PositionIndex[y, x]
|
76
97
|
cells[cy][cx] = data
|
77
98
|
|
78
99
|
true
|
@@ -80,16 +101,18 @@ module Vedeu
|
|
80
101
|
|
81
102
|
private
|
82
103
|
|
83
|
-
# @param from [Array]
|
84
|
-
# @param which [
|
104
|
+
# @param from [Array] An Array of rows, or an Array of cells.
|
105
|
+
# @param which [Fixnum] A Fixnum representing the index; the row number or
|
106
|
+
# the cell number for a row.
|
85
107
|
# @return [Array<Vedeu::Char>|Array]
|
86
108
|
def fetch(from, which)
|
87
109
|
from[which] || []
|
88
110
|
end
|
89
111
|
|
90
112
|
# @return [Array<Array<Vedeu::Char>>]
|
113
|
+
# @see {Vedeu::VirtualTerminal#cells}
|
91
114
|
def new_virtual_terminal
|
92
|
-
Array.new(
|
115
|
+
Array.new(height) { Array.new(width) { Vedeu::Char.new } }
|
93
116
|
end
|
94
117
|
|
95
118
|
end # VirtualTerminal
|