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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f4d14d40ab0bd1c8030ad5f1cbd706e2dd884ea9eb7f1a251e3b41b3839e7c6
4
- data.tar.gz: 4236c0e2eca6dab6802360067eb31774abd70f9e82d0bb54e8d46d157338fc31
3
+ metadata.gz: 66cd38e818e47ac372868586d8a76cdeb41a98aa9efc59430ec89acb84629410
4
+ data.tar.gz: d96e96b93e46a9ed8b7432632618af9c54e4da5f9575df820c6f77987104baf2
5
5
  SHA512:
6
- metadata.gz: e02a01c723e2d3daa1353a7ba5cec72cbd6f657d26e8e24fc1b7f209b0010a3fa8805292bd3129c4c64c23e857395356d51ada371d0005e8ec6c030e8eb20989
7
- data.tar.gz: 57296652a8991121efdccdd00bb74c6d2ca5068cb765236ff3f787e05162505b0c63ed27c2ae0282dddef1883330cc809dd31300ed5a4361d9c648cfbe5c472c
6
+ metadata.gz: 6bc7bddb63b580b8430d3dcdf596801db37e2f5813c12b8512a89dc9aff4140ebf6478e91d828020ffb182c84ca81b990d3d346c27718491c420a5a0099deca7
7
+ data.tar.gz: 43756dd006eec4de539d4a802c69afa04ca1b56fdd29505725d7001418a9e37f94005fc4606daa6be2564a8a12d2b876cbfb4d2ff1f0b43254c7580a99961b48
@@ -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 your terminal interface.
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 'tty-box'
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 do
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: 'TITLE', bottom_right: 'v1.0'})
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:
@@ -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
- top_left = border.top_left? && border.left? ? send(:"#{border.top_left}_char", border.type) : ""
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.(top_left)),
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.(top_right))
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
- bottom_left = border.bottom_left? && border.left? ? send(:"#{border.bottom_left}_char", border.type) : ""
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.(bottom_left)),
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.(bottom_right))
424
+ bg.(fg.(bottom_right_corner(border)))
365
425
  ].join('')
366
426
  end
367
427
  end # TTY
@@ -23,7 +23,7 @@ module TTY
23
23
  def self.parse(border)
24
24
  case border
25
25
  when Hash
26
- new(border)
26
+ new(**border)
27
27
  when *TTY::Box::BOX_CHARS.keys
28
28
  new(type: border)
29
29
  else
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  module Box
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end # Box
7
7
  end # TTY
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.5.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: 2019-10-08 00:00:00.000000000 Z
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.7.2
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.7.2
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.1.6
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.1.6
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 your terminal interface.
83
+ description: Draw various frames and boxes in the terminal window.
98
84
  email:
99
- - me@piotrmurach.com
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
- - spec/spec_helper.rb
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.0.3
125
+ rubygems_version: 3.1.2
153
126
  signing_key:
154
127
  specification_version: 4
155
- summary: Draw various frames and boxes in your terminal interface.
128
+ summary: Draw various frames and boxes in the terminal window.
156
129
  test_files: []
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- FileList['tasks/**/*.rake'].each(&method(:import))
4
-
5
- desc 'Run all specs'
6
- task ci: %w[ spec ]
7
-
8
- task default: :spec
@@ -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
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-box"
4
-
5
- box = TTY::Box.frame "Drawing a box in", "terminal emulator",
6
- padding: 3, align: :center
7
-
8
- puts box
@@ -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