vedeu 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +40 -0
- data/README.md +1 -0
- data/docs/dsl.md +24 -24
- data/lib/vedeu/all.rb +21 -44
- data/lib/vedeu/api.rb +13 -13
- data/lib/vedeu/application/application_controller.rb +2 -0
- data/lib/vedeu/bindings/movement.rb +53 -18
- data/lib/vedeu/bindings/refresh.rb +1 -1
- data/lib/vedeu/bindings/system.rb +2 -2
- data/lib/vedeu/bindings/visibility.rb +3 -3
- data/lib/vedeu/borders/all.rb +13 -0
- data/lib/vedeu/borders/border.rb +209 -202
- data/lib/vedeu/{dsl/border.rb → borders/dsl.rb} +15 -15
- data/lib/vedeu/{null/border.rb → borders/null.rb} +9 -9
- data/lib/vedeu/borders/render.rb +347 -0
- data/lib/vedeu/borders/repository.rb +19 -0
- data/lib/vedeu/buffers/all.rb +13 -0
- data/lib/vedeu/buffers/buffer.rb +182 -176
- data/lib/vedeu/{null/buffer.rb → buffers/null.rb} +8 -8
- data/lib/vedeu/buffers/repository.rb +24 -0
- data/lib/vedeu/buffers/virtual_buffer.rb +2 -2
- data/lib/vedeu/cursors/all.rb +11 -0
- data/lib/vedeu/cursors/cursor.rb +276 -0
- data/lib/vedeu/cursors/refresh.rb +84 -0
- data/lib/vedeu/cursors/repository.rb +34 -0
- data/lib/vedeu/dsl/interface.rb +9 -9
- data/lib/vedeu/dsl/shared.rb +11 -11
- data/lib/vedeu/{exceptions.rb → error.rb} +2 -2
- data/lib/vedeu/esc/esc.rb +1 -1
- data/lib/vedeu/geometry/all.rb +18 -0
- data/lib/vedeu/geometry/area.rb +170 -160
- data/lib/vedeu/geometry/coordinate.rb +61 -39
- data/lib/vedeu/geometry/dimension.rb +139 -132
- data/lib/vedeu/{dsl/geometry.rb → geometry/dsl.rb} +11 -11
- data/lib/vedeu/geometry/generic_coordinate.rb +159 -153
- data/lib/vedeu/geometry/geometry.rb +310 -212
- data/lib/vedeu/geometry/grid.rb +73 -69
- data/lib/vedeu/{null/geometry.rb → geometry/null.rb} +10 -10
- data/lib/vedeu/geometry/position.rb +124 -120
- data/lib/vedeu/geometry/repository.rb +19 -0
- data/lib/vedeu/input/editor/document.rb +2 -2
- data/lib/vedeu/internal_api.rb +8 -8
- data/lib/vedeu/models/escape.rb +2 -2
- data/lib/vedeu/models/interface.rb +1 -1
- data/lib/vedeu/models/page.rb +89 -0
- data/lib/vedeu/models/row.rb +66 -0
- data/lib/vedeu/models/toggleable.rb +1 -1
- data/lib/vedeu/models/views/char.rb +7 -6
- data/lib/vedeu/models/views/line.rb +1 -1
- data/lib/vedeu/models/views/view.rb +2 -2
- data/lib/vedeu/options.rb +19 -0
- data/lib/vedeu/output/clear/named_interface.rb +1 -1
- data/lib/vedeu/output/direct.rb +1 -1
- data/lib/vedeu/output/presentation.rb +2 -1
- data/lib/vedeu/output/viewport.rb +3 -3
- data/lib/vedeu/repositories/model.rb +9 -1
- data/lib/vedeu/repositories/repository.rb +5 -0
- data/lib/vedeu/terminal/terminal.rb +3 -3
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/borders/border_test.rb +299 -291
- data/test/lib/vedeu/{dsl/border_test.rb → borders/dsl_test.rb} +6 -6
- data/test/lib/vedeu/{null/border_test.rb → borders/null_test.rb} +6 -6
- data/test/lib/vedeu/borders/render_test.rb +125 -0
- data/test/lib/vedeu/borders/repository_test.rb +17 -0
- data/test/lib/vedeu/buffers/buffer_test.rb +116 -112
- data/test/lib/vedeu/{null/buffer_test.rb → buffers/null_test.rb} +5 -5
- data/test/lib/vedeu/buffers/repository_test.rb +18 -0
- data/test/lib/vedeu/cursors/cursor_test.rb +370 -0
- data/test/lib/vedeu/cursors/refresh_test.rb +69 -0
- data/test/lib/vedeu/cursors/repository_test.rb +41 -0
- data/test/lib/vedeu/dsl/interface_test.rb +5 -5
- data/test/lib/vedeu/{exceptions_test.rb → error_test.rb} +0 -0
- data/test/lib/vedeu/geometry/area_test.rb +141 -137
- data/test/lib/vedeu/geometry/coordinate_test.rb +93 -89
- data/test/lib/vedeu/geometry/dimension_test.rb +137 -133
- data/test/lib/vedeu/{dsl/geometry_test.rb → geometry/dsl_test.rb} +17 -17
- data/test/lib/vedeu/geometry/generic_coordinate_test.rb +32 -28
- data/test/lib/vedeu/geometry/geometry_test.rb +282 -157
- data/test/lib/vedeu/geometry/grid_test.rb +35 -31
- data/test/lib/vedeu/{null/geometry_test.rb → geometry/null_test.rb} +5 -5
- data/test/lib/vedeu/geometry/position_test.rb +146 -142
- data/test/lib/vedeu/geometry/repository_test.rb +19 -0
- data/test/lib/vedeu/input/editor/document_test.rb +1 -1
- data/test/lib/vedeu/models/escape_test.rb +1 -1
- data/test/lib/vedeu/models/interface_test.rb +2 -2
- data/test/lib/vedeu/models/page_test.rb +235 -0
- data/test/lib/vedeu/models/row_test.rb +111 -0
- data/test/lib/vedeu/models/views/char_test.rb +3 -3
- data/test/lib/vedeu/options_test.rb +57 -0
- data/test/lib/vedeu/output/clear/named_interface_test.rb +1 -1
- data/test/lib/vedeu/output/renderers/json_test.rb +1 -1
- data/test/lib/vedeu/output/viewport_test.rb +15 -9
- data/test/lib/vedeu/refresh/refresh_buffer_test.rb +12 -12
- data/test/lib/vedeu/repositories/repositories_test.rb +1 -1
- data/test/lib/vedeu/repositories/repository_test.rb +7 -0
- data/test/lib/vedeu/terminal/terminal_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/vedeu.gemspec +2 -2
- metadata +57 -63
- data/lib/vedeu/borders/borders.rb +0 -15
- data/lib/vedeu/borders/render_border.rb +0 -331
- data/lib/vedeu/buffers/buffers.rb +0 -20
- data/lib/vedeu/cursor/cursor.rb +0 -174
- data/lib/vedeu/cursor/cursors.rb +0 -30
- data/lib/vedeu/cursor/move.rb +0 -239
- data/lib/vedeu/cursor/reposition.rb +0 -78
- data/lib/vedeu/geometry/geometries.rb +0 -15
- data/lib/vedeu/refresh/refresh_cursor.rb +0 -92
- data/test/lib/vedeu/borders/borders_test.rb +0 -13
- data/test/lib/vedeu/borders/render_border_test.rb +0 -121
- data/test/lib/vedeu/buffers/buffers_test.rb +0 -14
- data/test/lib/vedeu/cursor/cursor_test.rb +0 -246
- data/test/lib/vedeu/cursor/cursors_test.rb +0 -37
- data/test/lib/vedeu/cursor/move_test.rb +0 -301
- data/test/lib/vedeu/cursor/reposition_test.rb +0 -63
- data/test/lib/vedeu/geometry/geometries_test.rb +0 -15
- data/test/lib/vedeu/refresh/refresh_cursor_test.rb +0 -65
@@ -1,6 +1,6 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
module
|
3
|
+
module Borders
|
4
4
|
|
5
5
|
# Borders are defined by name for each of the client application's
|
6
6
|
# interfaces or views. They can be enabled or disabled (which controls
|
@@ -26,7 +26,7 @@ module Vedeu
|
|
26
26
|
# # ...
|
27
27
|
# end
|
28
28
|
#
|
29
|
-
class
|
29
|
+
class DSL
|
30
30
|
|
31
31
|
include Vedeu::DSL
|
32
32
|
include Vedeu::DSL::Presentation
|
@@ -43,18 +43,18 @@ module Vedeu
|
|
43
43
|
# @param block [Proc]
|
44
44
|
# @raise [Vedeu::Error::InvalidSyntax]
|
45
45
|
# The required block was not given.
|
46
|
-
# @return [Vedeu::Border]
|
46
|
+
# @return [Vedeu::Borders::Border]
|
47
47
|
def self.border(name, &block)
|
48
48
|
fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
|
49
49
|
|
50
|
-
Vedeu::Border.build(enabled: true, name: name, &block).store
|
50
|
+
Vedeu::Borders::Border.build(enabled: true, name: name, &block).store
|
51
51
|
end
|
52
52
|
|
53
|
-
# Returns an instance of DSL
|
53
|
+
# Returns an instance of Borders::DSL.
|
54
54
|
#
|
55
|
-
# @param model [Border]
|
55
|
+
# @param model [Vedeu::Borders::Border]
|
56
56
|
# @param client [Object]
|
57
|
-
# @return [Vedeu::DSL
|
57
|
+
# @return [Vedeu::Borders::DSL]
|
58
58
|
def initialize(model, client = nil)
|
59
59
|
@model = model
|
60
60
|
@client = client
|
@@ -169,14 +169,14 @@ module Vedeu
|
|
169
169
|
|
170
170
|
# Disable the bottom border.
|
171
171
|
#
|
172
|
-
# @see Vedeu::DSL
|
172
|
+
# @see Vedeu::Borders::DSL#bottom
|
173
173
|
def hide_bottom!
|
174
174
|
bottom(false)
|
175
175
|
end
|
176
176
|
|
177
177
|
# Enable the bottom border.
|
178
178
|
#
|
179
|
-
# @see Vedeu::DSL
|
179
|
+
# @see Vedeu::Borders::DSL#bottom
|
180
180
|
def show_bottom!
|
181
181
|
bottom(true)
|
182
182
|
end
|
@@ -204,14 +204,14 @@ module Vedeu
|
|
204
204
|
|
205
205
|
# Disable the left border.
|
206
206
|
#
|
207
|
-
# @see Vedeu::DSL
|
207
|
+
# @see Vedeu::Borders::DSL#left
|
208
208
|
def hide_left!
|
209
209
|
left(false)
|
210
210
|
end
|
211
211
|
|
212
212
|
# Enable the left border.
|
213
213
|
#
|
214
|
-
# @see Vedeu::DSL
|
214
|
+
# @see Vedeu::Borders::DSL#left
|
215
215
|
def show_left!
|
216
216
|
left(true)
|
217
217
|
end
|
@@ -239,14 +239,14 @@ module Vedeu
|
|
239
239
|
|
240
240
|
# Disable the right border.
|
241
241
|
#
|
242
|
-
# @see Vedeu::DSL
|
242
|
+
# @see Vedeu::Borders::DSL#right
|
243
243
|
def hide_right!
|
244
244
|
right(false)
|
245
245
|
end
|
246
246
|
|
247
247
|
# Enable the right border.
|
248
248
|
#
|
249
|
-
# @see Vedeu::DSL
|
249
|
+
# @see Vedeu::Borders::DSL#right
|
250
250
|
def show_right!
|
251
251
|
right(true)
|
252
252
|
end
|
@@ -310,14 +310,14 @@ module Vedeu
|
|
310
310
|
|
311
311
|
# Disable the top border.
|
312
312
|
#
|
313
|
-
# @see Vedeu::DSL
|
313
|
+
# @see Vedeu::Borders::DSL#top
|
314
314
|
def hide_top!
|
315
315
|
top(false)
|
316
316
|
end
|
317
317
|
|
318
318
|
# Enable the top border.
|
319
319
|
#
|
320
|
-
# @see Vedeu::DSL
|
320
|
+
# @see Vedeu::Borders::DSL#top
|
321
321
|
def show_top!
|
322
322
|
top(true)
|
323
323
|
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
module
|
3
|
+
module Borders
|
4
4
|
|
5
|
-
# Provides a non-existent Vedeu::Border that acts like the real
|
6
|
-
# does nothing.
|
5
|
+
# Provides a non-existent Vedeu::Borders::Border that acts like the real
|
6
|
+
# thing, but does nothing.
|
7
7
|
#
|
8
|
-
class
|
8
|
+
class Null
|
9
9
|
|
10
10
|
# @!attribute [r] name
|
11
11
|
# @return [String|NilClass]
|
12
12
|
attr_reader :name
|
13
13
|
|
14
|
-
# Returns a new instance of Vedeu::Null
|
14
|
+
# Returns a new instance of Vedeu::Borders::Null.
|
15
15
|
#
|
16
16
|
# @param attributes [Hash<Symbol => void>]
|
17
17
|
# @option attributes name [String|NilClass]
|
18
|
-
# @return [Vedeu::Null
|
18
|
+
# @return [Vedeu::Borders::Null]
|
19
19
|
def initialize(attributes = {})
|
20
20
|
@attributes = attributes
|
21
21
|
@name = @attributes[:name]
|
@@ -77,13 +77,13 @@ module Vedeu
|
|
77
77
|
|
78
78
|
# Returns the geometry for the interface.
|
79
79
|
#
|
80
|
-
# @return (see Vedeu::
|
80
|
+
# @return (see Vedeu::Geometry::Repository#by_name)
|
81
81
|
def geometry
|
82
82
|
@geometry ||= Vedeu.geometries.by_name(name)
|
83
83
|
end
|
84
84
|
|
85
|
-
end #
|
85
|
+
end # Null
|
86
86
|
|
87
|
-
end #
|
87
|
+
end # Borders
|
88
88
|
|
89
89
|
end # Vedeu
|
@@ -0,0 +1,347 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Borders
|
4
|
+
|
5
|
+
# Renders the provided border.
|
6
|
+
#
|
7
|
+
class Render
|
8
|
+
|
9
|
+
extend Forwardable
|
10
|
+
include Vedeu::Common
|
11
|
+
|
12
|
+
def_delegators :border,
|
13
|
+
:bottom?,
|
14
|
+
:bottom_left,
|
15
|
+
:bottom_right,
|
16
|
+
:bx,
|
17
|
+
:bxn,
|
18
|
+
:by,
|
19
|
+
:byn,
|
20
|
+
:caption,
|
21
|
+
:colour,
|
22
|
+
:enabled?,
|
23
|
+
:height,
|
24
|
+
:horizontal,
|
25
|
+
:left?,
|
26
|
+
:name,
|
27
|
+
:right?,
|
28
|
+
:style,
|
29
|
+
:title,
|
30
|
+
:top?,
|
31
|
+
:top_left,
|
32
|
+
:top_right,
|
33
|
+
:width,
|
34
|
+
:vertical
|
35
|
+
|
36
|
+
def_delegators :geometry,
|
37
|
+
:x,
|
38
|
+
:xn,
|
39
|
+
:y,
|
40
|
+
:yn
|
41
|
+
|
42
|
+
# @return [Array<Array<Vedeu::Views::Char>>]
|
43
|
+
# @see Vedeu::Borders::Render#initialize
|
44
|
+
def self.with(border)
|
45
|
+
new(border).render
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns a new instance of Vedeu::Borders::Render.
|
49
|
+
#
|
50
|
+
# @param border [Vedeu::Borders::Border]
|
51
|
+
# @return [Vedeu::Borders::Render]
|
52
|
+
def initialize(border)
|
53
|
+
@border = border
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Array<Array<Vedeu::Views::Char>>]
|
57
|
+
def render
|
58
|
+
return [] unless enabled?
|
59
|
+
|
60
|
+
Vedeu.timer("Bordering: '#{name}'") do
|
61
|
+
out = [top, bottom]
|
62
|
+
|
63
|
+
height.times { |y| out << [left(y), right(y)] }
|
64
|
+
|
65
|
+
out.flatten
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
protected
|
70
|
+
|
71
|
+
# @!attribute [r] border
|
72
|
+
# @return [Vedeu::Borders::Border]
|
73
|
+
attr_reader :border
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# @param value [String]
|
78
|
+
# @param type [Symbol|NilClass]
|
79
|
+
# @param iy [Fixnum]
|
80
|
+
# @param ix [Fixnum]
|
81
|
+
# @return [Vedeu::Views::Char]
|
82
|
+
def build(value, type = :border, iy = 0, ix = 0)
|
83
|
+
Vedeu::Views::Char.new(value: value,
|
84
|
+
parent: interface,
|
85
|
+
colour: colour,
|
86
|
+
style: style,
|
87
|
+
position: [iy, ix],
|
88
|
+
border: type)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Creates the bottom left border character.
|
92
|
+
#
|
93
|
+
# @return [Vedeu::Views::Char]
|
94
|
+
def build_bottom_left
|
95
|
+
build(bottom_left, :bottom_left, yn, x) if left?
|
96
|
+
end
|
97
|
+
|
98
|
+
# Creates the bottom right border character.
|
99
|
+
#
|
100
|
+
# @return [Vedeu::Views::Char]
|
101
|
+
def build_bottom_right
|
102
|
+
build(bottom_right, :bottom_right, yn, xn) if right?
|
103
|
+
end
|
104
|
+
|
105
|
+
# Creates a top border character.
|
106
|
+
#
|
107
|
+
# @return [Array<Vedeu::Views::Char>]
|
108
|
+
def build_top
|
109
|
+
build_horizontal(:bottom_horizontal, y)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Creates a bottom border character.
|
113
|
+
#
|
114
|
+
# @return [Array<Vedeu::Views::Char>]
|
115
|
+
def build_bottom
|
116
|
+
build_horizontal(:bottom_horizontal, yn)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Creates the top left border character.
|
120
|
+
#
|
121
|
+
# @return [Vedeu::Views::Char]
|
122
|
+
def build_top_left
|
123
|
+
build(top_left, :top_left, y, x) if left?
|
124
|
+
end
|
125
|
+
|
126
|
+
# Creates the top right border character.
|
127
|
+
#
|
128
|
+
# @return [Vedeu::Views::Char]
|
129
|
+
def build_top_right
|
130
|
+
build(top_right, :top_right, y, xn) if right?
|
131
|
+
end
|
132
|
+
|
133
|
+
# Renders the bottom border for the interface.
|
134
|
+
#
|
135
|
+
# @note
|
136
|
+
# If a caption has been specified, then the bottom border will include
|
137
|
+
# this caption unless the size of the interface is smaller than the
|
138
|
+
# padded caption length.
|
139
|
+
#
|
140
|
+
# @return [String]
|
141
|
+
def bottom
|
142
|
+
return [] unless bottom?
|
143
|
+
|
144
|
+
[build_bottom_left, captionbar, build_bottom_right].compact
|
145
|
+
end
|
146
|
+
|
147
|
+
# @return [Vedeu::Geometry::Geometry]
|
148
|
+
def geometry
|
149
|
+
Vedeu.geometries.by_name(name)
|
150
|
+
end
|
151
|
+
|
152
|
+
# @param position [Symbol] Either :top_horizontal, or :bottom_horizontal.
|
153
|
+
# @param y_coordinate [Fixnum] The value of either y or yn.
|
154
|
+
# @return [Array<Vedeu::Views::Char>]
|
155
|
+
def build_horizontal(position, y_coordinate)
|
156
|
+
Array.new(width) do |ix|
|
157
|
+
build(horizontal, position, y_coordinate, (bx + ix))
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# The parent of a border is always an interface.
|
162
|
+
#
|
163
|
+
# @return [Vedeu::Interface]
|
164
|
+
def interface
|
165
|
+
@interface ||= Vedeu.interfaces.by_name(name)
|
166
|
+
end
|
167
|
+
alias_method :parent, :interface
|
168
|
+
|
169
|
+
# Renders the left border for the interface.
|
170
|
+
#
|
171
|
+
# @param iy [Fixnum]
|
172
|
+
# @return [String]
|
173
|
+
def left(iy = 0)
|
174
|
+
return [] unless left?
|
175
|
+
|
176
|
+
build(vertical, :left_vertical, (by + iy), x)
|
177
|
+
end
|
178
|
+
|
179
|
+
# Renders the right border for the interface.
|
180
|
+
#
|
181
|
+
# @param iy [Fixnum]
|
182
|
+
# @return [String]
|
183
|
+
def right(iy = 0)
|
184
|
+
return [] unless right?
|
185
|
+
|
186
|
+
build(vertical, :right_vertical, (by + iy), xn)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Renders the top border for the interface.
|
190
|
+
#
|
191
|
+
# @note
|
192
|
+
# If a title has been specified, then the top border will include this
|
193
|
+
# title unless the size of the interface is smaller than the padded
|
194
|
+
# title length.
|
195
|
+
#
|
196
|
+
# @return [String]
|
197
|
+
def top
|
198
|
+
return [] unless top?
|
199
|
+
|
200
|
+
[build_top_left, titlebar, build_top_right].compact
|
201
|
+
end
|
202
|
+
|
203
|
+
# Overwrite the border from {#build_horizontal} on the bottom border to
|
204
|
+
# include the caption if given.
|
205
|
+
#
|
206
|
+
# @return [Array<Vedeu::Views::Char>]
|
207
|
+
def captionbar
|
208
|
+
return build_bottom unless caption? && caption_fits?
|
209
|
+
|
210
|
+
caption_starts_at = (width - caption_characters.size) - 2
|
211
|
+
|
212
|
+
caption_char = 0
|
213
|
+
build_bottom.each_with_index do |char, index|
|
214
|
+
next if index <= caption_starts_at || index > (width - 2)
|
215
|
+
|
216
|
+
char.border = nil
|
217
|
+
char.value = caption_characters[caption_char]
|
218
|
+
caption_char += 1
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Overwrite the border from {#build_horizontal} on the top border to
|
223
|
+
# include the title if given.
|
224
|
+
#
|
225
|
+
# @return [Array<Vedeu::Views::Char>]
|
226
|
+
def titlebar
|
227
|
+
return build_top unless title? && title_fits?
|
228
|
+
|
229
|
+
build_top.each_with_index do |char, index|
|
230
|
+
next if index == 0 || index > title_characters.size
|
231
|
+
|
232
|
+
char.border = nil
|
233
|
+
char.value = title_characters[(index - 1)]
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# Return boolean indicating whether this border has a non-empty title.
|
238
|
+
#
|
239
|
+
# @return [Boolean]
|
240
|
+
def title?
|
241
|
+
present?(title)
|
242
|
+
end
|
243
|
+
|
244
|
+
# Return boolean indicating whether this border has a non-empty caption.
|
245
|
+
#
|
246
|
+
# @return [Boolean]
|
247
|
+
def caption?
|
248
|
+
present?(caption)
|
249
|
+
end
|
250
|
+
|
251
|
+
# Return boolean indicating whether the title fits within the width of the
|
252
|
+
# top border.
|
253
|
+
#
|
254
|
+
# @return [Boolean]
|
255
|
+
def title_fits?
|
256
|
+
width > title_characters.size
|
257
|
+
end
|
258
|
+
|
259
|
+
# Return boolean indicating whether the caption fits within the width of
|
260
|
+
# the bottom border.
|
261
|
+
#
|
262
|
+
# @return [Boolean]
|
263
|
+
def caption_fits?
|
264
|
+
width > caption_characters.size
|
265
|
+
end
|
266
|
+
|
267
|
+
# @return [Array<String>]
|
268
|
+
def title_characters
|
269
|
+
@title_characters ||= title_padded.chars
|
270
|
+
end
|
271
|
+
|
272
|
+
# @return [Array<String>]
|
273
|
+
def caption_characters
|
274
|
+
@caption_characters ||= caption_padded.chars
|
275
|
+
end
|
276
|
+
|
277
|
+
# Pads the title with a single whitespace either side.
|
278
|
+
#
|
279
|
+
# @example
|
280
|
+
# title = 'Truncated!'
|
281
|
+
# width = 20
|
282
|
+
# # => ' Truncated! '
|
283
|
+
#
|
284
|
+
# width = 10
|
285
|
+
# # => ' Trunca '
|
286
|
+
#
|
287
|
+
# @return [String]
|
288
|
+
# @see #truncated_title
|
289
|
+
def title_padded
|
290
|
+
truncated_title.center(truncated_title.size + 2)
|
291
|
+
end
|
292
|
+
|
293
|
+
# Pads the caption with a single whitespace either side.
|
294
|
+
#
|
295
|
+
# @example
|
296
|
+
# caption = 'Truncated!'
|
297
|
+
# width = 20
|
298
|
+
# # => ' Truncated! '
|
299
|
+
#
|
300
|
+
# width = 10
|
301
|
+
# # => ' Trunca '
|
302
|
+
#
|
303
|
+
# @return [String]
|
304
|
+
# @see #truncated_caption
|
305
|
+
def caption_padded
|
306
|
+
truncated_caption.center(truncated_caption.size + 2)
|
307
|
+
end
|
308
|
+
|
309
|
+
# Truncates the title to the width of the interface, minus characters
|
310
|
+
# needed to ensure there is at least a single character of horizontal
|
311
|
+
# border and a whitespace on either side of the title.
|
312
|
+
#
|
313
|
+
# @example
|
314
|
+
# title = 'Truncated!'
|
315
|
+
# width = 20
|
316
|
+
# # => 'Truncated!'
|
317
|
+
#
|
318
|
+
# width = 10
|
319
|
+
# # => 'Trunca'
|
320
|
+
#
|
321
|
+
# @return [String]
|
322
|
+
def truncated_title
|
323
|
+
title.chomp.slice(0..(width - 5))
|
324
|
+
end
|
325
|
+
|
326
|
+
# Truncates the caption to the width of the interface, minus characters
|
327
|
+
# needed to ensure there is at least a single character of horizontal
|
328
|
+
# border and a whitespace on either side of the caption.
|
329
|
+
#
|
330
|
+
# @example
|
331
|
+
# caption = 'Truncated!'
|
332
|
+
# width = 20
|
333
|
+
# # => 'Truncated!'
|
334
|
+
#
|
335
|
+
# width = 10
|
336
|
+
# # => 'Trunca'
|
337
|
+
#
|
338
|
+
# @return [String]
|
339
|
+
def truncated_caption
|
340
|
+
caption.chomp.slice(0..(width - 5))
|
341
|
+
end
|
342
|
+
|
343
|
+
end # Render
|
344
|
+
|
345
|
+
end # Borders
|
346
|
+
|
347
|
+
end # Vedeu
|