tty-box 0.5.0 → 0.6.0
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/CHANGELOG.md +11 -0
- data/README.md +4 -6
- data/lib/tty/box.rb +79 -19
- data/lib/tty/box/border.rb +1 -1
- data/lib/tty/box/version.rb +1 -1
- metadata +24 -51
- data/Rakefile +0 -8
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/examples/basic.rb +0 -8
- data/examples/commander.rb +0 -54
- data/examples/connected.rb +0 -47
- data/examples/messages.rb +0 -11
- data/examples/newline.rb +0 -14
- data/spec/spec_helper.rb +0 -31
- data/spec/unit/align_spec.rb +0 -29
- data/spec/unit/border/parse_spec.rb +0 -61
- data/spec/unit/border_spec.rb +0 -151
- data/spec/unit/custom_frame_spec.rb +0 -51
- data/spec/unit/frame_spec.rb +0 -134
- data/spec/unit/padding_spec.rb +0 -82
- data/spec/unit/position_spec.rb +0 -25
- data/spec/unit/style_spec.rb +0 -123
- data/spec/unit/title_spec.rb +0 -37
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-box.gemspec +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66cd38e818e47ac372868586d8a76cdeb41a98aa9efc59430ec89acb84629410
|
4
|
+
data.tar.gz: d96e96b93e46a9ed8b7432632618af9c54e4da5f9575df820c6f77987104baf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bc7bddb63b580b8430d3dcdf596801db37e2f5813c12b8512a89dc9aff4140ebf6478e91d828020ffb182c84ca81b990d3d346c27718491c420a5a0099deca7
|
7
|
+
data.tar.gz: 43756dd006eec4de539d4a802c69afa04ca1b56fdd29505725d7001418a9e37f94005fc4606daa6be2564a8a12d2b876cbfb4d2ff1f0b43254c7580a99961b48
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.6.0] - 2020-08-11
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
* Change to preserve newline characters when wrapping content
|
7
|
+
* Change gemspec to include metadata and remove test files
|
8
|
+
* Change to update pastel & strings dependencies
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
* Fix Ruby 2.7 warnings
|
12
|
+
|
3
13
|
## [v0.5.0] - 2019-10-08
|
4
14
|
|
5
15
|
### Added
|
@@ -52,6 +62,7 @@
|
|
52
62
|
|
53
63
|
* Initial implementation and release
|
54
64
|
|
65
|
+
[v0.6.0]: https://github.com/piotrmurach/tty-box/compare/v0.5.0...v0.6.0
|
55
66
|
[v0.5.0]: https://github.com/piotrmurach/tty-box/compare/v0.4.1...v0.5.0
|
56
67
|
[v0.4.1]: https://github.com/piotrmurach/tty-box/compare/v0.4.0...v0.4.1
|
57
68
|
[v0.4.0]: https://github.com/piotrmurach/tty-box/compare/v0.3.0...v0.4.0
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
[coverage]: https://coveralls.io/github/piotrmurach/tty-box
|
20
20
|
[inchpages]: http://inch-ci.org/github/piotrmurach/tty-box
|
21
21
|
|
22
|
-
> Draw various frames and boxes in
|
22
|
+
> Draw various frames and boxes in the terminal window.
|
23
23
|
|
24
24
|
**TTY::Box** provides box drawing component for [TTY](https://github.com/piotrmurach/tty) toolkit.
|
25
25
|
|
@@ -30,7 +30,7 @@
|
|
30
30
|
Add this line to your application's Gemfile:
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
gem
|
33
|
+
gem "tty-box"
|
34
34
|
```
|
35
35
|
|
36
36
|
And then execute:
|
@@ -122,9 +122,7 @@ print TTY::Box.frame "Hello\nworld!"
|
|
122
122
|
Finally, you can use a block to specify content:
|
123
123
|
|
124
124
|
```ruby
|
125
|
-
print TTY::Box.frame
|
126
|
-
"Hello world!"
|
127
|
-
end
|
125
|
+
print TTY::Box.frame { "Hello world!" }
|
128
126
|
# =>
|
129
127
|
# ┌────────────┐
|
130
128
|
# │Hello world!│
|
@@ -213,7 +211,7 @@ You can specify titles using the `:title` keyword and a hash value that contains
|
|
213
211
|
|
214
212
|
|
215
213
|
```ruby
|
216
|
-
box = TTY::Box.frame(width: 30, height: 10, title: {top_left:
|
214
|
+
box = TTY::Box.frame(width: 30, height: 10, title: {top_left: "TITLE", bottom_right: "v1.0"})
|
217
215
|
```
|
218
216
|
|
219
217
|
which when printed in console will render the following:
|
data/lib/tty/box.rb
CHANGED
@@ -214,6 +214,8 @@ module TTY
|
|
214
214
|
# infer dimensions
|
215
215
|
dimensions = infer_dimensions(lines, padding)
|
216
216
|
width ||= left_size + dimensions[0] + right_size
|
217
|
+
width = [width, top_space_taken(title, border), bottom_space_taken(title, border)].max
|
218
|
+
|
217
219
|
height ||= top_size + dimensions[1] + bottom_size
|
218
220
|
content = format(str, width, padding, align) # adjust content
|
219
221
|
# infer styling
|
@@ -306,34 +308,99 @@ module TTY
|
|
306
308
|
[fg, bg]
|
307
309
|
end
|
308
310
|
|
311
|
+
# Top space taken by titles and corners
|
312
|
+
#
|
313
|
+
# @return [Integer]
|
314
|
+
#
|
315
|
+
# @api private
|
316
|
+
def top_space_taken(title, border)
|
317
|
+
top_titles_size(title) + top_left_corner(border).size + top_right_corner(border).size
|
318
|
+
end
|
319
|
+
|
320
|
+
# Top left corner
|
321
|
+
#
|
322
|
+
# @return [String]
|
323
|
+
#
|
324
|
+
# @api private
|
325
|
+
def top_left_corner(border)
|
326
|
+
border.top_left? && border.left? ? send(:"#{border.top_left}_char", border.type) : ""
|
327
|
+
end
|
328
|
+
|
329
|
+
# Top right corner
|
330
|
+
#
|
331
|
+
# @return [String]
|
332
|
+
#
|
333
|
+
# @api private
|
334
|
+
def top_right_corner(border)
|
335
|
+
border.top_right? && border.right? ? send(:"#{border.top_right}_char", border.type) : ""
|
336
|
+
end
|
337
|
+
|
338
|
+
# Top titles size
|
339
|
+
#
|
340
|
+
# @return [Integer]
|
341
|
+
#
|
342
|
+
# @api private
|
343
|
+
def top_titles_size(title)
|
344
|
+
title[:top_left].to_s.size + title[:top_center].to_s.size + title[:top_right].to_s.size
|
345
|
+
end
|
346
|
+
|
309
347
|
# Top border
|
310
348
|
#
|
311
349
|
# @return [String]
|
312
350
|
#
|
313
351
|
# @api private
|
314
352
|
def top_border(title, width, border, style)
|
315
|
-
top_titles_size = title[:top_left].to_s.size +
|
316
|
-
title[:top_center].to_s.size +
|
317
|
-
title[:top_right].to_s.size
|
318
353
|
fg, bg = *extract_style(style[:border] || {})
|
319
354
|
|
320
|
-
|
321
|
-
top_right = border.top_right? && border.right? ? send(:"#{border.top_right}_char", border.type) : ""
|
322
|
-
|
323
|
-
top_space_left = width - top_titles_size - top_left.size - top_right.size
|
355
|
+
top_space_left = width - top_space_taken(title, border)
|
324
356
|
top_space_before = top_space_left / 2
|
325
357
|
top_space_after = top_space_left / 2 + top_space_left % 2
|
326
358
|
|
327
359
|
[
|
328
|
-
bg.(fg.(
|
360
|
+
bg.(fg.(top_left_corner(border))),
|
329
361
|
bg.(fg.(title[:top_left].to_s)),
|
330
362
|
bg.(fg.(line_char(border.type) * top_space_before)),
|
331
363
|
bg.(fg.(title[:top_center].to_s)),
|
332
364
|
bg.(fg.(line_char(border.type) * top_space_after)),
|
333
365
|
bg.(fg.(title[:top_right].to_s)),
|
334
|
-
bg.(fg.(
|
366
|
+
bg.(fg.(top_right_corner(border)))
|
335
367
|
].join('')
|
336
368
|
end
|
369
|
+
# Bottom space taken by titles and corners
|
370
|
+
#
|
371
|
+
# @return [Integer]
|
372
|
+
#
|
373
|
+
# @api private
|
374
|
+
def bottom_space_taken(title, border)
|
375
|
+
bottom_titles_size(title) + bottom_left_corner(border).size + bottom_right_corner(border).size
|
376
|
+
end
|
377
|
+
|
378
|
+
# Bottom left corner
|
379
|
+
#
|
380
|
+
# @return [String]
|
381
|
+
#
|
382
|
+
# @api private
|
383
|
+
def bottom_left_corner(border)
|
384
|
+
border.bottom_left? && border.left? ? send(:"#{border.bottom_left}_char", border.type) : ""
|
385
|
+
end
|
386
|
+
|
387
|
+
# Bottom right corner
|
388
|
+
#
|
389
|
+
# @return [String]
|
390
|
+
#
|
391
|
+
# @api private
|
392
|
+
def bottom_right_corner(border)
|
393
|
+
border.bottom_right? && border.right? ? send(:"#{border.bottom_right}_char", border.type) : ""
|
394
|
+
end
|
395
|
+
|
396
|
+
# Bottom titles size
|
397
|
+
#
|
398
|
+
# @return [Integer]
|
399
|
+
#
|
400
|
+
# @api private
|
401
|
+
def bottom_titles_size(title)
|
402
|
+
title[:bottom_left].to_s.size + title[:bottom_center].to_s.size + title[:bottom_right].to_s.size
|
403
|
+
end
|
337
404
|
|
338
405
|
# Bottom border
|
339
406
|
#
|
@@ -341,27 +408,20 @@ module TTY
|
|
341
408
|
#
|
342
409
|
# @api private
|
343
410
|
def bottom_border(title, width, border, style)
|
344
|
-
bottom_titles_size = title[:bottom_left].to_s.size +
|
345
|
-
title[:bottom_center].to_s.size +
|
346
|
-
title[:bottom_right].to_s.size
|
347
411
|
fg, bg = *extract_style(style[:border] || {})
|
348
412
|
|
349
|
-
|
350
|
-
bottom_right = border.bottom_right? && border.right? ? send(:"#{border.bottom_right}_char", border.type) : ""
|
351
|
-
|
352
|
-
bottom_space_left = width - bottom_titles_size -
|
353
|
-
bottom_left.size - bottom_right.size
|
413
|
+
bottom_space_left = width - bottom_space_taken(title, border)
|
354
414
|
bottom_space_before = bottom_space_left / 2
|
355
415
|
bottom_space_after = bottom_space_left / 2 + bottom_space_left % 2
|
356
416
|
|
357
417
|
[
|
358
|
-
bg.(fg.(
|
418
|
+
bg.(fg.(bottom_left_corner(border))),
|
359
419
|
bg.(fg.(title[:bottom_left].to_s)),
|
360
420
|
bg.(fg.(line_char(border.type) * bottom_space_before)),
|
361
421
|
bg.(fg.(title[:bottom_center].to_s)),
|
362
422
|
bg.(fg.(line_char(border.type) * bottom_space_after)),
|
363
423
|
bg.(fg.(title[:bottom_right].to_s)),
|
364
|
-
bg.(fg.(
|
424
|
+
bg.(fg.(bottom_right_corner(border)))
|
365
425
|
].join('')
|
366
426
|
end
|
367
427
|
end # TTY
|
data/lib/tty/box/border.rb
CHANGED
data/lib/tty/box/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: '0.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tty-cursor
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,28 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.2.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: bundler
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.5'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.5'
|
54
|
+
version: 0.2.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,56 +70,43 @@ dependencies:
|
|
84
70
|
name: rspec
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - "
|
73
|
+
- - ">="
|
88
74
|
- !ruby/object:Gem::Version
|
89
75
|
version: '3.0'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- - "
|
80
|
+
- - ">="
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '3.0'
|
97
|
-
description: Draw various frames and boxes in
|
83
|
+
description: Draw various frames and boxes in the terminal window.
|
98
84
|
email:
|
99
|
-
-
|
85
|
+
- piotr@piotrmurach.com
|
100
86
|
executables: []
|
101
87
|
extensions: []
|
102
|
-
extra_rdoc_files:
|
88
|
+
extra_rdoc_files:
|
89
|
+
- README.md
|
90
|
+
- CHANGELOG.md
|
91
|
+
- LICENSE.txt
|
103
92
|
files:
|
104
93
|
- CHANGELOG.md
|
105
94
|
- LICENSE.txt
|
106
95
|
- README.md
|
107
|
-
- Rakefile
|
108
|
-
- bin/console
|
109
|
-
- bin/setup
|
110
|
-
- examples/basic.rb
|
111
|
-
- examples/commander.rb
|
112
|
-
- examples/connected.rb
|
113
|
-
- examples/messages.rb
|
114
|
-
- examples/newline.rb
|
115
96
|
- lib/tty-box.rb
|
116
97
|
- lib/tty/box.rb
|
117
98
|
- lib/tty/box/border.rb
|
118
99
|
- lib/tty/box/version.rb
|
119
|
-
|
120
|
-
- spec/unit/align_spec.rb
|
121
|
-
- spec/unit/border/parse_spec.rb
|
122
|
-
- spec/unit/border_spec.rb
|
123
|
-
- spec/unit/custom_frame_spec.rb
|
124
|
-
- spec/unit/frame_spec.rb
|
125
|
-
- spec/unit/padding_spec.rb
|
126
|
-
- spec/unit/position_spec.rb
|
127
|
-
- spec/unit/style_spec.rb
|
128
|
-
- spec/unit/title_spec.rb
|
129
|
-
- tasks/console.rake
|
130
|
-
- tasks/coverage.rake
|
131
|
-
- tasks/spec.rake
|
132
|
-
- tty-box.gemspec
|
133
|
-
homepage: https://piotrmurach.github.io/tty
|
100
|
+
homepage: https://ttytoolkit.org
|
134
101
|
licenses:
|
135
102
|
- MIT
|
136
|
-
metadata:
|
103
|
+
metadata:
|
104
|
+
allowed_push_host: https://rubygems.org
|
105
|
+
bug_tracker_uri: https://github.com/piotrmurach/tty-box/issues
|
106
|
+
changelog_uri: https://github.com/piotrmurach/tty-box/blob/master/CHANGELOG.md
|
107
|
+
documentation_uri: https://www.rubydoc.info/gems/tty-box
|
108
|
+
homepage_uri: https://ttytoolkit.org
|
109
|
+
source_code_uri: https://github.com/piotrmurach/tty-box
|
137
110
|
post_install_message:
|
138
111
|
rdoc_options: []
|
139
112
|
require_paths:
|
@@ -149,8 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
122
|
- !ruby/object:Gem::Version
|
150
123
|
version: '0'
|
151
124
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
125
|
+
rubygems_version: 3.1.2
|
153
126
|
signing_key:
|
154
127
|
specification_version: 4
|
155
|
-
summary: Draw various frames and boxes in
|
128
|
+
summary: Draw various frames and boxes in the terminal window.
|
156
129
|
test_files: []
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "tty/box"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
data/bin/setup
DELETED
data/examples/basic.rb
DELETED
data/examples/commander.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../lib/tty-box'
|
4
|
-
|
5
|
-
print TTY::Cursor.clear_screen
|
6
|
-
|
7
|
-
box_1 = TTY::Box.frame(
|
8
|
-
top: 2,
|
9
|
-
left: 10,
|
10
|
-
width: 30,
|
11
|
-
height: 10,
|
12
|
-
border: :thick,
|
13
|
-
align: :center,
|
14
|
-
padding: 3,
|
15
|
-
title: {
|
16
|
-
top_left: ' file1 '
|
17
|
-
},
|
18
|
-
style: {
|
19
|
-
fg: :bright_yellow,
|
20
|
-
bg: :blue,
|
21
|
-
border: {
|
22
|
-
fg: :bright_yellow,
|
23
|
-
bg: :blue
|
24
|
-
}
|
25
|
-
}
|
26
|
-
) do
|
27
|
-
"Drawing a box in terminal emulator"
|
28
|
-
end
|
29
|
-
|
30
|
-
box_2 = TTY::Box.frame(
|
31
|
-
top: 8,
|
32
|
-
left: 34,
|
33
|
-
width: 30,
|
34
|
-
height: 10,
|
35
|
-
border: :thick,
|
36
|
-
align: :center,
|
37
|
-
padding: 3,
|
38
|
-
title: {
|
39
|
-
top_left: ' file2 '
|
40
|
-
},
|
41
|
-
style: {
|
42
|
-
fg: :bright_yellow,
|
43
|
-
bg: :blue,
|
44
|
-
border: {
|
45
|
-
fg: :bright_yellow,
|
46
|
-
bg: :blue
|
47
|
-
}
|
48
|
-
}
|
49
|
-
) do
|
50
|
-
"Drawing a box in terminal emulator"
|
51
|
-
end
|
52
|
-
|
53
|
-
puts box_1 + box_2
|
54
|
-
print "\n" * 5
|