vedeu 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +6 -0
- data/bin/vedeu_drb_client +8 -3
- data/bin/vedeu_drb_server +113 -0
- data/bin/vedeu_test +1 -1
- data/docs/events.md +0 -127
- data/examples/borders_app.rb +17 -7
- data/examples/configuration_app.rb +1 -1
- data/examples/cursor_app.rb +4 -2
- data/examples/drb_app.rb +113 -0
- data/examples/focus_app.rb +1 -1
- data/examples/geometry_app.rb +1 -1
- data/examples/hello_world.rb +1 -1
- data/examples/lines_app.rb +1 -1
- data/features/start_stop.feature +1 -1
- data/inch.yml +5 -0
- data/lib/vedeu/all.rb +2 -0
- data/lib/vedeu/api.rb +1 -0
- data/lib/vedeu/application.rb +17 -36
- data/lib/vedeu/bindings.rb +134 -27
- data/lib/vedeu/buffers/display_buffer.rb +1 -4
- data/lib/vedeu/configuration/api.rb +15 -14
- data/lib/vedeu/configuration/cli.rb +17 -16
- data/lib/vedeu/configuration/configuration.rb +3 -1
- data/lib/vedeu/cursor/cursor.rb +6 -8
- data/lib/vedeu/cursor/move_cursor.rb +1 -0
- data/lib/vedeu/cursor/toggle_cursor.rb +1 -0
- data/lib/vedeu/debug.rb +23 -0
- data/lib/vedeu/distributed/all.rb +1 -1
- data/lib/vedeu/distributed/client.rb +55 -13
- data/lib/vedeu/distributed/server.rb +207 -0
- data/lib/vedeu/distributed/subprocess.rb +22 -21
- data/lib/vedeu/distributed/templates/default_application.vedeu +3 -1
- data/lib/vedeu/distributed/test_application.rb +2 -1
- data/lib/vedeu/distributed/uri.rb +1 -0
- data/lib/vedeu/dsl/all.rb +4 -2
- data/lib/vedeu/dsl/components/border.rb +11 -10
- data/lib/vedeu/dsl/components/geometry.rb +1 -0
- data/lib/vedeu/dsl/components/keymap.rb +1 -0
- data/lib/vedeu/dsl/components/menu.rb +1 -0
- data/lib/vedeu/dsl/interface.rb +1 -0
- data/lib/vedeu/dsl/line.rb +3 -1
- data/lib/vedeu/dsl/shared/colour.rb +1 -0
- data/lib/vedeu/dsl/shared/style.rb +1 -0
- data/lib/vedeu/dsl/shared/text.rb +2 -0
- data/lib/vedeu/dsl/shared/use.rb +3 -0
- data/lib/vedeu/dsl/stream.rb +3 -1
- data/lib/vedeu/dsl/view.rb +1 -0
- data/lib/vedeu/events/event.rb +9 -6
- data/lib/vedeu/events/trigger.rb +18 -7
- data/lib/vedeu/exceptions.rb +4 -1
- data/lib/vedeu/input/input.rb +1 -0
- data/lib/vedeu/input/key.rb +0 -1
- data/lib/vedeu/input/keymap.rb +5 -3
- data/lib/vedeu/input/keys.rb +1 -0
- data/lib/vedeu/input/mapper.rb +1 -0
- data/lib/vedeu/launcher.rb +35 -12
- data/lib/vedeu/main_loop.rb +53 -0
- data/lib/vedeu/models/collection.rb +11 -3
- data/lib/vedeu/models/focus.rb +3 -3
- data/lib/vedeu/models/geometry.rb +8 -16
- data/lib/vedeu/models/group.rb +1 -0
- data/lib/vedeu/models/menu.rb +2 -1
- data/lib/vedeu/models/model.rb +7 -1
- data/lib/vedeu/models/view/char.rb +52 -44
- data/lib/vedeu/models/view/chars.rb +1 -0
- data/lib/vedeu/models/view/composition.rb +2 -1
- data/lib/vedeu/models/view/interface.rb +5 -3
- data/lib/vedeu/models/view/interfaces.rb +1 -0
- data/lib/vedeu/models/view/line.rb +2 -1
- data/lib/vedeu/models/view/stream.rb +2 -1
- data/lib/vedeu/models/view/streams.rb +1 -0
- data/lib/vedeu/output/all.rb +4 -0
- data/lib/vedeu/output/border.rb +75 -206
- data/lib/vedeu/output/compositor.rb +1 -0
- data/lib/vedeu/output/html_char.rb +119 -0
- data/lib/vedeu/output/html_renderer.rb +89 -0
- data/lib/vedeu/output/output.rb +48 -44
- data/lib/vedeu/output/position_index.rb +12 -1
- data/lib/vedeu/output/renderer.rb +28 -0
- data/lib/vedeu/output/viewport.rb +14 -14
- data/lib/vedeu/output/virtual_buffer.rb +56 -0
- data/lib/vedeu/output/virtual_terminal.rb +42 -34
- data/lib/vedeu/output/wordwrap.rb +3 -0
- data/lib/vedeu/output/writer.rb +13 -1
- data/lib/vedeu/presentation/background.rb +1 -0
- data/lib/vedeu/presentation/colour.rb +8 -7
- data/lib/vedeu/presentation/foreground.rb +1 -0
- data/lib/vedeu/presentation/presentation.rb +43 -7
- data/lib/vedeu/presentation/translator.rb +12 -0
- data/lib/vedeu/repositories/repository.rb +8 -8
- data/lib/vedeu/support/bounding_area.rb +2 -0
- data/lib/vedeu/support/coercions.rb +2 -1
- data/lib/vedeu/support/common.rb +1 -0
- data/lib/vedeu/support/console.rb +17 -23
- data/lib/vedeu/support/content_geometry.rb +2 -0
- data/lib/vedeu/support/coordinate.rb +1 -0
- data/lib/vedeu/support/esc.rb +58 -29
- data/lib/vedeu/support/grid.rb +1 -0
- data/lib/vedeu/support/limit.rb +9 -0
- data/lib/vedeu/support/log.rb +31 -9
- data/lib/vedeu/support/node.rb +8 -18
- data/lib/vedeu/support/position.rb +13 -34
- data/lib/vedeu/support/position_validator.rb +3 -0
- data/lib/vedeu/support/read.rb +1 -0
- data/lib/vedeu/support/refresh.rb +3 -2
- data/lib/vedeu/support/terminal.rb +11 -5
- data/lib/vedeu/support/trace.rb +16 -1
- data/lib/vedeu/support/visible.rb +2 -0
- data/lib/vedeu/support/write.rb +1 -0
- data/lib/vedeu/traps.rb +1 -0
- data/lib/vedeu.rb +2 -0
- data/test/integration/distributed_test.rb +10 -8
- data/test/lib/vedeu/api_test.rb +3 -7
- data/test/lib/vedeu/application_test.rb +2 -5
- data/test/lib/vedeu/configuration/api_test.rb +12 -0
- data/test/lib/vedeu/cursor/cursor_test.rb +2 -0
- data/test/lib/vedeu/distributed/client_test.rb +17 -7
- data/test/lib/vedeu/distributed/server_test.rb +56 -0
- data/test/lib/vedeu/distributed/test_application_test.rb +7 -3
- data/test/lib/vedeu/dsl/components/border_test.rb +10 -2
- data/test/lib/vedeu/dsl/interface_test.rb +6 -0
- data/test/lib/vedeu/dsl/line_test.rb +19 -0
- data/test/lib/vedeu/dsl/shared/colour_test.rb +4 -26
- data/test/lib/vedeu/dsl/shared/text_test.rb +8 -1
- data/test/lib/vedeu/dsl/stream_test.rb +13 -1
- data/test/lib/vedeu/input/input_test.rb +1 -1
- data/test/lib/vedeu/input/key_test.rb +3 -16
- data/test/lib/vedeu/launcher_test.rb +11 -1
- data/test/lib/vedeu/main_loop_test.rb +41 -0
- data/test/lib/vedeu/models/geometry_test.rb +15 -34
- data/test/lib/vedeu/models/view/char_test.rb +44 -45
- data/test/lib/vedeu/models/view/interface_test.rb +6 -0
- data/test/lib/vedeu/models/view/line_test.rb +1 -1
- data/test/lib/vedeu/models/view/stream_test.rb +1 -1
- data/test/lib/vedeu/output/border_test.rb +6 -5
- data/test/lib/vedeu/output/compositor_test.rb +2 -20
- data/test/lib/vedeu/output/html_char_test.rb +85 -0
- data/test/lib/vedeu/output/html_renderer_test.rb +37 -0
- data/test/lib/vedeu/output/position_index_test.rb +2 -10
- data/test/lib/vedeu/output/renderer_test.rb +24 -0
- data/test/lib/vedeu/output/virtual_buffer_test.rb +53 -0
- data/test/lib/vedeu/output/virtual_terminal_test.rb +32 -2
- data/test/lib/vedeu/presentation/background_test.rb +41 -1
- data/test/lib/vedeu/presentation/colour_test.rb +10 -6
- data/test/lib/vedeu/presentation/foreground_test.rb +46 -6
- data/test/lib/vedeu/presentation/presentation_test.rb +44 -1
- data/test/lib/vedeu/presentation/translator_test.rb +34 -0
- data/test/lib/vedeu/repositories/repository_test.rb +1 -1
- data/test/lib/vedeu/support/bounding_area_test.rb +4 -12
- data/test/lib/vedeu/support/console_test.rb +9 -50
- data/test/lib/vedeu/support/esc_test.rb +7 -7
- data/test/lib/vedeu/support/position_test.rb +42 -0
- data/test/lib/vedeu/support/terminal_test.rb +5 -20
- data/test/lib/vedeu/support/write_test.rb +42 -18
- data/test/support/helpers/all.rb +0 -1
- data/test/support/helpers/repository_test_module.rb +1 -0
- data/test/test_helper.rb +5 -2
- data/vedeu.gemspec +7 -5
- metadata +60 -14
- data/lib/vedeu/distributed/application.rb +0 -91
- data/test/lib/vedeu/distributed/application_test.rb +0 -24
- data/test/support/helpers/presentation.rb +0 -16
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'vedeu/support/common'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
|
5
|
+
class HTMLChar
|
6
|
+
|
7
|
+
include Vedeu::Common
|
8
|
+
|
9
|
+
# @param char [Vedeu::Char]
|
10
|
+
# @return [String]
|
11
|
+
def self.render(char)
|
12
|
+
new(char).render
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param char [Vedeu::Char]
|
16
|
+
# @return [Vedeu::HTMLChar]
|
17
|
+
def initialize(char)
|
18
|
+
@char = char
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [String]
|
22
|
+
def render
|
23
|
+
"<td#{td_style}>#{td_value}</td>"
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :char
|
29
|
+
|
30
|
+
# @return [String]
|
31
|
+
def td_style
|
32
|
+
return '' unless border || defined_value?(value)
|
33
|
+
|
34
|
+
" style='background:#{bg};color:#{fg};border:1px #{bg} solid;#{border_style}'"
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [String]
|
38
|
+
def td_value
|
39
|
+
return ' ' if border || !defined_value?(value)
|
40
|
+
|
41
|
+
value
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [String]
|
45
|
+
def border_style
|
46
|
+
case border
|
47
|
+
when nil then ''
|
48
|
+
when :top_horizontal then border_css('top')
|
49
|
+
when :left_vertical then border_css('left')
|
50
|
+
when :right_vertical then border_css('right')
|
51
|
+
when :bottom_horizontal then border_css('bottom')
|
52
|
+
when :top_left then [border_css('top'), border_css('left')].join
|
53
|
+
when :top_right then [border_css('top'), border_css('right')].join
|
54
|
+
when :bottom_left then [border_css('bottom'), border_css('left')].join
|
55
|
+
when :bottom_right then [border_css('bottom'), border_css('right')].join
|
56
|
+
when :horizontal then ''
|
57
|
+
when :vertical then ''
|
58
|
+
else
|
59
|
+
# ... should not get here
|
60
|
+
''
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [String]
|
65
|
+
def border_css(direction = '')
|
66
|
+
"border-#{direction}:1px #{fg} solid;"
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [String]
|
70
|
+
def fg
|
71
|
+
@fg ||= colour_fg || parent_fg || '#222'
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [String]
|
75
|
+
def bg
|
76
|
+
@bg ||= colour_bg || parent_bg || '#000'
|
77
|
+
end
|
78
|
+
|
79
|
+
# @return [String|NilClass]
|
80
|
+
def colour_bg
|
81
|
+
if char.background && defined_value?(char.background.to_html)
|
82
|
+
char.background.to_html
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# @return [String|NilClass]
|
87
|
+
def colour_fg
|
88
|
+
if char.foreground && defined_value?(char.foreground.to_html)
|
89
|
+
char.foreground.to_html
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [String|NilClass]
|
94
|
+
def parent_bg
|
95
|
+
if char.parent_background && defined_value?(char.parent_background.to_html)
|
96
|
+
char.parent_background.to_html
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [String|NilClass]
|
101
|
+
def parent_fg
|
102
|
+
if char.parent_foreground && defined_value?(char.parent_foreground.to_html)
|
103
|
+
char.parent_foreground.to_html
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# @return [Symbol|NilClass]
|
108
|
+
def border
|
109
|
+
char.border
|
110
|
+
end
|
111
|
+
|
112
|
+
# @return [String]
|
113
|
+
def value
|
114
|
+
char.value
|
115
|
+
end
|
116
|
+
|
117
|
+
end # HTMLChar
|
118
|
+
|
119
|
+
end # Vedeu
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
class HTMLRenderer
|
4
|
+
|
5
|
+
# @param output [Array<Array<Vedeu::Char>>]
|
6
|
+
# @return [String]
|
7
|
+
def self.render(output)
|
8
|
+
new(output).render
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param output [Array<Array<Vedeu::Char>>]
|
12
|
+
# @return [Vedeu::HTMLRenderer]
|
13
|
+
def initialize(output)
|
14
|
+
@output = output
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String]
|
18
|
+
def render
|
19
|
+
html_header + html_body + html_footer
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param path [String]
|
23
|
+
# @return [String]
|
24
|
+
def to_file(path = file_path)
|
25
|
+
content = render
|
26
|
+
|
27
|
+
File.open(path, "w", 0644) { |file| file.write(content) }
|
28
|
+
|
29
|
+
content
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :output
|
35
|
+
|
36
|
+
# @return [String]
|
37
|
+
def html_body
|
38
|
+
out = ''
|
39
|
+
Array(output).each do |line|
|
40
|
+
out << "<tr>\n"
|
41
|
+
line.each do |char|
|
42
|
+
out << char.to_html
|
43
|
+
out << "\n"
|
44
|
+
end
|
45
|
+
out << "</tr>\n"
|
46
|
+
end
|
47
|
+
out
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [String]
|
51
|
+
def html_header
|
52
|
+
<<-HTML
|
53
|
+
<html>
|
54
|
+
<head>
|
55
|
+
<style type='text/css'>
|
56
|
+
body { background:#000; }
|
57
|
+
td { border:1px #171717 solid;
|
58
|
+
font-size:12px;
|
59
|
+
font-family:monospace;
|
60
|
+
height:18px;
|
61
|
+
margin:1px;
|
62
|
+
text-align:center;
|
63
|
+
vertical-align:center;
|
64
|
+
width:18px; }
|
65
|
+
</style>
|
66
|
+
</head>
|
67
|
+
<body>
|
68
|
+
<table>
|
69
|
+
HTML
|
70
|
+
end
|
71
|
+
|
72
|
+
# @return [String]
|
73
|
+
def html_footer
|
74
|
+
"</table></body></html>"
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [String]
|
78
|
+
def file_path
|
79
|
+
"/tmp/vedeu_html_#{timestamp}.html"
|
80
|
+
end
|
81
|
+
|
82
|
+
# return [Fixnum]
|
83
|
+
def timestamp
|
84
|
+
@timestamp ||= Time.now.to_i
|
85
|
+
end
|
86
|
+
|
87
|
+
end # HTMLRenderer
|
88
|
+
|
89
|
+
end # Vedeu
|
data/lib/vedeu/output/output.rb
CHANGED
@@ -25,9 +25,11 @@ module Vedeu
|
|
25
25
|
#
|
26
26
|
# @return [Array]
|
27
27
|
def render
|
28
|
-
Vedeu.
|
28
|
+
if Vedeu::Configuration.drb?
|
29
|
+
Vedeu.trigger(:_drb_store_output_, virtual_view)
|
30
|
+
end
|
29
31
|
|
30
|
-
Terminal.output(
|
32
|
+
Terminal.output(Renderer.render(virtual_view, interface.cursor))
|
31
33
|
end
|
32
34
|
|
33
35
|
private
|
@@ -38,66 +40,45 @@ module Vedeu
|
|
38
40
|
# colours to those specified when the interface was defined, then starting
|
39
41
|
# write space characters over the area which the interface occupies.
|
40
42
|
#
|
41
|
-
# @
|
42
|
-
|
43
|
-
Vedeu.log("Clearing view: '#{interface.name}'")
|
44
|
-
|
45
|
-
interface.height.times.inject([interface.colour]) do |line, index|
|
46
|
-
line << interface.origin(index) { ' ' * interface.width }
|
47
|
-
end.join
|
48
|
-
end
|
49
|
-
|
50
|
-
# Produces a single string which contains all content and escape sequences
|
51
|
-
# required to render this interface in the terminal window.
|
43
|
+
# @note
|
44
|
+
# omg!
|
52
45
|
#
|
53
|
-
# @return [
|
54
|
-
def view
|
55
|
-
out = [ clear ]
|
56
|
-
|
57
|
-
Vedeu.log("Rendering view: '#{interface.name}'")
|
58
|
-
|
59
|
-
viewport.each_with_index do |line, index|
|
60
|
-
out << interface.origin(index)
|
61
|
-
out << line.join
|
62
|
-
end
|
63
|
-
|
64
|
-
out.join
|
65
|
-
end
|
66
|
-
|
67
|
-
def viewport
|
68
|
-
@_viewport ||= Vedeu::Viewport.new(interface).render
|
69
|
-
end
|
70
|
-
|
71
|
-
# omg!
|
46
|
+
# @return [Array<Array<Vedeu::Char>>]
|
72
47
|
def virtual_clear
|
48
|
+
Vedeu.log(type: :output, message: "Clearing: '#{interface.name}'")
|
49
|
+
|
73
50
|
out = []
|
74
|
-
interface.height.times do |
|
51
|
+
interface.height.times do |iy|
|
75
52
|
row = []
|
76
|
-
interface.width.times do |
|
77
|
-
|
78
|
-
pos = Vedeu::Position.new(v.first, (v.last + wi))
|
79
|
-
row << Vedeu::Char.new(' ', nil, interface.colour, nil, pos)
|
53
|
+
interface.width.times do |ix|
|
54
|
+
row << char_builder(' ', iy, ix)
|
80
55
|
end
|
81
56
|
out << row
|
82
57
|
end
|
83
58
|
out
|
84
59
|
end
|
85
60
|
|
86
|
-
#
|
61
|
+
# Builds up a virtual view; a grid of Vedeu::Char objects- each one holding
|
62
|
+
# one character along with its colour, style and position attributes.
|
63
|
+
#
|
64
|
+
# @note
|
65
|
+
# omg!
|
66
|
+
#
|
67
|
+
# @return [Array<Array<Vedeu::Char>>]
|
87
68
|
def virtual_view
|
88
69
|
out = [ virtual_clear ]
|
89
70
|
|
90
|
-
|
71
|
+
Vedeu.log(type: :output, message: "Rendering: '#{interface.name}'")
|
72
|
+
|
73
|
+
viewport.each_with_index do |line, iy|
|
91
74
|
row = []
|
92
|
-
line.each_with_index do |char,
|
93
|
-
v = interface.raw_origin(line_index)
|
94
|
-
pos = Vedeu::Position.new(v.first, (v.last + char_index))
|
75
|
+
line.each_with_index do |char, ix|
|
95
76
|
row << if char.is_a?(Vedeu::Char)
|
96
|
-
char.position=(
|
77
|
+
char.position = position(iy, ix)
|
97
78
|
char
|
98
79
|
|
99
80
|
else
|
100
|
-
|
81
|
+
char_builder(char, iy, ix)
|
101
82
|
|
102
83
|
end
|
103
84
|
end
|
@@ -106,6 +87,29 @@ module Vedeu
|
|
106
87
|
out
|
107
88
|
end
|
108
89
|
|
90
|
+
# @return [void]
|
91
|
+
def viewport
|
92
|
+
@_viewport ||= Vedeu::Viewport.new(interface).render
|
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)
|
100
|
+
end
|
101
|
+
|
102
|
+
# @param value [String]
|
103
|
+
# @param iy [Fixnum]
|
104
|
+
# @param ix [Fixnum]
|
105
|
+
# @return [Vedeu::Char]
|
106
|
+
def char_builder(value, iy, ix)
|
107
|
+
Vedeu::Char.new({ value: value,
|
108
|
+
colour: interface.colour,
|
109
|
+
style: interface.style,
|
110
|
+
position: position(iy, ix) })
|
111
|
+
end
|
112
|
+
|
109
113
|
end # Output
|
110
114
|
|
111
115
|
end # Vedeu
|
@@ -1,20 +1,31 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
+
# Converts a position into an index for the terminal.
|
4
|
+
#
|
3
5
|
class PositionIndex
|
4
6
|
|
5
|
-
attr_reader :y,
|
7
|
+
attr_reader :y,
|
8
|
+
:x
|
9
|
+
|
6
10
|
alias_method :first, :y
|
7
11
|
alias_method :last, :x
|
8
12
|
|
13
|
+
# @param y [Fixnum]
|
14
|
+
# @param x [Fixnum]
|
15
|
+
# @return [Array]
|
9
16
|
def self.[](y, x)
|
10
17
|
new(y, x).[]
|
11
18
|
end
|
12
19
|
|
20
|
+
# @param y [Fixnum]
|
21
|
+
# @param x [Fixnum]
|
22
|
+
# @return [Vedeu::PositionIndex]
|
13
23
|
def initialize(y, x)
|
14
24
|
@y = [(y - 1), 1].max
|
15
25
|
@x = [(x - 1), 1].max
|
16
26
|
end
|
17
27
|
|
28
|
+
# @return [Array]
|
18
29
|
def []
|
19
30
|
[y, x]
|
20
31
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
class Renderer
|
4
|
+
|
5
|
+
# @param output [Array<Array<Vedeu::Char>>]
|
6
|
+
# @return [String]
|
7
|
+
def self.render(*output)
|
8
|
+
new(*output).render
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param output [Array<Array<Vedeu::Char>>]
|
12
|
+
# @return [Vedeu::Renderer]
|
13
|
+
def initialize(*output)
|
14
|
+
@output = output
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String]
|
18
|
+
def render
|
19
|
+
Array(output).flatten.map(&:to_s).join
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :output
|
25
|
+
|
26
|
+
end # Renderer
|
27
|
+
|
28
|
+
end # Vedeu
|
@@ -114,18 +114,18 @@ module Vedeu
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
# Using the current cursor's
|
117
|
+
# Using the current cursor's y position, return a range of visible lines.
|
118
118
|
#
|
119
|
-
# Scrolls the content
|
120
|
-
#
|
119
|
+
# Scrolls the content vertically when the stored cursor's y position for the
|
120
|
+
# interface is outside of the visible area.
|
121
121
|
#
|
122
122
|
# @note
|
123
|
-
# [value, 0].max # this allows us to set a
|
124
|
-
# #
|
123
|
+
# [value, 0].max # this allows us to set a top that is greater than
|
124
|
+
# # the content height.
|
125
125
|
#
|
126
|
-
# [[value, (
|
126
|
+
# [[value, (content_height - height)].min, 0].max
|
127
127
|
# # this does not allow us to have a position
|
128
|
-
# # greater than the content
|
128
|
+
# # greater than the content height.
|
129
129
|
#
|
130
130
|
# @return [Range]
|
131
131
|
def rows
|
@@ -140,18 +140,18 @@ module Vedeu
|
|
140
140
|
top..(top + (height - 1))
|
141
141
|
end
|
142
142
|
|
143
|
-
# Using the current cursor's
|
143
|
+
# Using the current cursor's x position, return a range of visible columns.
|
144
144
|
#
|
145
|
-
# Scrolls the content
|
146
|
-
# interface is outside of the visible area.
|
145
|
+
# Scrolls the content horizontally when the stored cursor's x position for
|
146
|
+
# the interface is outside of the visible area.
|
147
147
|
#
|
148
148
|
# @note
|
149
|
-
# [value, 0].max # this allows us to set a
|
150
|
-
# # the content
|
149
|
+
# [value, 0].max # this allows us to set a left that is greater
|
150
|
+
# # than the content width.
|
151
151
|
#
|
152
|
-
# [[value, (
|
152
|
+
# [[value, (content_width - width)].min, 0].max
|
153
153
|
# # this does not allow us to have a position
|
154
|
-
# # greater than the content
|
154
|
+
# # greater than the content width.
|
155
155
|
#
|
156
156
|
# @return [Range]
|
157
157
|
def columns
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Store and retrieve virtual terminals.
|
4
|
+
#
|
5
|
+
module VirtualBuffer
|
6
|
+
|
7
|
+
extend self
|
8
|
+
|
9
|
+
# Fetch the oldest stored virtual buffer first.
|
10
|
+
#
|
11
|
+
# @return [Array<Array<Vedeu::Char>>|NilClass]
|
12
|
+
def retrieve
|
13
|
+
storage.pop
|
14
|
+
end
|
15
|
+
|
16
|
+
# Store a new virtual buffer.
|
17
|
+
#
|
18
|
+
# @return [Array<Array<Vedeu::Char>>]
|
19
|
+
def store(data)
|
20
|
+
storage.unshift(data)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Return the number of virtual buffers currently stored.
|
24
|
+
#
|
25
|
+
# @return [Fixnum]
|
26
|
+
def size
|
27
|
+
storage.size
|
28
|
+
end
|
29
|
+
|
30
|
+
# Destroy all virtual buffers currently stored.
|
31
|
+
#
|
32
|
+
# @return [Array]
|
33
|
+
def clear
|
34
|
+
@_storage = in_memory
|
35
|
+
end
|
36
|
+
alias_method :reset, :clear
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# Access to the storage for this repository.
|
41
|
+
#
|
42
|
+
# @return [Array]
|
43
|
+
def storage
|
44
|
+
@_storage ||= in_memory
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns an empty collection ready for the storing of virtual buffers.
|
48
|
+
#
|
49
|
+
# @return [Array]
|
50
|
+
def in_memory
|
51
|
+
[]
|
52
|
+
end
|
53
|
+
|
54
|
+
end # VirtualBuffer
|
55
|
+
|
56
|
+
end # Vedeu
|
@@ -1,52 +1,28 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
# class Cell < Struct.new(:value)
|
4
|
-
# def initialize(value = [])
|
5
|
-
# super
|
6
|
-
# end
|
7
|
-
# end
|
8
|
-
|
9
|
-
# class Cells
|
10
|
-
# attr_reader :size, :value
|
11
|
-
|
12
|
-
# def initialize(size = 0, &block)
|
13
|
-
# @size = size
|
14
|
-
# @value = if block_given?
|
15
|
-
# [instance_eval(&block)] * size
|
16
|
-
|
17
|
-
# else
|
18
|
-
# [Cell.new] * size
|
19
|
-
|
20
|
-
# end
|
21
|
-
# end
|
22
|
-
|
23
|
-
# def [](index)
|
24
|
-
# value[index] || self
|
25
|
-
# end
|
26
|
-
|
27
|
-
# private
|
28
|
-
|
29
|
-
# attr_reader :size, :value
|
30
|
-
# end
|
31
|
-
|
32
3
|
class VirtualTerminal
|
33
4
|
|
5
|
+
attr_accessor :renderer
|
34
6
|
attr_reader :cell_height, :cell_width, :height, :width
|
35
7
|
|
36
8
|
# @param height [Fixnum]
|
37
9
|
# @param width [Fixnum]
|
10
|
+
# @param renderer [Object|HTMLRenderer] An object responding to .render.
|
38
11
|
# @return [Vedeu::VirtualTerminal]
|
39
|
-
def initialize(height, width)
|
12
|
+
def initialize(height, width, renderer = HTMLRenderer)
|
40
13
|
@cell_height, @cell_width = Vedeu::PositionIndex[height, width]
|
41
|
-
@height
|
42
|
-
@width
|
14
|
+
@height = height
|
15
|
+
@width = width
|
16
|
+
@renderer = renderer
|
43
17
|
end
|
44
18
|
|
45
|
-
# @return [Array<Vedeu::Char
|
19
|
+
# @return [Array<Array<Vedeu::Char>>]
|
46
20
|
def cells
|
47
|
-
|
21
|
+
@cells ||= new_virtual_terminal
|
48
22
|
end
|
49
23
|
|
24
|
+
# Read a single cell from the virtual terminal.
|
25
|
+
#
|
50
26
|
# @param y [Fixnum]
|
51
27
|
# @param x [Fixnum]
|
52
28
|
# @return [Vedeu::Char]
|
@@ -59,6 +35,33 @@ module Vedeu
|
|
59
35
|
cell
|
60
36
|
end
|
61
37
|
|
38
|
+
# Write a collection of cells to the virtual terminal.
|
39
|
+
#
|
40
|
+
# @param data [Array<Array<Vedeu::Char>>]
|
41
|
+
# @return [Array<Array<Vedeu::Char>>]
|
42
|
+
def output(data)
|
43
|
+
Array(data).flatten.each do |char|
|
44
|
+
write(char.y, char.x, char) if char.is_a?(Vedeu::Char)
|
45
|
+
end
|
46
|
+
|
47
|
+
cells
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [void]
|
51
|
+
def render
|
52
|
+
renderer.render(cells)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Removes all content from the virtual terminal; effectively clearing it.
|
56
|
+
#
|
57
|
+
# @return [Array<Array<Vedeu::Char>>]
|
58
|
+
def reset
|
59
|
+
@cells = new_virtual_terminal
|
60
|
+
end
|
61
|
+
alias_method :clear, :reset
|
62
|
+
|
63
|
+
# Write a single cell to the virtual terminal.
|
64
|
+
#
|
62
65
|
# @param y [Fixnum]
|
63
66
|
# @param x [Fixnum]
|
64
67
|
# @param data [Vedeu::Char]
|
@@ -81,6 +84,11 @@ module Vedeu
|
|
81
84
|
from[which] || []
|
82
85
|
end
|
83
86
|
|
87
|
+
# @return [Array<Array<Vedeu::Char>>]
|
88
|
+
def new_virtual_terminal
|
89
|
+
Array.new(cell_height) { Array.new(cell_width) { Vedeu::Char.new } }
|
90
|
+
end
|
91
|
+
|
84
92
|
end # VirtualTerminal
|
85
93
|
|
86
94
|
end # Vedeu
|
data/lib/vedeu/output/writer.rb
CHANGED
@@ -1,32 +1,44 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
+
# Provides access to all possible mechanisms to write content.
|
4
|
+
#
|
5
|
+
# @note
|
6
|
+
# Will be used to translate output into HTML, etc.
|
7
|
+
#
|
3
8
|
class Writer
|
4
9
|
|
5
10
|
attr_reader :writers
|
6
11
|
|
12
|
+
# @param args []
|
7
13
|
# @return [Vedeu::Writer]
|
8
14
|
def self.[](*args)
|
9
15
|
new(args)
|
10
16
|
end
|
11
17
|
|
18
|
+
# @param writers []
|
12
19
|
# @return [Vedeu::Writer]
|
13
20
|
def initialize(writers)
|
14
21
|
@writers = writers
|
15
22
|
end
|
16
23
|
|
24
|
+
# @param other []
|
25
|
+
# @return [Boolean]
|
17
26
|
def ==(other)
|
18
27
|
writers == other.writers
|
19
28
|
end
|
20
29
|
|
30
|
+
# @param other []
|
21
31
|
# @return [Vedeu::Writer]
|
22
32
|
def +(other)
|
23
33
|
Writer[*(writers + other.writers)]
|
24
34
|
end
|
25
35
|
|
36
|
+
# @param stream []
|
37
|
+
# @return [Array]
|
26
38
|
def write(stream)
|
27
39
|
@writers.each { |writer| writer.write(stream) }
|
28
40
|
end
|
29
41
|
|
30
|
-
end #
|
42
|
+
end # Writer
|
31
43
|
|
32
44
|
end # Vedeu
|