vedeu 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/vedeu_drb_client +6 -0
- data/lib/vedeu/all.rb +1 -0
- data/lib/vedeu/application.rb +24 -1
- data/lib/vedeu/configuration/api.rb +107 -0
- data/lib/vedeu/configuration/cli.rb +34 -0
- data/lib/vedeu/configuration/configuration.rb +75 -4
- data/lib/vedeu/distributed/all.rb +8 -0
- data/lib/vedeu/distributed/application.rb +91 -0
- data/lib/vedeu/distributed/client.rb +58 -0
- data/lib/vedeu/distributed/subprocess.rb +111 -0
- data/lib/vedeu/distributed/templates/default_application.vedeu +34 -0
- data/lib/vedeu/distributed/templates/default_borders.vedeu +19 -0
- data/lib/vedeu/distributed/templates/default_configuration.vedeu +31 -0
- data/lib/vedeu/distributed/templates/default_events.vedeu +1 -0
- data/lib/vedeu/distributed/templates/default_geometries.vedeu +7 -0
- data/lib/vedeu/distributed/templates/default_interfaces.vedeu +4 -0
- data/lib/vedeu/distributed/templates/default_keymaps.vedeu +6 -0
- data/lib/vedeu/distributed/templates/default_menus.vedeu +3 -0
- data/lib/vedeu/distributed/templates/default_views.vedeu +14 -0
- data/lib/vedeu/distributed/test_application.rb +99 -0
- data/lib/vedeu/distributed/uri.rb +38 -0
- data/lib/vedeu/input/mapper.rb +10 -0
- data/lib/vedeu/launcher.rb +4 -0
- data/lib/vedeu/models/geometry.rb +16 -31
- data/lib/vedeu/models/view/char.rb +5 -5
- data/lib/vedeu/models/view/interface.rb +2 -1
- data/lib/vedeu/output/all.rb +2 -0
- data/lib/vedeu/output/output.rb +40 -0
- data/lib/vedeu/output/position_index.rb +24 -0
- data/lib/vedeu/output/virtual_terminal.rb +87 -0
- data/lib/vedeu/support/all.rb +1 -0
- data/lib/vedeu/support/limit.rb +33 -0
- data/lib/vedeu/support/position.rb +29 -0
- data/lib/vedeu/support/terminal.rb +14 -2
- data/test/integration/distributed_test.rb +14 -0
- data/test/lib/vedeu/application_test.rb +7 -6
- data/test/lib/vedeu/buffers/buffer_test.rb +6 -8
- data/test/lib/vedeu/configuration/api_test.rb +50 -0
- data/test/lib/vedeu/configuration/cli_test.rb +21 -0
- data/test/lib/vedeu/configuration/configuration_test.rb +24 -0
- data/test/lib/vedeu/cursor/move_cursor_test.rb +5 -7
- data/test/lib/vedeu/distributed/application_test.rb +24 -0
- data/test/lib/vedeu/distributed/client_test.rb +36 -0
- data/test/lib/vedeu/distributed/subprocess_test.rb +20 -0
- data/test/lib/vedeu/distributed/test_application_test.rb +26 -0
- data/test/lib/vedeu/distributed/uri_test.rb +73 -0
- data/test/lib/vedeu/dsl/components/border_test.rb +3 -5
- data/test/lib/vedeu/dsl/components/keymap_test.rb +2 -4
- data/test/lib/vedeu/dsl/components/menu_test.rb +2 -4
- data/test/lib/vedeu/dsl/composition_test.rb +3 -5
- data/test/lib/vedeu/dsl/interface_test.rb +3 -5
- data/test/lib/vedeu/dsl/line_test.rb +3 -5
- data/test/lib/vedeu/dsl/stream_test.rb +3 -5
- data/test/lib/vedeu/events/event_test.rb +8 -10
- data/test/lib/vedeu/events/trigger_test.rb +4 -6
- data/test/lib/vedeu/input/input_test.rb +2 -4
- data/test/lib/vedeu/input/key_test.rb +0 -2
- data/test/lib/vedeu/input/keymap_test.rb +4 -6
- data/test/lib/vedeu/input/mapper_test.rb +5 -7
- data/test/lib/vedeu/launcher_test.rb +7 -9
- data/test/lib/vedeu/models/collection_test.rb +4 -6
- data/test/lib/vedeu/models/geometry_test.rb +40 -13
- data/test/lib/vedeu/models/group_test.rb +4 -6
- data/test/lib/vedeu/models/menu_test.rb +6 -9
- data/test/lib/vedeu/models/view/char_test.rb +7 -9
- data/test/lib/vedeu/models/view/chars_test.rb +1 -3
- data/test/lib/vedeu/models/view/composition_test.rb +4 -6
- data/test/lib/vedeu/models/view/interface_test.rb +10 -12
- data/test/lib/vedeu/models/view/interfaces_test.rb +1 -3
- data/test/lib/vedeu/models/view/line_test.rb +5 -7
- data/test/lib/vedeu/models/view/lines_test.rb +1 -3
- data/test/lib/vedeu/models/view/stream_test.rb +6 -8
- data/test/lib/vedeu/models/view/streams_test.rb +1 -3
- data/test/lib/vedeu/output/border_test.rb +6 -8
- data/test/lib/vedeu/output/compositor_test.rb +2 -4
- data/test/lib/vedeu/output/output_test.rb +5 -4
- data/test/lib/vedeu/output/position_index_test.rb +72 -0
- data/test/lib/vedeu/output/viewport_test.rb +2 -4
- data/test/lib/vedeu/output/virtual_terminal_test.rb +120 -0
- data/test/lib/vedeu/output/wordwrap_test.rb +3 -5
- data/test/lib/vedeu/presentation/colour_test.rb +0 -2
- data/test/lib/vedeu/presentation/style_test.rb +2 -4
- data/test/lib/vedeu/presentation/translator_test.rb +2 -4
- data/test/lib/vedeu/repositories/repository_test.rb +3 -5
- data/test/lib/vedeu/support/console_test.rb +5 -7
- data/test/lib/vedeu/support/content_geometry_test.rb +2 -4
- data/test/lib/vedeu/support/coordinate_test.rb +5 -7
- data/test/lib/vedeu/support/grid_test.rb +2 -4
- data/test/lib/vedeu/support/limit_test.rb +30 -0
- data/test/lib/vedeu/support/position_test.rb +8 -4
- data/test/lib/vedeu/support/position_validator_test.rb +4 -6
- data/test/lib/vedeu/support/read_test.rb +3 -5
- data/test/lib/vedeu/support/sentence_test.rb +3 -4
- data/test/lib/vedeu/support/trace_test.rb +2 -4
- data/test/lib/vedeu/support/visible_test.rb +6 -8
- data/test/lib/vedeu/support/write_test.rb +3 -5
- data/test/test_helper.rb +6 -2
- data/vedeu.gemspec +1 -1
- metadata +40 -2
@@ -0,0 +1,31 @@
|
|
1
|
+
Vedeu.configure do
|
2
|
+
colour_mode 16777216
|
3
|
+
log '/tmp/vedeu_test_helper.log'
|
4
|
+
debug!
|
5
|
+
drb!
|
6
|
+
drb_host 'localhost'
|
7
|
+
drb_port 21420
|
8
|
+
drb_width 80
|
9
|
+
drb_height 25
|
10
|
+
|
11
|
+
# cooked!
|
12
|
+
# raw!
|
13
|
+
|
14
|
+
# run_once!
|
15
|
+
|
16
|
+
# interactive!
|
17
|
+
# standalone!
|
18
|
+
|
19
|
+
# trace!
|
20
|
+
|
21
|
+
# System keys can be redefined
|
22
|
+
# exit_key 'q'
|
23
|
+
# focus_next_key :tab
|
24
|
+
# focus_prev_key :shift_tab
|
25
|
+
# mode_switch_key :escape
|
26
|
+
|
27
|
+
# Not used yet
|
28
|
+
# stdin File.open("/dev/tty", "r")
|
29
|
+
# stdout File.open("/dev/tty", "w")
|
30
|
+
# stderr File.open("/tmp/vedeu_error.log", "w+")
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
Vedeu.renders do
|
2
|
+
view 'test_interface' do
|
3
|
+
lines do
|
4
|
+
line 'a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1'
|
5
|
+
line 'a2b2c2d2e2f2g2h2i2j2k2l2m2n2o2p2q2r2s2t2u2v2w2x2y2z2'
|
6
|
+
line 'a3b3c3d3e3f3g3h3i3j3k3l3m3n3o3p3q3r3s3t3u3v3w3x3y3z3'
|
7
|
+
line 'a4b4c4d4e4f4g4h4i4j4k4l4m4n4o4p4q4r4s4t4u4v4w4x4y4z4'
|
8
|
+
line 'a5b5c5d5e5f5g5h5i5j5k5l5m5n5o5p5q5r5s5t5u5v5w5x5y5z5'
|
9
|
+
line 'a6b6c6d6e6f6g6h6i6j6k6l6m6n6o6p6q6r6s6t6u6v6w6x6y6z6'
|
10
|
+
line 'a7b7c7d7e7f7g7h7i7j7k7l7m7n7o7p7q7r7s7t7u7v7w7x7y7z7'
|
11
|
+
line 'a8b8c8d8e8f8g8h8i8j8k8l8m8n8o8p8q8r8s8t8u8v8w8x8y8z8'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
|
5
|
+
# Create a test application as a string.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# test_app = TestApplication.build do |app|
|
9
|
+
# app.borders = ''
|
10
|
+
# app.configuration = ''
|
11
|
+
# app.events = ''
|
12
|
+
# app.geometries = ''
|
13
|
+
# app.interfaces = ''
|
14
|
+
# app.keymaps = ''
|
15
|
+
# app.menus = ''
|
16
|
+
# app.views = ''
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
class TestApplication
|
20
|
+
|
21
|
+
attr_accessor :borders,
|
22
|
+
:configuration,
|
23
|
+
:events,
|
24
|
+
:geometries,
|
25
|
+
:interfaces,
|
26
|
+
:keymaps,
|
27
|
+
:menus,
|
28
|
+
:views
|
29
|
+
|
30
|
+
# @return [String]
|
31
|
+
def self.build(attributes = {}, &block)
|
32
|
+
new(attributes).build(&block)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param attributes [Hash]
|
36
|
+
# @option attributes borders [String]
|
37
|
+
# @option attributes configuration [String]
|
38
|
+
# @option attributes events [String]
|
39
|
+
# @option attributes geometries [String]
|
40
|
+
# @option attributes interfaces [String]
|
41
|
+
# @option attributes keymaps [String]
|
42
|
+
# @option attributes menus [String]
|
43
|
+
# @option attributes views [String]
|
44
|
+
# @param block [Proc]
|
45
|
+
# @return [TestApplication]
|
46
|
+
def initialize(attributes = {})
|
47
|
+
@attributes = defaults.merge(attributes)
|
48
|
+
|
49
|
+
@attributes.each do |k, v|
|
50
|
+
instance_variable_set("@#{k.to_s}", @attributes[k])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# @param block [Proc]
|
55
|
+
# @return [String]
|
56
|
+
def build(&block)
|
57
|
+
self.instance_eval(&block) if block_given?
|
58
|
+
|
59
|
+
@object = self
|
60
|
+
|
61
|
+
ERB.new(application, nil, '-').result(binding)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [String]
|
65
|
+
def lib_dir
|
66
|
+
File.dirname(__FILE__) + "/../../../lib"
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
# @return [String]
|
72
|
+
def application
|
73
|
+
@application ||= read('default_application.vedeu')
|
74
|
+
end
|
75
|
+
|
76
|
+
# @todo Don't like all this file reading.
|
77
|
+
#
|
78
|
+
# @return [Hash]
|
79
|
+
def defaults
|
80
|
+
{
|
81
|
+
borders: read('default_borders.vedeu'),
|
82
|
+
configuration: read('default_configuration.vedeu'),
|
83
|
+
events: read('default_events.vedeu'),
|
84
|
+
geometries: read('default_geometries.vedeu'),
|
85
|
+
interfaces: read('default_interfaces.vedeu'),
|
86
|
+
keymaps: read('default_keymaps.vedeu'),
|
87
|
+
menus: read('default_menus.vedeu'),
|
88
|
+
views: read('default_views.vedeu'),
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
# @return [String]
|
93
|
+
def read(filename)
|
94
|
+
File.read(File.dirname(__FILE__) + '/templates/' + filename)
|
95
|
+
end
|
96
|
+
|
97
|
+
end # TestApplication
|
98
|
+
|
99
|
+
end # Vedeu
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Distributed
|
4
|
+
|
5
|
+
# Value class which provides the host and port for the DRb server and
|
6
|
+
# client.
|
7
|
+
class Uri
|
8
|
+
|
9
|
+
attr_reader :host, :port
|
10
|
+
|
11
|
+
# @param host [String] Hostname or IP address.
|
12
|
+
# @param port [Fixnum|String]
|
13
|
+
# @return [Uri]
|
14
|
+
def initialize(host = 'localhost', port = 21420)
|
15
|
+
@host = host || 'localhost'
|
16
|
+
@port = port || 21420
|
17
|
+
end
|
18
|
+
|
19
|
+
# @example
|
20
|
+
# 'druby://localhost:21420'
|
21
|
+
#
|
22
|
+
# @return [String] The host and port as a single value.
|
23
|
+
def to_s
|
24
|
+
[scheme, host, ':', port].join
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# @return [String]
|
30
|
+
def scheme
|
31
|
+
'druby://'
|
32
|
+
end
|
33
|
+
|
34
|
+
end # Uri
|
35
|
+
|
36
|
+
end # Distributed
|
37
|
+
|
38
|
+
end # Vedeu
|
data/lib/vedeu/input/mapper.rb
CHANGED
@@ -64,28 +64,38 @@ module Vedeu
|
|
64
64
|
|
65
65
|
attr_reader :key, :repository
|
66
66
|
|
67
|
+
# Is the key a global key?
|
68
|
+
#
|
67
69
|
# @return [Boolean]
|
68
70
|
def global_key?
|
69
71
|
key_defined?(global)
|
70
72
|
end
|
71
73
|
|
74
|
+
# Is the key a system key?
|
75
|
+
#
|
72
76
|
# @return [Boolean]
|
73
77
|
def system_key?
|
74
78
|
key_defined?(system)
|
75
79
|
end
|
76
80
|
|
81
|
+
# Is the key defined in the named keymap?
|
82
|
+
#
|
77
83
|
# @param named [NilClass|String]
|
78
84
|
# @return [Boolean]
|
79
85
|
def key_defined?(named = name)
|
80
86
|
keymap?(named) && keymap(named).key_defined?(key)
|
81
87
|
end
|
82
88
|
|
89
|
+
# Fetch the named keymap from the repository.
|
90
|
+
#
|
83
91
|
# @param named [NilClass|String]
|
84
92
|
# @return [Keymap]
|
85
93
|
def keymap(named = name)
|
86
94
|
repository.find(named)
|
87
95
|
end
|
88
96
|
|
97
|
+
# Does the keymaps repository have the named keymap already registered?
|
98
|
+
#
|
89
99
|
# @param named [NilClass|String]
|
90
100
|
# @return [Boolean]
|
91
101
|
def keymap?(named = name)
|
data/lib/vedeu/launcher.rb
CHANGED
@@ -127,47 +127,23 @@ module Vedeu
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
# Returns a dynamic value calculated from the current terminal
|
131
|
-
# combined with the desired
|
130
|
+
# Returns a dynamic value calculated from the current terminal dimensions,
|
131
|
+
# combined with the desired start point.
|
132
132
|
#
|
133
133
|
# If the interface is `centred` then if the terminal resizes, this value
|
134
134
|
# should attempt to accommodate that.
|
135
135
|
#
|
136
136
|
# For uncentred interfaces, when the terminal resizes, then this will help
|
137
|
-
# Vedeu render the view to ensure
|
138
|
-
# is not off-screen.
|
137
|
+
# Vedeu render the view to ensure the content is not off-screen.
|
139
138
|
#
|
140
139
|
# @return [Fixnum]
|
141
140
|
def width
|
142
|
-
|
143
|
-
new_width = @width - ((x + @width) - Terminal.width)
|
144
|
-
return new_width < 1 ? 1 : new_width
|
145
|
-
|
146
|
-
else
|
147
|
-
@width
|
148
|
-
|
149
|
-
end
|
141
|
+
Vedeu::Limit.apply(x, @width, Terminal.width, Terminal.origin)
|
150
142
|
end
|
151
143
|
|
152
|
-
#
|
153
|
-
# combined with the desired row start point.
|
154
|
-
#
|
155
|
-
# If the interface is `centred` then if the terminal resizes, this value
|
156
|
-
# should attempt to accommodate that.
|
157
|
-
#
|
158
|
-
# For uncentred interfaces, when the terminal resizes, then this will help
|
159
|
-
# Vedeu render the view to ensure the content is not off-screen.
|
160
|
-
#
|
161
|
-
# @return [Fixnum]
|
144
|
+
# @see Vedeu::Geometry#width
|
162
145
|
def height
|
163
|
-
|
164
|
-
new_height = @height - ((y + @height) - Terminal.height)
|
165
|
-
return new_height < 1 ? 1 : new_height
|
166
|
-
|
167
|
-
else
|
168
|
-
@height
|
169
|
-
|
170
|
-
end
|
146
|
+
Vedeu::Limit.apply(y, @height, Terminal.height, Terminal.origin)
|
171
147
|
end
|
172
148
|
|
173
149
|
# Returns an escape sequence to position the cursor at the top-left
|
@@ -177,7 +153,16 @@ module Vedeu
|
|
177
153
|
# @param block [Proc]
|
178
154
|
# @return [String]
|
179
155
|
def origin(index = 0, &block)
|
180
|
-
Esc.set_position(
|
156
|
+
Esc.set_position(*raw_origin(index), &block)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Returns a tuple which positions the cursor at the top-left coordinate,
|
160
|
+
# relative to the interface's position.
|
161
|
+
#
|
162
|
+
# @param index [Fixnum]
|
163
|
+
# @return [Array<Fixnum>]
|
164
|
+
def raw_origin(index = 0)
|
165
|
+
[virtual_y[index], left]
|
181
166
|
end
|
182
167
|
|
183
168
|
# Returns the top coordinate of the interface, a fixed or dynamic value
|
@@ -13,8 +13,8 @@ module Vedeu
|
|
13
13
|
|
14
14
|
include Vedeu::Presentation
|
15
15
|
|
16
|
-
attr_accessor :parent
|
17
|
-
|
16
|
+
attr_accessor :parent,
|
17
|
+
:position
|
18
18
|
|
19
19
|
class << self
|
20
20
|
|
@@ -58,16 +58,16 @@ module Vedeu
|
|
58
58
|
def initialize(value = nil, parent = nil, colour = nil, style = nil, position = nil)
|
59
59
|
@value = value
|
60
60
|
@parent = parent
|
61
|
-
@colour = colour
|
61
|
+
@colour = Vedeu::Colour.coerce(colour)
|
62
62
|
@style = style
|
63
|
-
@position = position
|
63
|
+
@position = Vedeu::Position.coerce(position)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Returns log friendly output.
|
67
67
|
#
|
68
68
|
# @return [String]
|
69
69
|
def inspect
|
70
|
-
"<#{self.class.name} (value
|
70
|
+
"<#{self.class.name} (value:'#{@value}')>"
|
71
71
|
end
|
72
72
|
|
73
73
|
# @param other []
|
data/lib/vedeu/output/all.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'vedeu/output/border'
|
2
2
|
require 'vedeu/output/compositor'
|
3
|
+
require 'vedeu/output/position_index'
|
3
4
|
require 'vedeu/output/output'
|
4
5
|
require 'vedeu/output/viewport'
|
6
|
+
require 'vedeu/output/virtual_terminal'
|
5
7
|
require 'vedeu/output/wordwrap'
|
6
8
|
require 'vedeu/output/writer'
|
7
9
|
|
data/lib/vedeu/output/output.rb
CHANGED
@@ -25,6 +25,8 @@ module Vedeu
|
|
25
25
|
#
|
26
26
|
# @return [Array]
|
27
27
|
def render
|
28
|
+
Vedeu.trigger(:_output_, virtual_view)
|
29
|
+
|
28
30
|
Terminal.output(view, interface.cursor.to_s)
|
29
31
|
end
|
30
32
|
|
@@ -66,6 +68,44 @@ module Vedeu
|
|
66
68
|
@_viewport ||= Vedeu::Viewport.new(interface).render
|
67
69
|
end
|
68
70
|
|
71
|
+
# omg!
|
72
|
+
def virtual_clear
|
73
|
+
out = []
|
74
|
+
interface.height.times do |hi|
|
75
|
+
row = []
|
76
|
+
interface.width.times do |wi|
|
77
|
+
v = interface.raw_origin(hi)
|
78
|
+
pos = Vedeu::Position.new(v.first, (v.last + wi))
|
79
|
+
row << Vedeu::Char.new(' ', nil, interface.colour, nil, pos)
|
80
|
+
end
|
81
|
+
out << row
|
82
|
+
end
|
83
|
+
out
|
84
|
+
end
|
85
|
+
|
86
|
+
# omg!
|
87
|
+
def virtual_view
|
88
|
+
out = [ virtual_clear ]
|
89
|
+
|
90
|
+
viewport.each_with_index do |line, line_index|
|
91
|
+
row = []
|
92
|
+
line.each_with_index do |char, char_index|
|
93
|
+
v = interface.raw_origin(line_index)
|
94
|
+
pos = Vedeu::Position.new(v.first, (v.last + char_index))
|
95
|
+
row << if char.is_a?(Vedeu::Char)
|
96
|
+
char.position=(pos)
|
97
|
+
char
|
98
|
+
|
99
|
+
else
|
100
|
+
Vedeu::Char.new(char, nil, interface.colour, nil, pos)
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
out << row
|
105
|
+
end
|
106
|
+
out
|
107
|
+
end
|
108
|
+
|
69
109
|
end # Output
|
70
110
|
|
71
111
|
end # Vedeu
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
class PositionIndex
|
4
|
+
|
5
|
+
attr_reader :y, :x
|
6
|
+
alias_method :first, :y
|
7
|
+
alias_method :last, :x
|
8
|
+
|
9
|
+
def self.[](y, x)
|
10
|
+
new(y, x).[]
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(y, x)
|
14
|
+
@y = [(y - 1), 1].max
|
15
|
+
@x = [(x - 1), 1].max
|
16
|
+
end
|
17
|
+
|
18
|
+
def []
|
19
|
+
[y, x]
|
20
|
+
end
|
21
|
+
|
22
|
+
end # PositionIndex
|
23
|
+
|
24
|
+
end # Vedeu
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Vedeu
|
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
|
+
class VirtualTerminal
|
33
|
+
|
34
|
+
attr_reader :cell_height, :cell_width, :height, :width
|
35
|
+
|
36
|
+
# @param height [Fixnum]
|
37
|
+
# @param width [Fixnum]
|
38
|
+
# @return [Vedeu::VirtualTerminal]
|
39
|
+
def initialize(height, width)
|
40
|
+
@cell_height, @cell_width = Vedeu::PositionIndex[height, width]
|
41
|
+
@height = height
|
42
|
+
@width = width
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Array<Vedeu::Char>]
|
46
|
+
def cells
|
47
|
+
Array.new(cell_height) { Array.new(cell_width) { Vedeu::Char.new } }
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param y [Fixnum]
|
51
|
+
# @param x [Fixnum]
|
52
|
+
# @return [Vedeu::Char]
|
53
|
+
def read(y, x)
|
54
|
+
cy, cx = Vedeu::PositionIndex[y, x]
|
55
|
+
|
56
|
+
row = fetch(cells, cy)
|
57
|
+
cell = fetch(row, cx)
|
58
|
+
|
59
|
+
cell
|
60
|
+
end
|
61
|
+
|
62
|
+
# @param y [Fixnum]
|
63
|
+
# @param x [Fixnum]
|
64
|
+
# @param data [Vedeu::Char]
|
65
|
+
# @return [Vedeu::Char]
|
66
|
+
def write(y, x, data)
|
67
|
+
cy, cx = Vedeu::PositionIndex[y, x]
|
68
|
+
|
69
|
+
return false unless read(y, x).is_a?(Vedeu::Char)
|
70
|
+
|
71
|
+
cells[cy][cx] = data
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# @param from [Array]
|
78
|
+
# @param which [Array]
|
79
|
+
# @return [Array<Vedeu::Char>|Array]
|
80
|
+
def fetch(from, which)
|
81
|
+
from[which] || []
|
82
|
+
end
|
83
|
+
|
84
|
+
end # VirtualTerminal
|
85
|
+
|
86
|
+
end # Vedeu
|
87
|
+
|
data/lib/vedeu/support/all.rb
CHANGED
@@ -6,6 +6,7 @@ require 'vedeu/support/content_geometry'
|
|
6
6
|
require 'vedeu/support/coordinate'
|
7
7
|
require 'vedeu/support/esc'
|
8
8
|
require 'vedeu/support/grid'
|
9
|
+
require 'vedeu/support/limit'
|
9
10
|
require 'vedeu/support/log'
|
10
11
|
require 'vedeu/support/position'
|
11
12
|
require 'vedeu/support/position_validator'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
class Limit
|
4
|
+
|
5
|
+
def self.apply(v, vn, max, min = 1)
|
6
|
+
new(v, vn, max, min).apply
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(v, vn, max, min = 1)
|
10
|
+
@v = v
|
11
|
+
@vn = vn
|
12
|
+
@max = max
|
13
|
+
@min = min || 1
|
14
|
+
end
|
15
|
+
|
16
|
+
def apply
|
17
|
+
if (v + vn) > max
|
18
|
+
applied = vn - ((v + vn) - max)
|
19
|
+
return applied < min ? min : applied
|
20
|
+
|
21
|
+
else
|
22
|
+
vn
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :v, :vn, :min, :max
|
30
|
+
|
31
|
+
end # Limit
|
32
|
+
|
33
|
+
end # Vedeu
|
@@ -11,6 +11,19 @@ module Vedeu
|
|
11
11
|
alias_method :first, :y
|
12
12
|
alias_method :last, :x
|
13
13
|
|
14
|
+
def self.coerce(value)
|
15
|
+
if value.is_a?(self)
|
16
|
+
value
|
17
|
+
|
18
|
+
elsif value.is_a?(Array)
|
19
|
+
new(*value)
|
20
|
+
|
21
|
+
else
|
22
|
+
# not sure how to proceed
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
14
27
|
# Initializes a new instance of Position.
|
15
28
|
#
|
16
29
|
# @param y [Fixnum]
|
@@ -21,6 +34,22 @@ module Vedeu
|
|
21
34
|
@x = x
|
22
35
|
end
|
23
36
|
|
37
|
+
def inspect
|
38
|
+
"<#{self.class.name} (y:#{@y} x:#{@x})>"
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param other []
|
42
|
+
# @return [Boolean]
|
43
|
+
def ==(other)
|
44
|
+
eql?(other)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @param other []
|
48
|
+
# @return [Boolean]
|
49
|
+
def eql?(other)
|
50
|
+
self.class == other.class && (x == other.x && y == other.y)
|
51
|
+
end
|
52
|
+
|
24
53
|
# Returns an escape sequence to position the cursor. When passed a block,
|
25
54
|
# will position the cursor, yield and return the original position.
|
26
55
|
#
|
@@ -215,7 +215,13 @@ module Vedeu
|
|
215
215
|
#
|
216
216
|
# @return [Fixnum]
|
217
217
|
def width
|
218
|
-
|
218
|
+
if Configuration.drb?
|
219
|
+
Configuration.drb_width
|
220
|
+
|
221
|
+
else
|
222
|
+
size.last
|
223
|
+
|
224
|
+
end
|
219
225
|
end
|
220
226
|
alias_method :xn, :width
|
221
227
|
alias_method :txn, :width
|
@@ -227,7 +233,13 @@ module Vedeu
|
|
227
233
|
#
|
228
234
|
# @return [Fixnum]
|
229
235
|
def height
|
230
|
-
|
236
|
+
if Configuration.drb?
|
237
|
+
Configuration.drb_height
|
238
|
+
|
239
|
+
else
|
240
|
+
size.first
|
241
|
+
|
242
|
+
end
|
231
243
|
end
|
232
244
|
alias_method :yn, :height
|
233
245
|
alias_method :tyn, :height
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'Running a distributed app' do
|
4
|
+
|
5
|
+
# it 'runs a simple app and exits' do
|
6
|
+
# app = Vedeu::TestApplication.build
|
7
|
+
# client = Vedeu::Distributed::Client.new("druby://localhost:21420")
|
8
|
+
# server = Vedeu::Subprocess.execute!(app)
|
9
|
+
# client.input('q')
|
10
|
+
# client.output.must_equal('')
|
11
|
+
# client.stop
|
12
|
+
# end
|
13
|
+
|
14
|
+
end
|