vedeu 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +3 -0
- data/Rakefile +16 -7
- data/examples/borders_app.rb +58 -55
- data/lib/vedeu/api.rb +1 -1
- data/lib/vedeu/application.rb +25 -25
- data/lib/vedeu/bindings.rb +5 -7
- data/lib/vedeu/configuration/api.rb +0 -2
- data/lib/vedeu/configuration/cli.rb +0 -2
- data/lib/vedeu/configuration/configuration.rb +0 -2
- data/lib/vedeu/cursor/cursor.rb +0 -2
- data/lib/vedeu/debug.rb +2 -2
- data/lib/vedeu/distributed/server.rb +0 -2
- data/lib/vedeu/dsl/components/border.rb +15 -19
- data/lib/vedeu/dsl/components/geometry.rb +14 -18
- data/lib/vedeu/dsl/components/keymap.rb +28 -32
- data/lib/vedeu/dsl/composition.rb +27 -9
- data/lib/vedeu/events/all.rb +1 -0
- data/lib/vedeu/events/event.rb +6 -8
- data/lib/vedeu/events/events.rb +10 -0
- data/lib/vedeu/events/trigger.rb +6 -12
- data/lib/vedeu/geometry/grid.rb +0 -2
- data/lib/vedeu/geometry/position.rb +0 -2
- data/lib/vedeu/geometry/position_validator.rb +0 -14
- data/lib/vedeu/input/input.rb +0 -2
- data/lib/vedeu/models/collection.rb +0 -2
- data/lib/vedeu/models/focus.rb +0 -1
- data/lib/vedeu/models/geometry.rb +7 -3
- data/lib/vedeu/models/group.rb +0 -2
- data/lib/vedeu/models/menu.rb +23 -29
- data/lib/vedeu/models/model.rb +0 -2
- data/lib/vedeu/models/view/char.rb +14 -10
- data/lib/vedeu/models/view/composition.rb +7 -9
- data/lib/vedeu/models/view/interface.rb +0 -1
- data/lib/vedeu/models/view/line.rb +2 -3
- data/lib/vedeu/models/view/stream.rb +0 -3
- data/lib/vedeu/output/all.rb +1 -0
- data/lib/vedeu/output/background.rb +0 -2
- data/lib/vedeu/output/colour.rb +0 -2
- data/lib/vedeu/output/compositor.rb +0 -2
- data/lib/vedeu/output/foreground.rb +0 -2
- data/lib/vedeu/output/html_renderer.rb +6 -0
- data/lib/vedeu/output/index_position.rb +35 -0
- data/lib/vedeu/output/output.rb +3 -1
- data/lib/vedeu/output/position_index.rb +2 -2
- data/lib/vedeu/output/presentation.rb +0 -2
- data/lib/vedeu/output/style.rb +0 -1
- data/lib/vedeu/output/translator.rb +18 -20
- data/lib/vedeu/output/viewport.rb +76 -51
- data/lib/vedeu/output/virtual_terminal.rb +2 -1
- data/lib/vedeu/repositories/all.rb +4 -4
- data/lib/vedeu/repositories/repository.rb +0 -2
- data/lib/vedeu/support/coercions.rb +0 -2
- data/lib/vedeu/support/common.rb +0 -2
- data/lib/vedeu/support/esc.rb +0 -2
- data/lib/vedeu/support/log.rb +86 -3
- data/lib/vedeu/support/refresh.rb +0 -2
- data/lib/vedeu/support/sentence.rb +5 -9
- data/lib/vedeu/support/terminal.rb +0 -2
- data/lib/vedeu/support/trace.rb +0 -2
- data/lib/vedeu/support/visible.rb +1 -1
- data/test/lib/vedeu/configuration/api_test.rb +14 -0
- data/test/lib/vedeu/configuration/configuration_test.rb +10 -0
- data/test/lib/vedeu/distributed/server_test.rb +5 -0
- data/test/lib/vedeu/dsl/components/border_test.rb +7 -0
- data/test/lib/vedeu/dsl/components/geometry_test.rb +8 -3
- data/test/lib/vedeu/dsl/interface_test.rb +5 -0
- data/test/lib/vedeu/dsl/line_test.rb +4 -0
- data/test/lib/vedeu/dsl/shared/colour_test.rb +7 -7
- data/test/lib/vedeu/dsl/shared/style_test.rb +5 -2
- data/test/lib/vedeu/dsl/stream_test.rb +4 -1
- data/test/lib/vedeu/events/event_test.rb +6 -0
- data/test/lib/vedeu/geometry/bounding_area_test.rb +30 -30
- data/test/lib/vedeu/geometry/position_test.rb +5 -0
- data/test/lib/vedeu/models/view/char_test.rb +1 -14
- data/test/lib/vedeu/output/index_position_test.rb +64 -0
- data/test/lib/vedeu/output/style_test.rb +4 -0
- data/test/lib/vedeu/output/translator_test.rb +4 -0
- data/test/lib/vedeu/output/virtual_terminal_test.rb +2 -0
- data/test/lib/vedeu/output/wordwrap_test.rb +5 -0
- data/test/lib/vedeu/repositories/all_test.rb +3 -3
- data/test/lib/vedeu/repositories/repository_test.rb +8 -0
- data/test/lib/vedeu/support/console_test.rb +14 -0
- data/test/lib/vedeu/support/esc_test.rb +6 -0
- data/test/lib/vedeu/support/terminal_test.rb +13 -0
- data/vedeu.gemspec +4 -4
- metadata +12 -24
- data/test/integration/distributed_test.rb +0 -16
- data/test/integration/dsl/compositions_test.rb +0 -19
- data/test/integration/dsl/interfaces_test.rb +0 -193
- data/test/integration/dsl/keymaps_test.rb +0 -30
- data/test/integration/dsl/lines_test.rb +0 -104
- data/test/integration/dsl/menus_test.rb +0 -59
- data/test/integration/dsl/streams_test.rb +0 -103
- data/test/integration/dsl/views_test.rb +0 -45
@@ -78,40 +78,41 @@ module Vedeu
|
|
78
78
|
def show
|
79
79
|
return [] unless lines?
|
80
80
|
|
81
|
-
|
81
|
+
padded_lines.map { |line| padded_columns(line) }.compact
|
82
82
|
end
|
83
83
|
|
84
|
-
#
|
85
|
-
# length for each viewport.
|
84
|
+
# Returns the lines, padded where necessary for the viewport.
|
86
85
|
#
|
87
86
|
# @return [Array<Array<String>>]
|
88
|
-
def
|
89
|
-
|
87
|
+
def padded_lines
|
88
|
+
visible = lines[rows] || []
|
90
89
|
|
91
|
-
|
92
|
-
visible_lines + [" "] * (height - visible_lines.size)
|
93
|
-
|
94
|
-
else
|
95
|
-
visible_lines
|
96
|
-
|
97
|
-
end
|
90
|
+
pad(visible, :height)
|
98
91
|
end
|
99
92
|
|
100
|
-
#
|
101
|
-
# length for each line.
|
93
|
+
# Returns the columns, padded where necessary for the given line.
|
102
94
|
#
|
103
95
|
# @param line [Array<String>]
|
104
96
|
# @return [Array<String>]
|
105
|
-
def
|
106
|
-
|
97
|
+
def padded_columns(line)
|
98
|
+
visible = line.chars[columns] || []
|
107
99
|
|
108
|
-
|
109
|
-
|
100
|
+
pad(visible, :width)
|
101
|
+
end
|
110
102
|
|
111
|
-
|
112
|
-
|
103
|
+
# Pads the number of rows or columns to always return an Array of the same
|
104
|
+
# length for each viewport or line respectively.
|
105
|
+
#
|
106
|
+
# @param visible [Array<Array<String>>|Array<String>]
|
107
|
+
# @param dimension [Symbol] The dimension to pad (:height or :width).
|
108
|
+
# @return [Array<Array<String>>|Array<String>]
|
109
|
+
def pad(visible, dimension)
|
110
|
+
dim = send(dimension)
|
111
|
+
size = visible.size
|
113
112
|
|
114
|
-
|
113
|
+
return visible unless size < dim
|
114
|
+
|
115
|
+
visible + [" "] * (dim - size)
|
115
116
|
end
|
116
117
|
|
117
118
|
# Using the current cursor's y position, return a range of visible lines.
|
@@ -119,24 +120,8 @@ module Vedeu
|
|
119
120
|
# Scrolls the content vertically when the stored cursor's y position for the
|
120
121
|
# interface is outside of the visible area.
|
121
122
|
#
|
122
|
-
# @note
|
123
|
-
# [value, 0].max # this allows us to set a top that is greater than
|
124
|
-
# # the content height.
|
125
|
-
#
|
126
|
-
# [[value, (content_height - height)].min, 0].max
|
127
|
-
# # this does not allow us to have a position
|
128
|
-
# # greater than the content height.
|
129
|
-
#
|
130
123
|
# @return [Range]
|
131
124
|
def rows
|
132
|
-
top = if oy >= bordered_height
|
133
|
-
[(oy - bordered_height), 0].max
|
134
|
-
|
135
|
-
else
|
136
|
-
0
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
125
|
top..(top + (height - 1))
|
141
126
|
end
|
142
127
|
|
@@ -145,27 +130,60 @@ module Vedeu
|
|
145
130
|
# Scrolls the content horizontally when the stored cursor's x position for
|
146
131
|
# the interface is outside of the visible area.
|
147
132
|
#
|
148
|
-
# @note
|
149
|
-
# [value, 0].max # this allows us to set a left that is greater
|
150
|
-
# # than the content width.
|
151
|
-
#
|
152
|
-
# [[value, (content_width - width)].min, 0].max
|
153
|
-
# # this does not allow us to have a position
|
154
|
-
# # greater than the content width.
|
155
|
-
#
|
156
133
|
# @return [Range]
|
157
134
|
def columns
|
158
|
-
left
|
159
|
-
|
135
|
+
left..(left + (width - 1))
|
136
|
+
end
|
160
137
|
|
161
|
-
|
162
|
-
|
138
|
+
# Returns the offset for the content based on the offset.
|
139
|
+
#
|
140
|
+
# @return [Fixnum]
|
141
|
+
def left
|
142
|
+
@left ||= reposition_x? ? reposition_x : 0
|
143
|
+
end
|
163
144
|
|
164
|
-
|
145
|
+
# Returns the offset for the content based on the offset.
|
146
|
+
#
|
147
|
+
# @return [Fixnum]
|
148
|
+
def top
|
149
|
+
@top ||= reposition_y? ? reposition_y : 0
|
150
|
+
end
|
165
151
|
|
166
|
-
|
152
|
+
# Returns a boolean indicating whether the x offset is greater than or equal
|
153
|
+
# to the bordered width.
|
154
|
+
#
|
155
|
+
# @return [Boolean]
|
156
|
+
def reposition_x?
|
157
|
+
ox >= bordered_width
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns a boolean indicating whether the y offset is greater than or equal
|
161
|
+
# to the bordered height.
|
162
|
+
#
|
163
|
+
# @return [Boolean]
|
164
|
+
def reposition_y?
|
165
|
+
oy >= bordered_height
|
167
166
|
end
|
168
167
|
|
168
|
+
# Returns the number of columns to change the viewport by on the x axis,
|
169
|
+
# determined by the position of the x offset.
|
170
|
+
#
|
171
|
+
# @return [Fixnum]
|
172
|
+
def reposition_x
|
173
|
+
((ox - bordered_width) <= 0) ? 0 : (ox - bordered_width)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Returns the number of rows to change the viewport by on the y axis,
|
177
|
+
# determined by the position of the y offset.
|
178
|
+
#
|
179
|
+
# @return [Fixnum]
|
180
|
+
def reposition_y
|
181
|
+
((oy - bordered_height) <= 0) ? 0 : (oy - bordered_height)
|
182
|
+
end
|
183
|
+
|
184
|
+
# When the viewport has a border, we need to account for that in our
|
185
|
+
# redrawing.
|
186
|
+
#
|
169
187
|
# @return [Fixnum]
|
170
188
|
def bordered_width
|
171
189
|
return border.width if border?
|
@@ -173,6 +191,9 @@ module Vedeu
|
|
173
191
|
width
|
174
192
|
end
|
175
193
|
|
194
|
+
# When the viewport has a border, we need to account for that in our
|
195
|
+
# redrawing.
|
196
|
+
#
|
176
197
|
# @return [Fixnum]
|
177
198
|
def bordered_height
|
178
199
|
return border.height if border?
|
@@ -180,11 +201,15 @@ module Vedeu
|
|
180
201
|
height
|
181
202
|
end
|
182
203
|
|
204
|
+
# Return the border associated with the interface we are drawing.
|
205
|
+
#
|
183
206
|
# @return [Vedeu::Border]
|
184
207
|
def border
|
185
208
|
@border ||= Vedeu.borders.find(interface.name)
|
186
209
|
end
|
187
210
|
|
211
|
+
# Returns a boolean indicating the interface we are drawing has a border.
|
212
|
+
#
|
188
213
|
# @return [Boolean]
|
189
214
|
def border?
|
190
215
|
Vedeu.borders.registered?(interface.name)
|
@@ -43,14 +43,14 @@ module Vedeu
|
|
43
43
|
|
44
44
|
# Allows the storing of events.
|
45
45
|
#
|
46
|
-
class
|
46
|
+
class EventsRepository < Repository
|
47
47
|
|
48
|
-
# @return [Vedeu::
|
48
|
+
# @return [Vedeu::EventsRepository]
|
49
49
|
def self.events
|
50
|
-
@events ||= Vedeu::
|
50
|
+
@events ||= Vedeu::EventsRepository.new(Vedeu::Events)
|
51
51
|
end
|
52
52
|
|
53
|
-
end #
|
53
|
+
end # EventsRepository
|
54
54
|
|
55
55
|
# Allows the storing of interface/view geometry independent of the interface
|
56
56
|
# instance.
|
data/lib/vedeu/support/common.rb
CHANGED
data/lib/vedeu/support/esc.rb
CHANGED
data/lib/vedeu/support/log.rb
CHANGED
@@ -2,9 +2,92 @@ require 'vedeu/configuration/configuration'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
#
|
5
|
+
# Allows the creation of a lock-less log device.
|
6
6
|
#
|
7
|
-
|
7
|
+
class MonoLogger < Logger
|
8
|
+
|
9
|
+
# Create a trappable Logger instance.
|
10
|
+
#
|
11
|
+
# @param logdev [String|IO] The filename (String) or IO object (typically
|
12
|
+
# STDOUT, STDERR or an open file).
|
13
|
+
# @param shift_age [] Number of old log files to keep, or frequency of
|
14
|
+
# rotation (daily, weekly, monthly).
|
15
|
+
# @param shift_size [] Maximum log file size (only applies when shift_age
|
16
|
+
# is a number).
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# Logger.new(name, shift_age = 7, shift_size = 1048576)
|
20
|
+
# Logger.new(name, shift_age = 'weekly')
|
21
|
+
#
|
22
|
+
def initialize(logdev, shift_age=nil, shift_size=nil)
|
23
|
+
@level = DEBUG
|
24
|
+
@default_formatter = Formatter.new
|
25
|
+
@formatter = nil
|
26
|
+
@logdev = nil
|
27
|
+
if logdev
|
28
|
+
@logdev = LocklessLogDevice.new(logdev)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Ensures we can always write to the log file by creating a lock-less
|
33
|
+
# log device.
|
34
|
+
class LocklessLogDevice < LogDevice
|
35
|
+
|
36
|
+
# @param log []
|
37
|
+
# @return []
|
38
|
+
def initialize(log = nil)
|
39
|
+
@dev = nil
|
40
|
+
@filename = nil
|
41
|
+
@shift_age = nil
|
42
|
+
@shift_size = nil
|
43
|
+
|
44
|
+
if log.respond_to?(:write) && log.respond_to?(:close)
|
45
|
+
@dev = log
|
46
|
+
|
47
|
+
else
|
48
|
+
@dev = open_logfile(log)
|
49
|
+
@dev.sync = true
|
50
|
+
@filename = log
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param message []
|
56
|
+
# @return []
|
57
|
+
def write(message)
|
58
|
+
@dev.write(message)
|
59
|
+
|
60
|
+
rescue Exception => ignored
|
61
|
+
warn("log writing failed. #{ignored}")
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return []
|
66
|
+
def close
|
67
|
+
@dev.close rescue nil
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
# @param filename []
|
73
|
+
# @return []
|
74
|
+
def open_logfile(filename)
|
75
|
+
if (FileTest.exist?(filename))
|
76
|
+
open(filename, (File::WRONLY | File::APPEND))
|
77
|
+
|
78
|
+
else
|
79
|
+
logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
|
80
|
+
logdev.sync = true
|
81
|
+
logdev
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end # LocklessLogDevice
|
87
|
+
|
88
|
+
end # MonoLogger
|
89
|
+
|
90
|
+
# Provides the ability to log anything to the Vedeu log file.
|
8
91
|
#
|
9
92
|
class Log
|
10
93
|
|
@@ -29,7 +112,7 @@ module Vedeu
|
|
29
112
|
|
30
113
|
# @return [TrueClass]
|
31
114
|
def logger
|
32
|
-
|
115
|
+
MonoLogger.new(log_file).tap do |log|
|
33
116
|
log.formatter = proc do |_, time, _, message|
|
34
117
|
formatted_message(message, time)
|
35
118
|
end
|
@@ -8,15 +8,11 @@ module Vedeu
|
|
8
8
|
#
|
9
9
|
class Sentence
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def construct(elements, label = 'elements')
|
17
|
-
new(elements, label).construct
|
18
|
-
end
|
19
|
-
|
11
|
+
# @param elements [Array]
|
12
|
+
# @param label [String]
|
13
|
+
# @return [String]
|
14
|
+
def self.construct(elements, label = 'elements')
|
15
|
+
new(elements, label).construct
|
20
16
|
end
|
21
17
|
|
22
18
|
# @param elements [Array]
|
data/lib/vedeu/support/trace.rb
CHANGED
@@ -6,9 +6,23 @@ module Vedeu
|
|
6
6
|
|
7
7
|
describe API do
|
8
8
|
|
9
|
+
let(:described) { Vedeu::Config::API }
|
10
|
+
let(:instance) { described.new }
|
11
|
+
|
9
12
|
before { Configuration.reset! }
|
10
13
|
after { test_configuration }
|
11
14
|
|
15
|
+
describe 'alias_methods' do
|
16
|
+
it { instance.must_respond_to(:interactive) }
|
17
|
+
it { instance.must_respond_to(:standalone) }
|
18
|
+
it { instance.must_respond_to(:run_once) }
|
19
|
+
it { instance.must_respond_to(:drb) }
|
20
|
+
it { instance.must_respond_to(:cooked) }
|
21
|
+
it { instance.must_respond_to(:raw) }
|
22
|
+
it { instance.must_respond_to(:debug) }
|
23
|
+
it { instance.must_respond_to(:trace) }
|
24
|
+
end
|
25
|
+
|
12
26
|
describe '.configure' do
|
13
27
|
it 'returns the configuration singleton' do
|
14
28
|
Vedeu.configure do
|