vedeu 0.6.23 → 0.6.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vedeu/borders/refresh.rb +2 -2
- data/lib/vedeu/buffers/refresh.rb +1 -3
- data/lib/vedeu/cursors/refresh.rb +3 -0
- data/lib/vedeu/editor/cropper.rb +58 -21
- data/lib/vedeu/editor/cursor.rb +18 -26
- data/lib/vedeu/editor/document.rb +41 -100
- data/lib/vedeu/models/focus.rb +2 -0
- data/lib/vedeu/models/toggleable.rb +6 -17
- data/lib/vedeu/output/clear/interface.rb +3 -3
- data/lib/vedeu/output/viewport.rb +2 -2
- data/lib/vedeu/runtime/main_loop.rb +6 -2
- data/lib/vedeu/terminal/buffer.rb +1 -1
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/editor/cropper_test.rb +67 -29
- data/test/lib/vedeu/editor/cursor_test.rb +32 -56
- data/test/lib/vedeu/editor/document_test.rb +11 -35
- data/test/lib/vedeu/models/page_test.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31ffcc8349f9218094f5a70a9aad877413bd7190
|
4
|
+
data.tar.gz: c2cba91b9c9c55055ca68aff099fb974005b6c03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e70bd67f435d4db9713ffdc8cb729463e7a7189bfd5ce4d4aa3a4d1d22c699ad3c43647d5410492632497450e51786f1a2cab57345e3b3bc7407783820c857df
|
7
|
+
data.tar.gz: d3cbb5f04bc6eb6f12d452e51c0711254f2203d82b2c929c97157a0e7c98d9d922e5443d3323bf7a69cfa92d90cf568d3ae2a461bc9759e0ebadd0551131ba42
|
@@ -57,7 +57,7 @@ module Vedeu
|
|
57
57
|
|
58
58
|
# @return [Array<Array<Vedeu::Views::Char>>]
|
59
59
|
def render
|
60
|
-
Vedeu::Output::Output.render(output) if enabled?
|
60
|
+
Vedeu::Output::Output.render(output) if enabled?
|
61
61
|
end
|
62
62
|
|
63
63
|
protected
|
@@ -75,7 +75,7 @@ module Vedeu
|
|
75
75
|
|
76
76
|
# @return [Array<Array<Vedeu::Views::Char>>]
|
77
77
|
def output
|
78
|
-
Vedeu.timer("
|
78
|
+
Vedeu.timer("Drawing border: '#{name}'") do
|
79
79
|
out = [top, bottom]
|
80
80
|
|
81
81
|
height.times { |y| out << [left(y), right(y)] }
|
@@ -42,9 +42,7 @@ module Vedeu
|
|
42
42
|
def by_name
|
43
43
|
Vedeu.trigger(:_clear_view_content_, name)
|
44
44
|
|
45
|
-
Vedeu.
|
46
|
-
Vedeu.buffers.by_name(name).render
|
47
|
-
end
|
45
|
+
Vedeu.buffers.by_name(name).render
|
48
46
|
|
49
47
|
Vedeu.trigger(:_refresh_border_, name) unless content_only?
|
50
48
|
end
|
data/lib/vedeu/editor/cropper.rb
CHANGED
@@ -7,41 +7,58 @@ module Vedeu
|
|
7
7
|
#
|
8
8
|
class Cropper
|
9
9
|
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
def_delegators :border,
|
13
|
+
:bx,
|
14
|
+
:bxn,
|
15
|
+
:by,
|
16
|
+
:byn,
|
17
|
+
:height,
|
18
|
+
:width
|
19
|
+
|
10
20
|
# Returns a new instance of Vedeu::Editor::Cropper.
|
11
21
|
#
|
12
22
|
# @param lines [Vedeu::Editor::Lines]
|
13
|
-
# @param
|
14
|
-
# @param width [Fixnum]
|
23
|
+
# @param name [String|Symbol]
|
15
24
|
# @param ox [Fixnum]
|
16
25
|
# @param oy [Fixnum]
|
17
26
|
# @return [Vedeu::Editor::Cropper]
|
18
|
-
def initialize(lines:,
|
19
|
-
@lines
|
20
|
-
@
|
21
|
-
@
|
22
|
-
@
|
23
|
-
@oy = oy
|
27
|
+
def initialize(lines:, ox:, oy:, name:)
|
28
|
+
@lines = lines
|
29
|
+
@name = name
|
30
|
+
@ox = ox
|
31
|
+
@oy = oy
|
24
32
|
end
|
25
33
|
|
26
|
-
# Returns the lines
|
27
|
-
#
|
28
|
-
# @note If there are no lines of content, we return an empty
|
29
|
-
# array. If there are any empty lines, then they are discarded.
|
34
|
+
# Returns the visible lines as a sequence of {Vedeu::View::Char}
|
35
|
+
# objects.
|
30
36
|
#
|
31
37
|
# @return [Array<void>]
|
32
|
-
def
|
33
|
-
|
38
|
+
def viewport
|
39
|
+
out = []
|
40
|
+
|
41
|
+
visible.each_with_index do |line, iy|
|
42
|
+
line.chars.each_with_index do |char, ix|
|
43
|
+
out << Vedeu::Views::Char.new(parent: interface,
|
44
|
+
position: [(by + iy), (bx + ix)],
|
45
|
+
value: char)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
out
|
34
50
|
end
|
35
51
|
|
36
|
-
|
52
|
+
# @return [Array<void>]
|
53
|
+
def to_a
|
54
|
+
visible
|
55
|
+
end
|
37
56
|
|
38
|
-
|
39
|
-
# @return [Fixnum]
|
40
|
-
attr_reader :height
|
57
|
+
protected
|
41
58
|
|
42
|
-
# @!attribute [r]
|
43
|
-
# @return [
|
44
|
-
attr_reader :
|
59
|
+
# @!attribute [r] name
|
60
|
+
# @return [String|Symbol]
|
61
|
+
attr_reader :name
|
45
62
|
|
46
63
|
# @!attribute [r] ox
|
47
64
|
# @return [Fixnum]
|
@@ -53,6 +70,16 @@ module Vedeu
|
|
53
70
|
|
54
71
|
private
|
55
72
|
|
73
|
+
# Returns the visible lines.
|
74
|
+
#
|
75
|
+
# @note If there are no lines of content, we return an empty
|
76
|
+
# array. If there are any empty lines, then they are discarded.
|
77
|
+
#
|
78
|
+
# @return [Array<void>]
|
79
|
+
def visible
|
80
|
+
lines.map { |line| columns(line) }
|
81
|
+
end
|
82
|
+
|
56
83
|
# Return a range of visible lines.
|
57
84
|
#
|
58
85
|
# @return [Vedeu::Editor::Lines]
|
@@ -60,6 +87,11 @@ module Vedeu
|
|
60
87
|
@lines[oy...(oy + height)] || []
|
61
88
|
end
|
62
89
|
|
90
|
+
# @return [Vedeu::Models::Interface]
|
91
|
+
def interface
|
92
|
+
@interface ||= Vedeu.interfaces.by_name(name)
|
93
|
+
end
|
94
|
+
|
63
95
|
# Return a range of visible characters from each line.
|
64
96
|
#
|
65
97
|
# @return [String]
|
@@ -67,6 +99,11 @@ module Vedeu
|
|
67
99
|
line[ox...(ox + width)] || ''
|
68
100
|
end
|
69
101
|
|
102
|
+
# @return [Vedeu::Borders::Border]
|
103
|
+
def border
|
104
|
+
@border ||= Vedeu.borders.by_name(name)
|
105
|
+
end
|
106
|
+
|
70
107
|
end # Editor
|
71
108
|
|
72
109
|
end # Cropper
|
data/lib/vedeu/editor/cursor.rb
CHANGED
@@ -7,21 +7,13 @@ module Vedeu
|
|
7
7
|
#
|
8
8
|
class Cursor
|
9
9
|
|
10
|
-
|
11
|
-
# @return [Fixnum]
|
12
|
-
attr_accessor :bx
|
13
|
-
|
14
|
-
# @!attribute [rw] by
|
15
|
-
# @return [Fixnum]
|
16
|
-
attr_accessor :by
|
10
|
+
extend Forwardable
|
17
11
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# @return [Fixnum]
|
24
|
-
attr_accessor :byn
|
12
|
+
def_delegators :border,
|
13
|
+
:bx,
|
14
|
+
:bxn,
|
15
|
+
:by,
|
16
|
+
:byn
|
25
17
|
|
26
18
|
# @!attribute [r] name
|
27
19
|
# @return [String|Symbol]
|
@@ -49,10 +41,6 @@ module Vedeu
|
|
49
41
|
# @option attributes y [Fixnum] The current line.
|
50
42
|
# @option attributes x [Fixnum] The current character with the
|
51
43
|
# line.
|
52
|
-
# @option attributes by [Fixnum]
|
53
|
-
# @option attributes bx [Fixnum]
|
54
|
-
# @option attributes byn [Fixnum]
|
55
|
-
# @option attributes bxn [Fixnum]
|
56
44
|
# @option attributes name [String|Symbol]
|
57
45
|
# @option attributes oy [Fixnum]
|
58
46
|
# @option attributes ox [Fixnum]
|
@@ -97,7 +85,8 @@ module Vedeu
|
|
97
85
|
# document being edited.
|
98
86
|
#
|
99
87
|
# @return [Vedeu::Editor::Cursor]
|
100
|
-
|
88
|
+
# @todo GL 2015-10-02 Should ox/oy be 0; or set to @ox/@oy?
|
89
|
+
def refresh
|
101
90
|
Vedeu::Cursors::Cursor.store(name: name,
|
102
91
|
x: real_x,
|
103
92
|
y: real_y,
|
@@ -105,6 +94,8 @@ module Vedeu
|
|
105
94
|
oy: 0,
|
106
95
|
visible: true)
|
107
96
|
|
97
|
+
Vedeu.trigger(:_refresh_cursor_, name)
|
98
|
+
|
108
99
|
self
|
109
100
|
end
|
110
101
|
|
@@ -165,20 +156,21 @@ module Vedeu
|
|
165
156
|
|
166
157
|
private
|
167
158
|
|
159
|
+
# @return [Vedeu::Borders::Border]
|
160
|
+
def border
|
161
|
+
@border ||= Vedeu.borders.by_name(name)
|
162
|
+
end
|
163
|
+
|
168
164
|
# Returns the default options/attributes for this class.
|
169
165
|
#
|
170
|
-
# @return [Hash<Symbol => Fixnum|NilClass>]
|
166
|
+
# @return [Hash<Symbol => Fixnum|NilClass|String|Symbol>]
|
171
167
|
def defaults
|
172
168
|
{
|
173
|
-
y: 0,
|
174
|
-
x: 0,
|
175
|
-
by: nil,
|
176
|
-
bx: nil,
|
177
|
-
byn: nil,
|
178
|
-
bxn: nil,
|
179
169
|
name: '',
|
180
170
|
ox: 0,
|
181
171
|
oy: 0,
|
172
|
+
x: 0,
|
173
|
+
y: 0,
|
182
174
|
}
|
183
175
|
end
|
184
176
|
|
@@ -9,25 +9,12 @@ module Vedeu
|
|
9
9
|
include Vedeu::Repositories::Model
|
10
10
|
extend Forwardable
|
11
11
|
|
12
|
-
def_delegators :border,
|
13
|
-
:bx,
|
14
|
-
:bxn,
|
15
|
-
:by,
|
16
|
-
:byn,
|
17
|
-
:height,
|
18
|
-
:width
|
19
|
-
|
20
12
|
def_delegators :cursor,
|
21
|
-
:bol,
|
22
13
|
:ox,
|
23
14
|
:oy,
|
24
15
|
:x,
|
25
16
|
:y
|
26
17
|
|
27
|
-
def_delegators :interface,
|
28
|
-
:colour,
|
29
|
-
:style
|
30
|
-
|
31
18
|
# @!attribute [r] attributes
|
32
19
|
# @return [Hash]
|
33
20
|
attr_reader :attributes
|
@@ -54,13 +41,6 @@ module Vedeu
|
|
54
41
|
end
|
55
42
|
end
|
56
43
|
|
57
|
-
# Clear the document content in the terminal.
|
58
|
-
#
|
59
|
-
# @return [void]
|
60
|
-
def clear
|
61
|
-
Vedeu.trigger(:_clear_view_content_, name)
|
62
|
-
end
|
63
|
-
|
64
44
|
# Deletes the character from the line where the cursor is
|
65
45
|
# currently positioned.
|
66
46
|
#
|
@@ -69,8 +49,6 @@ module Vedeu
|
|
69
49
|
@lines = lines.delete_character(y, x - 1)
|
70
50
|
|
71
51
|
left
|
72
|
-
|
73
|
-
refresh
|
74
52
|
end
|
75
53
|
|
76
54
|
# Delete a line.
|
@@ -82,15 +60,6 @@ module Vedeu
|
|
82
60
|
up
|
83
61
|
end
|
84
62
|
|
85
|
-
# Move the virtual cursor down.
|
86
|
-
#
|
87
|
-
# @return [Vedeu::Editor::Document]
|
88
|
-
def down
|
89
|
-
cursor.down
|
90
|
-
|
91
|
-
refresh
|
92
|
-
end
|
93
|
-
|
94
63
|
# Returns the document as a string with line breaks if there is
|
95
64
|
# more than one line.
|
96
65
|
#
|
@@ -100,7 +69,7 @@ module Vedeu
|
|
100
69
|
|
101
70
|
reset!
|
102
71
|
|
103
|
-
|
72
|
+
Vedeu.trigger(:_clear_view_content_, name)
|
104
73
|
|
105
74
|
Vedeu.trigger(:_command_, command)
|
106
75
|
|
@@ -129,17 +98,6 @@ module Vedeu
|
|
129
98
|
@lines = lines.insert_line(Vedeu::Editor::Line.new, y)
|
130
99
|
|
131
100
|
bol
|
132
|
-
|
133
|
-
refresh
|
134
|
-
end
|
135
|
-
|
136
|
-
# Move the virtual cursor left.
|
137
|
-
#
|
138
|
-
# @return [Vedeu::Editor::Document]
|
139
|
-
def left
|
140
|
-
cursor.left
|
141
|
-
|
142
|
-
refresh
|
143
101
|
end
|
144
102
|
|
145
103
|
# Returns the current line from the collection of lines.
|
@@ -157,15 +115,6 @@ module Vedeu
|
|
157
115
|
@lines ||= Vedeu::Editor::Lines.coerce(data)
|
158
116
|
end
|
159
117
|
|
160
|
-
# Render the document content in the terminal.
|
161
|
-
#
|
162
|
-
# @return [void]
|
163
|
-
def render
|
164
|
-
clear
|
165
|
-
|
166
|
-
Vedeu::Output::Output.render(output)
|
167
|
-
end
|
168
|
-
|
169
118
|
# Reset the document to the empty state.
|
170
119
|
#
|
171
120
|
# @return [Vedeu::Editor::Document]
|
@@ -178,17 +127,30 @@ module Vedeu
|
|
178
127
|
end
|
179
128
|
|
180
129
|
# Store the document in the documents repository, clear and
|
181
|
-
#
|
130
|
+
# send the content to the terminal.
|
182
131
|
#
|
183
132
|
# @return [Vedeu::Editor::Document]
|
184
133
|
def refresh
|
185
134
|
store
|
186
135
|
|
187
|
-
|
136
|
+
Vedeu.trigger(:_clear_view_content_, name)
|
137
|
+
|
138
|
+
Vedeu::Output::Output.render(output)
|
139
|
+
|
140
|
+
cursor.refresh
|
188
141
|
|
189
142
|
self
|
190
143
|
end
|
191
144
|
|
145
|
+
# Move the virtual cursor left.
|
146
|
+
#
|
147
|
+
# @return [Vedeu::Editor::Document]
|
148
|
+
def left
|
149
|
+
cursor.left
|
150
|
+
|
151
|
+
refresh
|
152
|
+
end
|
153
|
+
|
192
154
|
# Move the virtual cursor right.
|
193
155
|
#
|
194
156
|
# @return [Vedeu::Editor::Document]
|
@@ -207,21 +169,26 @@ module Vedeu
|
|
207
169
|
refresh
|
208
170
|
end
|
209
171
|
|
210
|
-
|
211
|
-
|
212
|
-
# Retrieve the dimensions of the document from the interface of
|
213
|
-
# the same name.
|
172
|
+
# Move the virtual cursor down.
|
214
173
|
#
|
215
|
-
# @return [Vedeu::
|
216
|
-
def
|
217
|
-
|
174
|
+
# @return [Vedeu::Editor::Document]
|
175
|
+
def down
|
176
|
+
cursor.down
|
177
|
+
|
178
|
+
refresh
|
218
179
|
end
|
219
180
|
|
220
|
-
#
|
221
|
-
|
222
|
-
|
181
|
+
# Move the virtual cursor to the beginning of the line.
|
182
|
+
#
|
183
|
+
# @return [Vedeu::Editor::Document]
|
184
|
+
def bol
|
185
|
+
cursor.bol
|
186
|
+
|
187
|
+
refresh
|
223
188
|
end
|
224
189
|
|
190
|
+
private
|
191
|
+
|
225
192
|
# Returns the default options/attributes for this class.
|
226
193
|
#
|
227
194
|
# @return [Hash<Symbol => void|Symbol]
|
@@ -233,25 +200,17 @@ module Vedeu
|
|
233
200
|
}
|
234
201
|
end
|
235
202
|
|
236
|
-
# Return the data needed to render the document
|
203
|
+
# Return the data needed to render the document, based on the
|
204
|
+
# current virtual cursor position. This output may be a cropped
|
205
|
+
# representation of the full document depending on the size of
|
206
|
+
# the interface.
|
237
207
|
#
|
238
|
-
# @return [
|
208
|
+
# @return [Array<Vedeu::Views::Char>]
|
239
209
|
def output
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
position = [(by + y_index), (bx + x_index)]
|
245
|
-
|
246
|
-
out << Vedeu::Views::Char.new(value: char,
|
247
|
-
parent: interface,
|
248
|
-
position: position)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
cursor.store
|
253
|
-
|
254
|
-
out.flatten
|
210
|
+
Vedeu::Editor::Cropper.new(lines: lines,
|
211
|
+
name: name,
|
212
|
+
ox: ox,
|
213
|
+
oy: oy).viewport
|
255
214
|
end
|
256
215
|
|
257
216
|
# Return a virtual cursor to track the cursor position within
|
@@ -259,25 +218,7 @@ module Vedeu
|
|
259
218
|
#
|
260
219
|
# @return [Vedeu::Editor::Cursor]
|
261
220
|
def cursor
|
262
|
-
@cursor ||= Vedeu::Editor::Cursor.new(
|
263
|
-
x: 0,
|
264
|
-
by: by,
|
265
|
-
bx: bx,
|
266
|
-
byn: byn,
|
267
|
-
bxn: bxn,
|
268
|
-
name: name)
|
269
|
-
end
|
270
|
-
|
271
|
-
# Return only the visible lines for the document based on the
|
272
|
-
# current virtual cursor position.
|
273
|
-
#
|
274
|
-
# @return [Vedeu::Editor::Lines]
|
275
|
-
def visible_lines
|
276
|
-
Vedeu::Editor::Cropper.new(lines: lines,
|
277
|
-
height: height,
|
278
|
-
width: width,
|
279
|
-
ox: ox,
|
280
|
-
oy: oy).cropped
|
221
|
+
@cursor ||= Vedeu::Editor::Cursor.new(name: name)
|
281
222
|
end
|
282
223
|
|
283
224
|
end # Document
|
data/lib/vedeu/models/focus.rb
CHANGED
@@ -55,8 +55,8 @@ module Vedeu
|
|
55
55
|
#
|
56
56
|
# @param name [String|Symbol]
|
57
57
|
# @return [void]
|
58
|
-
def hide(name =
|
59
|
-
|
58
|
+
def hide(name = Vedeu.focus)
|
59
|
+
repository.by_name(name).hide
|
60
60
|
end
|
61
61
|
alias_method :hide_cursor, :hide
|
62
62
|
alias_method :hide_group, :hide
|
@@ -71,8 +71,8 @@ module Vedeu
|
|
71
71
|
#
|
72
72
|
# @param name [String|Symbol]
|
73
73
|
# @return [void]
|
74
|
-
def show(name =
|
75
|
-
|
74
|
+
def show(name = Vedeu.focus)
|
75
|
+
repository.by_name(name).show
|
76
76
|
end
|
77
77
|
alias_method :show_cursor, :show
|
78
78
|
alias_method :show_group, :show
|
@@ -87,24 +87,13 @@ module Vedeu
|
|
87
87
|
#
|
88
88
|
# @param name [String|Symbol]
|
89
89
|
# @return [void]
|
90
|
-
def toggle(name =
|
91
|
-
|
90
|
+
def toggle(name = Vedeu.focus)
|
91
|
+
repository.by_name(name).toggle
|
92
92
|
end
|
93
93
|
alias_method :toggle_cursor, :toggle
|
94
94
|
alias_method :toggle_group, :toggle
|
95
95
|
alias_method :toggle_interface, :toggle
|
96
96
|
|
97
|
-
private
|
98
|
-
|
99
|
-
# Fetch the model by name.
|
100
|
-
#
|
101
|
-
# @param name [String|Symbol]
|
102
|
-
# @param klass [void] The repository of the model.
|
103
|
-
# @return [void]
|
104
|
-
def model_by_name(klass, name = nil)
|
105
|
-
klass.by_name(name || Vedeu.focus)
|
106
|
-
end
|
107
|
-
|
108
97
|
end # ClassMethods
|
109
98
|
|
110
99
|
# When this module is included in a class, provide ClassMethods as
|
@@ -51,7 +51,7 @@ module Vedeu
|
|
51
51
|
|
52
52
|
# @return [Array<Array<Vedeu::Views::Char>>]
|
53
53
|
def render
|
54
|
-
Vedeu::Output::Output.render(output)
|
54
|
+
Vedeu::Output::Output.render(output)
|
55
55
|
end
|
56
56
|
|
57
57
|
protected
|
@@ -132,9 +132,9 @@ module Vedeu
|
|
132
132
|
|
133
133
|
# @return [String]
|
134
134
|
def clearing
|
135
|
-
return '
|
135
|
+
return 'content' if content_only?
|
136
136
|
|
137
|
-
'
|
137
|
+
'interface'
|
138
138
|
end
|
139
139
|
|
140
140
|
# @return [Fixnum]
|
@@ -44,7 +44,7 @@ module Vedeu
|
|
44
44
|
#
|
45
45
|
# @return [Array<Array<String>>|NilClass]
|
46
46
|
def render
|
47
|
-
Vedeu::Output::Output.render(output) if visible?
|
47
|
+
Vedeu::Output::Output.render(output) if visible?
|
48
48
|
end
|
49
49
|
|
50
50
|
# Returns a string representation of the viewport.
|
@@ -65,7 +65,7 @@ module Vedeu
|
|
65
65
|
|
66
66
|
# @return [Array<Array<Vedeu::Views::Char>>]
|
67
67
|
def output
|
68
|
-
Vedeu.timer("Rendering: '#{name}'") do
|
68
|
+
Vedeu.timer("Rendering content: '#{name}'") do
|
69
69
|
out = []
|
70
70
|
|
71
71
|
show.each_with_index do |line, iy|
|
@@ -13,6 +13,7 @@ module Vedeu
|
|
13
13
|
class << self
|
14
14
|
|
15
15
|
# :nocov:
|
16
|
+
|
16
17
|
# Start the main loop.
|
17
18
|
#
|
18
19
|
# @return [void]
|
@@ -21,9 +22,9 @@ module Vedeu
|
|
21
22
|
@started = true
|
22
23
|
@loop = true
|
23
24
|
|
24
|
-
|
25
|
-
Vedeu.trigger(:_refresh_cursor_, Vedeu.focus)
|
25
|
+
Vedeu.trigger(:_refresh_cursor_, Vedeu.focus)
|
26
26
|
|
27
|
+
while @loop
|
27
28
|
yield
|
28
29
|
|
29
30
|
safe_exit_point!
|
@@ -32,6 +33,7 @@ module Vedeu
|
|
32
33
|
Vedeu.log(type: :info,
|
33
34
|
message: 'Vedeu execution interrupted, exiting.')
|
34
35
|
end
|
36
|
+
|
35
37
|
# :nocov:
|
36
38
|
|
37
39
|
# Signal that we wish to terminate the running application.
|
@@ -42,6 +44,7 @@ module Vedeu
|
|
42
44
|
end
|
43
45
|
|
44
46
|
# :nocov:
|
47
|
+
|
45
48
|
# Check the application has started and we wish to continue
|
46
49
|
# running.
|
47
50
|
#
|
@@ -51,6 +54,7 @@ module Vedeu
|
|
51
54
|
def safe_exit_point!
|
52
55
|
fail Vedeu::Error::Interrupt if @started && !@loop
|
53
56
|
end
|
57
|
+
|
54
58
|
# :nocov:
|
55
59
|
|
56
60
|
end # Eigenclass
|
data/lib/vedeu/version.rb
CHANGED
@@ -8,29 +8,43 @@ module Vedeu
|
|
8
8
|
|
9
9
|
let(:described) { Vedeu::Editor::Cropper }
|
10
10
|
let(:instance) {
|
11
|
-
described.new(lines:
|
12
|
-
height: height,
|
13
|
-
width: width,
|
14
|
-
ox: ox,
|
15
|
-
oy: oy)
|
11
|
+
described.new(lines: lines, name: _name, ox: ox, oy: oy)
|
16
12
|
}
|
13
|
+
let(:_name) { 'editor_cropper' }
|
17
14
|
let(:lines) { Vedeu::Editor::Lines.new }
|
18
|
-
let(:height) { 3 }
|
19
|
-
let(:width) { 5 }
|
20
15
|
let(:ox) { 1 }
|
21
16
|
let(:oy) { 1 }
|
22
17
|
|
18
|
+
let(:border) {
|
19
|
+
Vedeu::Borders::Border.new(name: _name, enabled: false)
|
20
|
+
}
|
21
|
+
let(:geometry) {
|
22
|
+
Vedeu::Geometry::Geometry.new(name: _name,
|
23
|
+
x: 1,
|
24
|
+
y: 1,
|
25
|
+
xn: 5,
|
26
|
+
yn: 3)
|
27
|
+
}
|
28
|
+
let(:interface) {
|
29
|
+
Vedeu::Models::Interface.new(name: _name)
|
30
|
+
}
|
31
|
+
|
32
|
+
before do
|
33
|
+
Vedeu.geometries.stubs(:by_name).with(_name).returns(geometry)
|
34
|
+
Vedeu.borders.stubs(:by_name).with(_name).returns(border)
|
35
|
+
Vedeu.interfaces.stubs(:by_name).with(_name).returns(interface)
|
36
|
+
end
|
37
|
+
|
23
38
|
describe '#initialize' do
|
24
39
|
it { instance.must_be_instance_of(described) }
|
25
40
|
it { instance.instance_variable_get('@lines').must_equal(lines) }
|
26
|
-
it { instance.instance_variable_get('@
|
27
|
-
it { instance.instance_variable_get('@width').must_equal(width) }
|
41
|
+
it { instance.instance_variable_get('@name').must_equal(_name) }
|
28
42
|
it { instance.instance_variable_get('@ox').must_equal(ox) }
|
29
43
|
it { instance.instance_variable_get('@oy').must_equal(oy) }
|
30
44
|
end
|
31
45
|
|
32
|
-
describe '#
|
33
|
-
subject { instance.
|
46
|
+
describe '#to_a' do
|
47
|
+
subject { instance.to_a }
|
34
48
|
|
35
49
|
context 'when there are no lines' do
|
36
50
|
let(:lines) { Vedeu::Editor::Lines.new }
|
@@ -50,30 +64,54 @@ module Vedeu
|
|
50
64
|
}
|
51
65
|
|
52
66
|
it { subject.must_equal(['elium', 'ithiu', 'eryll']) }
|
67
|
+
end
|
68
|
+
end
|
53
69
|
|
54
|
-
|
55
|
-
|
70
|
+
# describe '#viewport' do
|
71
|
+
# subject { instance.viewport }
|
56
72
|
|
57
|
-
|
58
|
-
|
73
|
+
# context 'when there are no lines' do
|
74
|
+
# let(:lines) { Vedeu::Editor::Lines.new }
|
59
75
|
|
60
|
-
|
61
|
-
|
62
|
-
let(:ox) { 10 }
|
76
|
+
# it { subject.must_equal([]) }
|
77
|
+
# end
|
63
78
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
79
|
+
# context 'when there are lines' do
|
80
|
+
# let(:lines) {
|
81
|
+
# Vedeu::Editor::Lines.new([
|
82
|
+
# Vedeu::Editor::Line.new('Hydrogen'),
|
83
|
+
# Vedeu::Editor::Line.new('Helium'),
|
84
|
+
# Vedeu::Editor::Line.new('Lithium'),
|
85
|
+
# Vedeu::Editor::Line.new('Beryllium'),
|
86
|
+
# Vedeu::Editor::Line.new('Boron'),
|
87
|
+
# ])
|
88
|
+
# }
|
68
89
|
|
69
|
-
|
70
|
-
let(:oy) { 10 }
|
71
|
-
let(:ox) { 20 }
|
90
|
+
# it { subject.must_equal(['elium', 'ithiu', 'eryll']) }
|
72
91
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
92
|
+
# context 'when oy is near the bottom' do
|
93
|
+
# let(:oy) { 6 }
|
94
|
+
|
95
|
+
# it { subject.must_equal([]) }
|
96
|
+
# end
|
97
|
+
|
98
|
+
# context 'when ox is nearly past the content width' do
|
99
|
+
# let(:oy) { 5 }
|
100
|
+
# let(:ox) { 10 }
|
101
|
+
|
102
|
+
# it 'returns only that which is visible, discarding empty lines' do
|
103
|
+
# subject.must_equal([])
|
104
|
+
# end
|
105
|
+
# end
|
106
|
+
|
107
|
+
# context 'when both oy and ox are effectively out of range' do
|
108
|
+
# let(:oy) { 10 }
|
109
|
+
# let(:ox) { 20 }
|
110
|
+
|
111
|
+
# it { subject.must_equal([]) }
|
112
|
+
# end
|
113
|
+
# end
|
114
|
+
# end
|
77
115
|
|
78
116
|
end # Cropper
|
79
117
|
|
@@ -10,78 +10,47 @@ module Vedeu
|
|
10
10
|
let(:instance) { described.new(attributes) }
|
11
11
|
let(:attributes) {
|
12
12
|
{
|
13
|
-
y: y,
|
14
|
-
x: x,
|
15
|
-
bx: bx,
|
16
|
-
by: by,
|
17
|
-
byn: byn,
|
18
|
-
bxn: bxn,
|
19
13
|
name: _name,
|
14
|
+
ox: ox,
|
20
15
|
oy: oy,
|
21
|
-
|
16
|
+
x: x,
|
17
|
+
y: y,
|
22
18
|
}
|
23
19
|
}
|
24
|
-
let(:
|
25
|
-
let(:
|
26
|
-
let(:
|
27
|
-
let(:
|
28
|
-
let(:
|
29
|
-
|
30
|
-
let(:
|
31
|
-
|
32
|
-
|
20
|
+
let(:_name) { 'editor_cursor' }
|
21
|
+
let(:ox) { 0 }
|
22
|
+
let(:oy) { 0 }
|
23
|
+
let(:x) { 0 }
|
24
|
+
let(:y) { 0 }
|
25
|
+
|
26
|
+
let(:border) {
|
27
|
+
Vedeu::Borders::Border.new(name: _name, enabled: false)
|
28
|
+
}
|
29
|
+
let(:geometry) {
|
30
|
+
Vedeu::Geometry::Geometry.new(name: _name,
|
31
|
+
x: 1,
|
32
|
+
y: 1,
|
33
|
+
xn: 6,
|
34
|
+
yn: 6)
|
35
|
+
}
|
33
36
|
|
34
37
|
describe '#initialize' do
|
35
38
|
it { instance.must_be_instance_of(described) }
|
36
39
|
it { instance.instance_variable_get('@y').must_equal(y) }
|
37
40
|
it { instance.instance_variable_get('@x').must_equal(x) }
|
38
|
-
it { instance.instance_variable_get('@by').must_equal(by) }
|
39
|
-
it { instance.instance_variable_get('@bx').must_equal(bx) }
|
40
|
-
it { instance.instance_variable_get('@byn').must_equal(byn) }
|
41
|
-
it { instance.instance_variable_get('@bxn').must_equal(bxn) }
|
42
41
|
it { instance.instance_variable_get('@name').must_equal(_name) }
|
43
42
|
it { instance.instance_variable_get('@oy').must_equal(0) }
|
44
43
|
it { instance.instance_variable_get('@ox').must_equal(0) }
|
45
|
-
|
46
|
-
context 'when x is nil' do
|
47
|
-
it { instance.instance_variable_get('@x').must_equal(0) }
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when x is not nil' do
|
51
|
-
let(:x) { 3 }
|
52
|
-
|
53
|
-
it { instance.instance_variable_get('@x').must_equal(3) }
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'when y is nil' do
|
57
|
-
it { instance.instance_variable_get('@y').must_equal(0) }
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when y is not nil' do
|
61
|
-
let(:y) { 6 }
|
62
|
-
|
63
|
-
it { instance.instance_variable_get('@y').must_equal(6) }
|
64
|
-
end
|
65
44
|
end
|
66
45
|
|
67
46
|
describe '#accessors' do
|
68
47
|
it {
|
69
|
-
instance.must_respond_to(:bx)
|
70
|
-
instance.must_respond_to(:bx=)
|
71
|
-
instance.must_respond_to(:by)
|
72
|
-
instance.must_respond_to(:by=)
|
73
|
-
instance.must_respond_to(:bxn)
|
74
|
-
instance.must_respond_to(:bxn=)
|
75
|
-
instance.must_respond_to(:byn)
|
76
|
-
instance.must_respond_to(:byn=)
|
77
48
|
instance.must_respond_to(:name)
|
78
49
|
instance.must_respond_to(:ox)
|
79
50
|
instance.must_respond_to(:ox=)
|
80
51
|
instance.must_respond_to(:oy)
|
81
52
|
instance.must_respond_to(:oy=)
|
82
|
-
instance.must_respond_to(:x)
|
83
53
|
instance.must_respond_to(:x=)
|
84
|
-
instance.must_respond_to(:y)
|
85
54
|
instance.must_respond_to(:y=)
|
86
55
|
}
|
87
56
|
end
|
@@ -120,13 +89,18 @@ module Vedeu
|
|
120
89
|
it { subject.ox.must_equal(3) }
|
121
90
|
end
|
122
91
|
|
123
|
-
describe '#
|
124
|
-
before {
|
92
|
+
describe '#refresh' do
|
93
|
+
before {
|
94
|
+
Vedeu::Cursors::Cursor.stubs(:store)
|
95
|
+
Vedeu.stubs(:trigger)
|
96
|
+
}
|
125
97
|
|
126
|
-
subject { instance.
|
98
|
+
subject { instance.refresh }
|
127
99
|
|
128
100
|
it 'stores the virtual cursor in place of the real cursor' do
|
129
101
|
Vedeu::Cursors::Cursor.expects(:store)
|
102
|
+
Vedeu.expects(:trigger).with(:_refresh_cursor_, _name)
|
103
|
+
|
130
104
|
subject.must_be_instance_of(described)
|
131
105
|
end
|
132
106
|
end
|
@@ -157,14 +131,16 @@ module Vedeu
|
|
157
131
|
end
|
158
132
|
|
159
133
|
describe '#to_s' do
|
160
|
-
let(:x)
|
161
|
-
let(:y)
|
134
|
+
let(:x) { 11 }
|
135
|
+
let(:y) { 5 }
|
136
|
+
let(:ox) { 0 }
|
137
|
+
let(:oy) { 0 }
|
162
138
|
|
163
139
|
subject { instance.to_s }
|
164
140
|
|
165
141
|
it { subject.must_be_instance_of(String) }
|
166
142
|
|
167
|
-
it { subject.must_equal("\e[6;
|
143
|
+
it { subject.must_equal("\e[6;12H\e[?25h") }
|
168
144
|
end
|
169
145
|
|
170
146
|
describe '#up' do
|
@@ -58,17 +58,6 @@ module Vedeu
|
|
58
58
|
}
|
59
59
|
end
|
60
60
|
|
61
|
-
describe '#clear' do
|
62
|
-
before { Vedeu.stubs(:trigger).with(:_clear_view_content_, _name) }
|
63
|
-
|
64
|
-
subject { instance.clear }
|
65
|
-
|
66
|
-
it {
|
67
|
-
Vedeu.expects(:trigger).with(:_clear_view_content_, _name)
|
68
|
-
subject
|
69
|
-
}
|
70
|
-
end
|
71
|
-
|
72
61
|
describe '#delete_character' do
|
73
62
|
let(:y) { 0 }
|
74
63
|
let(:x) { 0 }
|
@@ -172,29 +161,6 @@ module Vedeu
|
|
172
161
|
it { subject.must_equal(expected) }
|
173
162
|
end
|
174
163
|
|
175
|
-
describe '#render' do
|
176
|
-
let(:data) {
|
177
|
-
Vedeu::Editor::Lines.new([
|
178
|
-
Vedeu::Editor::Line.new('A'),
|
179
|
-
Vedeu::Editor::Line.new('B'),
|
180
|
-
Vedeu::Editor::Line.new('C'),
|
181
|
-
])
|
182
|
-
}
|
183
|
-
let(:output) { "\e[1;1HA\e[2;1HB\e[3;1HC\e[1;1H\e[?25h" }
|
184
|
-
|
185
|
-
before {
|
186
|
-
Vedeu.stubs(:trigger).with(:_clear_view_content_, _name)
|
187
|
-
Vedeu::Output::Output.stubs(:render)
|
188
|
-
}
|
189
|
-
|
190
|
-
subject { instance.render }
|
191
|
-
|
192
|
-
it {
|
193
|
-
Vedeu::Output::Output.expects(:render)
|
194
|
-
subject
|
195
|
-
}
|
196
|
-
end
|
197
|
-
|
198
164
|
describe '#reset!' do
|
199
165
|
subject { instance.reset! }
|
200
166
|
|
@@ -202,12 +168,22 @@ module Vedeu
|
|
202
168
|
end
|
203
169
|
|
204
170
|
describe '#refresh' do
|
171
|
+
before do
|
172
|
+
Vedeu.stubs(:trigger)
|
173
|
+
Vedeu::Output::Output.stubs(:render)
|
174
|
+
end
|
175
|
+
|
205
176
|
subject { instance.refresh }
|
206
177
|
|
207
178
|
it { subject.must_be_instance_of(described) }
|
208
179
|
|
209
180
|
it {
|
210
|
-
|
181
|
+
Vedeu.expects(:trigger).with(:_clear_view_content_, _name)
|
182
|
+
subject
|
183
|
+
}
|
184
|
+
|
185
|
+
it {
|
186
|
+
Vedeu::Output::Output.expects(:render)
|
211
187
|
subject
|
212
188
|
}
|
213
189
|
end
|