vedeu 0.4.10 → 0.4.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/cursor_app.rb +3 -2
- data/lib/vedeu/cursor/refresh_cursor.rb +3 -16
- data/lib/vedeu/dsl/components/border.rb +18 -0
- data/lib/vedeu/models/char.rb +2 -2
- data/lib/vedeu/output/border.rb +65 -68
- data/test/lib/vedeu/dsl/components/border_test.rb +9 -0
- data/test/lib/vedeu/output/border_test.rb +1 -0
- data/vedeu.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd5267f472bd0bcb05b29671a3e36b44ea4ec8d7
|
4
|
+
data.tar.gz: 1781dce30836a25b700ca8598728b5733f31ff1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9a413311537e668d1a65a28a21e5b20b1dc11bfe5446a502cd2c6735e7c7db28ca758ce8842155974742a9d6a6e7f1cae3212e685477e40b35f37e747aef3d3
|
7
|
+
data.tar.gz: cd9da8bd56aa811eaa945a24940e91056cfda503246877f287b27e73e19959fd16faf00f404a382e5efcc0a564b8f3e30f6164d9504ab244259030c34edf1dde
|
data/examples/cursor_app.rb
CHANGED
@@ -22,8 +22,8 @@ class VedeuCursorApp
|
|
22
22
|
|
23
23
|
geometry do
|
24
24
|
centred true
|
25
|
-
height
|
26
|
-
width
|
25
|
+
height 10
|
26
|
+
width 10
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -38,6 +38,7 @@ class VedeuCursorApp
|
|
38
38
|
view 'main_interface' do
|
39
39
|
border do
|
40
40
|
colour foreground: '#aadd00', background: '#000000'
|
41
|
+
title 'Move!'
|
41
42
|
end
|
42
43
|
lines do
|
43
44
|
streams do
|
@@ -33,8 +33,7 @@ module Vedeu
|
|
33
33
|
|
34
34
|
# @return [Boolean]
|
35
35
|
def refresh_view?
|
36
|
-
new_cursor.ox >= interface_width ||
|
37
|
-
new_cursor.oy >= interface_height
|
36
|
+
new_cursor.ox >= interface_width || new_cursor.oy >= interface_height
|
38
37
|
end
|
39
38
|
|
40
39
|
# @return [Vedeu::Cursor]
|
@@ -64,24 +63,12 @@ module Vedeu
|
|
64
63
|
|
65
64
|
# @return [Fixnum]
|
66
65
|
def interface_height
|
67
|
-
|
68
|
-
interface.border.height
|
69
|
-
|
70
|
-
else
|
71
|
-
interface.height
|
72
|
-
|
73
|
-
end
|
66
|
+
interface.border.height
|
74
67
|
end
|
75
68
|
|
76
69
|
# @return [Fixnum]
|
77
70
|
def interface_width
|
78
|
-
|
79
|
-
interface.border.width
|
80
|
-
|
81
|
-
else
|
82
|
-
interface.width
|
83
|
-
|
84
|
-
end
|
71
|
+
interface.border.width
|
85
72
|
end
|
86
73
|
|
87
74
|
# @return [Vedeu::Interface]
|
@@ -195,6 +195,24 @@ module Vedeu
|
|
195
195
|
right(true)
|
196
196
|
end
|
197
197
|
|
198
|
+
# If you have you are showing a top border, you could add a title.
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
# Vedeu.renders do
|
202
|
+
# view 'border_demo' do
|
203
|
+
# geometry { width: 50 }
|
204
|
+
# border do
|
205
|
+
# title 'My Cool Title'
|
206
|
+
# # ...
|
207
|
+
#
|
208
|
+
# +- My Cool Title --------------------------------+
|
209
|
+
#
|
210
|
+
# @param value [String] The title.
|
211
|
+
# @return [String]
|
212
|
+
def title(value)
|
213
|
+
model.title = value
|
214
|
+
end
|
215
|
+
|
198
216
|
# Enable/disable the top border.
|
199
217
|
#
|
200
218
|
# @example
|
data/lib/vedeu/models/char.rb
CHANGED
data/lib/vedeu/output/border.rb
CHANGED
@@ -13,6 +13,7 @@ module Vedeu
|
|
13
13
|
#
|
14
14
|
class Border
|
15
15
|
|
16
|
+
include Vedeu::Common
|
16
17
|
include Vedeu::Model
|
17
18
|
|
18
19
|
# @!attribute [rw] attributes
|
@@ -51,6 +52,10 @@ module Vedeu
|
|
51
52
|
attr_accessor :show_top
|
52
53
|
alias_method :top?, :show_top
|
53
54
|
|
55
|
+
# @!attribute [rw] title
|
56
|
+
# @return [String]
|
57
|
+
attr_accessor :title
|
58
|
+
|
54
59
|
# @!attribute [rw] top_left
|
55
60
|
# @return [String]
|
56
61
|
attr_accessor :top_left
|
@@ -90,7 +95,8 @@ module Vedeu
|
|
90
95
|
# @option attributes enabled [Boolean] Indicate whether the border is to be
|
91
96
|
# shown for this interface.
|
92
97
|
# @option attributes horizontal [String] The horizontal border character.
|
93
|
-
# @option attributes name [String]
|
98
|
+
# @option attributes name [String] The name of the interface to which this
|
99
|
+
# border relates.
|
94
100
|
# @option attributes style []
|
95
101
|
# @option attributes show_bottom [Boolean] Indicate whether the bottom
|
96
102
|
# border is to be shown.
|
@@ -100,6 +106,8 @@ module Vedeu
|
|
100
106
|
# is to be shown.
|
101
107
|
# @option attributes show_top [Boolean] Indicate whether the top border is
|
102
108
|
# to be shown.
|
109
|
+
# @option attributes title [String] A title bar for when the top border is
|
110
|
+
# to be shown.
|
103
111
|
# @option attributes top_left [String] The top left border character.
|
104
112
|
# @option attributes top_right [String] The top right border character.
|
105
113
|
# @option attributes vertical [String] The vertical border character.
|
@@ -113,6 +121,7 @@ module Vedeu
|
|
113
121
|
@show_left = @attributes[:show_left]
|
114
122
|
@show_right = @attributes[:show_right]
|
115
123
|
@show_top = @attributes[:show_top]
|
124
|
+
@title = @attributes[:title]
|
116
125
|
@top_left = @attributes[:top_left]
|
117
126
|
@top_right = @attributes[:top_right]
|
118
127
|
@horizontal = @attributes[:horizontal]
|
@@ -125,46 +134,30 @@ module Vedeu
|
|
125
134
|
|
126
135
|
# @return [Fixnum]
|
127
136
|
def bx
|
128
|
-
|
129
|
-
interface.x + 1
|
137
|
+
bo = (enabled? && left?) ? 1 : 0
|
130
138
|
|
131
|
-
|
132
|
-
interface.x
|
133
|
-
|
134
|
-
end
|
139
|
+
interface.x + bo
|
135
140
|
end
|
136
141
|
|
137
142
|
# @return [Fixnum]
|
138
143
|
def bxn
|
139
|
-
|
140
|
-
interface.xn - 1
|
144
|
+
bo = (enabled? && right?) ? 1 : 0
|
141
145
|
|
142
|
-
|
143
|
-
interface.xn
|
144
|
-
|
145
|
-
end
|
146
|
+
interface.xn - bo
|
146
147
|
end
|
147
148
|
|
148
149
|
# @return [Fixnum]
|
149
150
|
def by
|
150
|
-
|
151
|
-
interface.y + 1
|
152
|
-
|
153
|
-
else
|
154
|
-
interface.y
|
151
|
+
bo = (enabled? && top?) ? 1 : 0
|
155
152
|
|
156
|
-
|
153
|
+
interface.y + bo
|
157
154
|
end
|
158
155
|
|
159
156
|
# @return [Fixnum]
|
160
157
|
def byn
|
161
|
-
|
162
|
-
interface.yn - 1
|
158
|
+
bo = (enabled? && bottom?) ? 1 : 0
|
163
159
|
|
164
|
-
|
165
|
-
interface.yn
|
166
|
-
|
167
|
-
end
|
160
|
+
interface.yn - bo
|
168
161
|
end
|
169
162
|
|
170
163
|
# Returns the width of the interface determined by whether a left, right,
|
@@ -172,18 +165,7 @@ module Vedeu
|
|
172
165
|
#
|
173
166
|
# @return [Fixnum]
|
174
167
|
def width
|
175
|
-
|
176
|
-
|
177
|
-
if left? && right?
|
178
|
-
interface.width - 2
|
179
|
-
|
180
|
-
elsif left? || right?
|
181
|
-
interface.width - 1
|
182
|
-
|
183
|
-
else
|
184
|
-
interface.width
|
185
|
-
|
186
|
-
end
|
168
|
+
(bx..bxn).size
|
187
169
|
end
|
188
170
|
|
189
171
|
# Returns the height of the interface determined by whether a top, bottom,
|
@@ -191,18 +173,7 @@ module Vedeu
|
|
191
173
|
#
|
192
174
|
# @return [Fixnum]
|
193
175
|
def height
|
194
|
-
|
195
|
-
|
196
|
-
if top? && bottom?
|
197
|
-
interface.height - 2
|
198
|
-
|
199
|
-
elsif top? || bottom?
|
200
|
-
interface.height - 1
|
201
|
-
|
202
|
-
else
|
203
|
-
interface.height
|
204
|
-
|
205
|
-
end
|
176
|
+
(by..byn).size
|
206
177
|
end
|
207
178
|
|
208
179
|
# @return [Vedeu::Colour]
|
@@ -246,17 +217,7 @@ module Vedeu
|
|
246
217
|
#
|
247
218
|
# @return [String]
|
248
219
|
def bottom
|
249
|
-
|
250
|
-
|
251
|
-
out = []
|
252
|
-
|
253
|
-
out << border(bottom_left, :bottom_left) if left?
|
254
|
-
width.times do |ix|
|
255
|
-
out << border(horizontal, :bottom_horizontal, nil, ix)
|
256
|
-
end
|
257
|
-
out << border(bottom_right, :bottom_right) if right?
|
258
|
-
|
259
|
-
out.flatten
|
220
|
+
top_or_bottom('bottom')
|
260
221
|
end
|
261
222
|
|
262
223
|
# Renders the left border for the interface.
|
@@ -283,20 +244,50 @@ module Vedeu
|
|
283
244
|
#
|
284
245
|
# @return [String]
|
285
246
|
def top
|
286
|
-
|
247
|
+
top_or_bottom('top')
|
248
|
+
end
|
249
|
+
|
250
|
+
private
|
251
|
+
|
252
|
+
# @param prefix [String]
|
253
|
+
# @return [String]
|
254
|
+
def top_or_bottom(prefix)
|
255
|
+
predicate = (prefix + '?').to_sym
|
256
|
+
_left = (prefix + '_left').to_sym
|
257
|
+
_right = (prefix + '_right').to_sym
|
258
|
+
_horizontal = (prefix + '_horizontal').to_sym
|
259
|
+
|
260
|
+
return [] unless send(predicate)
|
287
261
|
|
288
262
|
out = []
|
289
|
-
out << border(
|
290
|
-
|
291
|
-
|
263
|
+
out << border(send(_left), _left) if left?
|
264
|
+
|
265
|
+
if prefix == 'top' && defined_value?(title)
|
266
|
+
title_out = []
|
267
|
+
width.times do |ix|
|
268
|
+
title_out << border(horizontal, _horizontal, nil, ix)
|
269
|
+
end
|
270
|
+
|
271
|
+
truncate = title.chomp.slice(0..(width - 5))
|
272
|
+
pad = truncate.center(truncate.size + 2).chars
|
273
|
+
out << title_out.each_with_index do |b, i|
|
274
|
+
if i >= 1 && i <= pad.size
|
275
|
+
b.border = nil
|
276
|
+
b.value = pad[(i - 1)]
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
else
|
281
|
+
width.times do |ix|
|
282
|
+
out << border(horizontal, _horizontal, nil, ix)
|
283
|
+
end
|
284
|
+
|
292
285
|
end
|
293
|
-
out << border(top_right, :top_right) if right?
|
294
286
|
|
295
|
-
out
|
287
|
+
out << border(send(_right), _right) if right?
|
288
|
+
out
|
296
289
|
end
|
297
290
|
|
298
|
-
private
|
299
|
-
|
300
291
|
# @param value [String]
|
301
292
|
# @param type [Symbol|NilClass]
|
302
293
|
# @param iy [Fixnum]
|
@@ -311,6 +302,11 @@ module Vedeu
|
|
311
302
|
border: type })
|
312
303
|
end
|
313
304
|
|
305
|
+
# @return [Vedeu::Interface]
|
306
|
+
def interface
|
307
|
+
@interface ||= Vedeu.interfaces.find(name)
|
308
|
+
end
|
309
|
+
|
314
310
|
# The default values for a new instance of this class.
|
315
311
|
#
|
316
312
|
# @return [Hash]
|
@@ -328,6 +324,7 @@ module Vedeu
|
|
328
324
|
show_right: true,
|
329
325
|
show_top: true,
|
330
326
|
style: [],
|
327
|
+
title: '',
|
331
328
|
top_left: "\x6C", # ┌
|
332
329
|
top_right: "\x6B", # ┐
|
333
330
|
vertical: "\x78", # │
|
@@ -172,6 +172,15 @@ module Vedeu
|
|
172
172
|
it { subject.must_be_instance_of(TrueClass) }
|
173
173
|
end
|
174
174
|
|
175
|
+
describe '#title' do
|
176
|
+
let(:value) { 'Some title'}
|
177
|
+
|
178
|
+
subject { instance.title(value) }
|
179
|
+
|
180
|
+
it { subject.must_be_instance_of(String) }
|
181
|
+
it { subject.must_equal('Some title') }
|
182
|
+
end
|
183
|
+
|
175
184
|
describe '#top_left' do
|
176
185
|
let(:char) { 'A' }
|
177
186
|
|
data/vedeu.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'vedeu'
|
7
|
-
spec.version = '0.4.
|
7
|
+
spec.version = '0.4.11'
|
8
8
|
spec.authors = ['Gavin Laking']
|
9
9
|
spec.email = ['gavinlaking@gmail.com']
|
10
10
|
spec.summary = %q{A terminal case of wonderland.}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vedeu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Laking
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aruba
|