tabulo 2.6.1 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +58 -0
- data/.gitignore +1 -0
- data/.simplecov +0 -0
- data/CHANGELOG.md +19 -0
- data/README.md +155 -39
- data/VERSION +1 -1
- data/lib/tabulo/cell.rb +76 -16
- data/lib/tabulo/column.rb +4 -0
- data/lib/tabulo/table.rb +47 -29
- data/lib/tabulo/util.rb +3 -1
- data/lib/tabulo/version.rb +1 -1
- data/tabulo.gemspec +2 -2
- metadata +8 -7
- data/.travis.yml +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63054578d0f667075a8e2888d3fc0a2572ec9b8a93e3f74468f058613a7c2f19
|
4
|
+
data.tar.gz: 3d0b8bad1b9ad7fa2949037ec6de683f7b43c7ecc73ca02c53bbb14f926139fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8626993288417bdd75b581819ea4ef9ef79bfcdfb5d18e7469ac2699e303096405f6155b690a289f5bbc27a8235cc80fb4cb0ad8e62146c664f198fefce9a7e
|
7
|
+
data.tar.gz: 9a306fb542677778f3e6998ee83352f87802bf6d07b422846b61d1fe42acdd8b40a914daa87a10e5abe2f84e6d4b8cd5ddc5711e49d9b5d066113b167b4cf4a9
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Tests
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [master]
|
13
|
+
pull_request:
|
14
|
+
branches: [master]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby-version: [
|
22
|
+
'2.2.10',
|
23
|
+
'2.3.8',
|
24
|
+
'2.4.10',
|
25
|
+
'2.5.9',
|
26
|
+
'2.6.8',
|
27
|
+
'2.7.4',
|
28
|
+
'3.0.2',
|
29
|
+
]
|
30
|
+
steps:
|
31
|
+
- uses: actions/checkout@v2
|
32
|
+
- name: Set up Ruby
|
33
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
34
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
35
|
+
uses: ruby/setup-ruby@v1 # Was: uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby-version }}
|
38
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
39
|
+
- name: Run tests
|
40
|
+
run: bundle exec rspec
|
41
|
+
|
42
|
+
- name: Report to Coveralls
|
43
|
+
uses: coverallsapp/github-action@v1.1.2
|
44
|
+
with:
|
45
|
+
github-token: ${{ secrets.github_token }}
|
46
|
+
flag-name: test-${{ matrix.ruby }}-${{ matrix.gemfile }}
|
47
|
+
parallel: true
|
48
|
+
|
49
|
+
finish:
|
50
|
+
needs: test
|
51
|
+
runs-on: ubuntu-latest
|
52
|
+
steps:
|
53
|
+
|
54
|
+
- name: Report completion to Coveralls
|
55
|
+
uses: coverallsapp/github-action@v1.1.2
|
56
|
+
with:
|
57
|
+
github-token: ${{ secrets.github_token }}
|
58
|
+
parallel-finished: true
|
data/.gitignore
CHANGED
data/.simplecov
ADDED
File without changes
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,24 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### v2.7.1
|
4
|
+
|
5
|
+
* Dependency version upgrades
|
6
|
+
* Minor documentation improvements and tweaks
|
7
|
+
|
8
|
+
### v2.7.0
|
9
|
+
|
10
|
+
* Add `wrap_preserve` option, allowing whole words to be preserved when wrapping.
|
11
|
+
* Internal: Use GitHub actions instead of Travis
|
12
|
+
|
13
|
+
### v2.6.3
|
14
|
+
|
15
|
+
* Update dependency versions
|
16
|
+
|
17
|
+
### v2.6.2
|
18
|
+
|
19
|
+
* Ensure line break character sequences are property formatted in output, regardless
|
20
|
+
of whether they are "\r\n", "\r" or "\n".
|
21
|
+
|
3
22
|
### v2.6.1
|
4
23
|
|
5
24
|
* Update dependency versions
|
data/README.md
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Gem Version][GV img]][Gem Version]
|
4
4
|
[![Documentation][DC img]][Documentation]
|
5
|
-
[![Coverage Status][CS img]][Coverage Status]
|
6
5
|
[![Build Status][BS img]][Build Status]
|
7
|
-
[![
|
6
|
+
[![Coverage Status][CS img]][Coverage Status]
|
8
7
|
[![Awesome][AR img]][Awesome Ruby]
|
9
8
|
|
10
9
|
Tabulo is a Ruby library for generating plain text tables (also known as “terminal tables”
|
@@ -16,19 +15,19 @@ or “ASCII tables”). It is both highly configurable and very easy to
|
|
16
15
|
_Quick API:_
|
17
16
|
|
18
17
|
```
|
19
|
-
> puts Tabulo::Table.new(User.all, :id, :first_name, :last_name
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
> puts Tabulo::Table.new(User.all, :id, :first_name, :last_name).pack
|
19
|
+
+----+------------+-----------+
|
20
|
+
| id | first_name | last_name |
|
21
|
+
+----+------------+-----------+
|
22
|
+
| 1 | John | Citizen |
|
23
|
+
| 2 | Jane | Doe |
|
24
|
+
+----+------------+-----------+
|
26
25
|
```
|
27
26
|
|
28
27
|
_Full API:_
|
29
28
|
|
30
29
|
```
|
31
|
-
table = Tabulo::Table.new(User.all
|
30
|
+
table = Tabulo::Table.new(User.all) do |t|
|
32
31
|
t.add_column("ID", &:id)
|
33
32
|
t.add_column("First name", &:first_name)
|
34
33
|
t.add_column("Last name") { |user| user.last_name.upcase }
|
@@ -37,12 +36,12 @@ end
|
|
37
36
|
|
38
37
|
```
|
39
38
|
> puts table.pack
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
+----+------------+-----------+
|
40
|
+
| ID | First name | Last name |
|
41
|
+
+----+------------+-----------+
|
42
|
+
| 1 | John | CITIZEN |
|
43
|
+
| 2 | Jane | DOE |
|
44
|
+
+----+------------+-----------+
|
46
45
|
```
|
47
46
|
|
48
47
|
<a name="features"></a>
|
@@ -63,6 +62,7 @@ end
|
|
63
62
|
* The header row can be [repeated](#repeating-headers) at arbitrary intervals
|
64
63
|
* Newlines within cell content are correctly handled
|
65
64
|
* Multibyte Unicode characters are correctly handled
|
65
|
+
* Option to [preserve whole words](#preserve-words) when wrapping content
|
66
66
|
* Apply [colours](#colours-and-styling) and other styling to table content and borders, without breaking the table
|
67
67
|
* Easily [transpose](#transposition) the table, so that rows are swapped with columns
|
68
68
|
* Choose from multiple [border configurations](#borders), including Markdown, “ASCII”, and smoothly
|
@@ -84,6 +84,7 @@ Tabulo has also been ported to Crystal (with some modifications): see [Tablo](ht
|
|
84
84
|
* [Full API](#quick-api)
|
85
85
|
* [Column labels _vs_ headers](#labels-headers)
|
86
86
|
* [Positioning columns](#column-positioning)
|
87
|
+
* [Extracting column content from a hash or array](#from-arrays-hashes)
|
87
88
|
* [Removing columns](#removing-columns)
|
88
89
|
* [Adding a title](#title)
|
89
90
|
* [Cell alignment](#cell-alignment)
|
@@ -92,6 +93,7 @@ Tabulo has also been ported to Crystal (with some modifications): see [Tablo](ht
|
|
92
93
|
* [Automating column widths](#automating-column-widths)
|
93
94
|
* [Configuring padding](#configuring-padding)
|
94
95
|
* [Overflow handling](#overflow-handling)
|
96
|
+
* [Wrapping at word boundaries](#preserve-words)
|
95
97
|
* [Manual cell wrapping](#manual-wrapping)
|
96
98
|
* [Formatting cell values](#formatting-cell-values)
|
97
99
|
* [Colours and other styling](#colours-and-styling)
|
@@ -280,6 +282,69 @@ table.add_column(:even?, before: :odd?)
|
|
280
282
|
+--------------+--------------+--------------+
|
281
283
|
```
|
282
284
|
|
285
|
+
<a name="from-arrays-hashes"></a>
|
286
|
+
#### Extracting column content from a hash or array [↑](#contents)
|
287
|
+
|
288
|
+
Sometimes the data source for the table may be a collection of hashes or arrays. For example:
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
data = [
|
292
|
+
{ english: "hello", portuguese: "bom dia" },
|
293
|
+
{ english: "goodbye", portuguese: "adeus" },
|
294
|
+
]
|
295
|
+
```
|
296
|
+
|
297
|
+
or
|
298
|
+
|
299
|
+
```ruby
|
300
|
+
data = [
|
301
|
+
["hello", "bom dia"],
|
302
|
+
["goodbye", "adeus"],
|
303
|
+
]
|
304
|
+
```
|
305
|
+
|
306
|
+
To tabulate such a collection, simply use the same mechanism as described above, passing a block to
|
307
|
+
the `add_column` method to tell Tabulo how to extract the data for each column from a row. For
|
308
|
+
example, to tabulate the first example above, you could do something like this:
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
table = Tabulo::Table.new(data) do |t|
|
312
|
+
t.add_column("English") { |h| h[:english] }
|
313
|
+
t.add_column("Portuguese") { |h| h[:portuguese] }
|
314
|
+
end
|
315
|
+
|
316
|
+
puts table
|
317
|
+
```
|
318
|
+
|
319
|
+
For the second example, you could do the following:
|
320
|
+
|
321
|
+
```ruby
|
322
|
+
table = Tabulo::Table.new(data) do |t|
|
323
|
+
t.add_column("English") { |a| a[0] }
|
324
|
+
t.add_column("Portuguese") { |a| a[1] }
|
325
|
+
end
|
326
|
+
|
327
|
+
puts table
|
328
|
+
```
|
329
|
+
|
330
|
+
In both cases, the output will be as follows:
|
331
|
+
|
332
|
+
```
|
333
|
+
+--------------+--------------+
|
334
|
+
| English | Portuguese |
|
335
|
+
+--------------+--------------+
|
336
|
+
| hello | bom dia |
|
337
|
+
| goodbye | adeus |
|
338
|
+
+--------------+--------------+
|
339
|
+
```
|
340
|
+
|
341
|
+
If you have previously used other terminal tabulation libraries, you may be accustomed to being _required_
|
342
|
+
to place your data into an array of hashes or arrays before you can tabulate them. Tabulo, however,
|
343
|
+
offers an API that is more general and flexible than this; your data source can be _any_
|
344
|
+
enumerable collection (not just an array), and each item in that collection can be _any_ object (not
|
345
|
+
necessarily an array or a hash). However, as shown above, it is still straightforward to tabulate an
|
346
|
+
array of hashes or arrays, if your data source happens to take that form.
|
347
|
+
|
283
348
|
<a name="removing-columns"></a>
|
284
349
|
### Removing columns [↑](#contents)
|
285
350
|
|
@@ -596,11 +661,51 @@ table = Tabulo::Table.new(
|
|
596
661
|
The character used to indicate truncation, which defaults to `~`, can be configured using the
|
597
662
|
`truncation_indicator` option passed to `Table.new`.
|
598
663
|
|
664
|
+
<a name="preserve-words"></a>
|
665
|
+
#### Wrapping at word boundaries [↑](#contents)
|
666
|
+
|
667
|
+
By passing `:word` to the `wrap_preserve` option on either table initialization (for all columns),
|
668
|
+
or when calling `add_column` (for an individual column), whole words can be preserved when wrapping:
|
669
|
+
|
670
|
+
```ruby
|
671
|
+
sentences = [
|
672
|
+
"Words are preserved.",
|
673
|
+
"Excessively long words may still be split to fit into the configured column width.",
|
674
|
+
]
|
675
|
+
table = Tabulo::Table.new(sentences, :itself, :length, column_width: 10, wrap_preserve: :word)
|
676
|
+
```
|
677
|
+
|
678
|
+
```
|
679
|
+
> puts table
|
680
|
+
+------------+------------+
|
681
|
+
| itself | length |
|
682
|
+
+------------+------------+
|
683
|
+
| Words are | 20 |
|
684
|
+
| preserved. | |
|
685
|
+
| Excessivel | 82 |
|
686
|
+
| y long | |
|
687
|
+
| words may | |
|
688
|
+
| still be | |
|
689
|
+
| split to | |
|
690
|
+
| fit into | |
|
691
|
+
| the | |
|
692
|
+
| configured | |
|
693
|
+
| column | |
|
694
|
+
| width. | |
|
695
|
+
+------------+------------+
|
696
|
+
```
|
697
|
+
|
698
|
+
When wrapping cell content, Tabulo will never insert hyphens itself, although it will recognize existing
|
699
|
+
hyphens, m-dashes and n-dashes as word boundaries.
|
700
|
+
|
701
|
+
The `wrap_preserve` option defaults to the value `:rune`, meaning by default it will _not_ respect word
|
702
|
+
boundaries when wrapping (although it will always preserve whole multibyte Unicode characters).
|
703
|
+
|
599
704
|
<a name="manual-wrapping"></a>
|
600
705
|
#### Manual cell wrapping [↑](#contents)
|
601
706
|
|
602
707
|
You can “manually” wrap the content of a title, header or body cell at a particular
|
603
|
-
point, simply by placing a newline character at that point:
|
708
|
+
point, simply by placing a newline character, at that point:
|
604
709
|
|
605
710
|
```ruby
|
606
711
|
table = Tabulo::Table.new(1..3) do |t|
|
@@ -622,6 +727,11 @@ end
|
|
622
727
|
+--------------+--------------+--------------+
|
623
728
|
```
|
624
729
|
|
730
|
+
Tabulo will treat any of the character combinations `"\n"`, `"\r\n"` or `"\r"` equally, as a line break,
|
731
|
+
regardless of the platform it’s currently being run on. This ensures things are formatted as
|
732
|
+
expected if, for example, you are examining content that was produced on another platform from
|
733
|
+
the one you’re running Tabulo on.
|
734
|
+
|
625
735
|
<a name="formatting-cell-values"></a>
|
626
736
|
### Formatting cell values [↑](#contents)
|
627
737
|
|
@@ -683,7 +793,7 @@ the table.
|
|
683
793
|
The `formatter` callback also has an alternative, 2-parameter version. If `formatter` is passed
|
684
794
|
a 2-parameter callable, the second parameter will be given a `CellData` instance,
|
685
795
|
containing additional information about the cell that may be useful in determining how to format
|
686
|
-
it—see the [documentation](https://www.rubydoc.info/gems/tabulo/2.
|
796
|
+
it—see the [documentation](https://www.rubydoc.info/gems/tabulo/2.7.1/Tabulo/CellData.html)
|
687
797
|
for details.
|
688
798
|
|
689
799
|
<a name="colours-and-styling"></a>
|
@@ -729,7 +839,7 @@ number is even). The second parameter represents the formatted string value of t
|
|
729
839
|
content after any processing by the [formatter](#formatting-cell-values). The third and fourth
|
730
840
|
parameters are optional, and contain further information about the cell and its contents that may be useful in
|
731
841
|
determining how to style it. See the
|
732
|
-
[documentation](https://www.rubydoc.info/gems/tabulo/2.
|
842
|
+
[documentation](https://www.rubydoc.info/gems/tabulo/2.7.1/Tabulo/Table#add_column-instance_method) for details.
|
733
843
|
|
734
844
|
If the content of a cell is wrapped over multiple lines, then the `styler` will be called once
|
735
845
|
per line, so that each line of the cell will have the escape sequence applied to it separately
|
@@ -749,7 +859,7 @@ table.add_column(:even?, header_styler: -> (s) { "\033[32m#{s}\033[0m" })
|
|
749
859
|
```
|
750
860
|
|
751
861
|
The `header_styler` option accepts a 1-, 2- or 3-parameter callable. See the
|
752
|
-
[documentation](https://www.rubydoc.info/gems/tabulo/2.
|
862
|
+
[documentation](https://www.rubydoc.info/gems/tabulo/2.7.1/Tabulo/Table#add_column-instance_method)
|
753
863
|
for details.
|
754
864
|
|
755
865
|
<a name="styling-title"></a>
|
@@ -763,7 +873,7 @@ table = Tabulo::Table.new(1..5, :itself, :even?, :odd?, title: "Numbers", title_
|
|
763
873
|
```
|
764
874
|
|
765
875
|
The `title_styler` option accepts a 1- or 2-parameter callable. See the
|
766
|
-
[documentation](https://www.rubydoc.info/gems/tabulo/2.
|
876
|
+
[documentation](https://www.rubydoc.info/gems/tabulo/2.7.1/Tabulo/Table#initialize-instance_method)
|
767
877
|
for details.
|
768
878
|
|
769
879
|
<a name="styling-borders"></a>
|
@@ -958,7 +1068,7 @@ a new table in which the rows and columns are swapped:
|
|
958
1068
|
By default, a header row is added to the new table, showing the string value of the element
|
959
1069
|
represented in that column. This can be configured, however, along with other aspects of
|
960
1070
|
`transpose`’s behaviour. For details, see the
|
961
|
-
[documentation](https://www.rubydoc.info/gems/tabulo/2.
|
1071
|
+
[documentation](https://www.rubydoc.info/gems/tabulo/2.7.1/Tabulo/Table#transpose-instance_method).
|
962
1072
|
|
963
1073
|
<a name="borders"></a>
|
964
1074
|
### Configuring borders [↑](#contents)
|
@@ -1014,6 +1124,10 @@ This is done using the `border` option passed to `Table.new`. The options are as
|
|
1014
1124
|
└──────────────┴──────────────┴──────────────┘
|
1015
1125
|
```
|
1016
1126
|
|
1127
|
+
_Note: The unicode characters used for the `:modern` border may not render properly
|
1128
|
+
when viewing this documentation on some browsers or devices. This doesn’t reflect any brokenness
|
1129
|
+
in `tabulo` itself._
|
1130
|
+
|
1017
1131
|
`:markdown`—renders a GitHub flavoured Markdown table:
|
1018
1132
|
|
1019
1133
|
```
|
@@ -1103,6 +1217,10 @@ generally support adding a caption (i.e. title) element to tables.
|
|
1103
1217
|
────────────── ────────────── ──────────────
|
1104
1218
|
```
|
1105
1219
|
|
1220
|
+
_Note: The unicode characters used for the `:reduced_modern` border may not render properly
|
1221
|
+
when viewing this documentation on some browsers or devices. This doesn’t reflect any brokenness
|
1222
|
+
in `tabulo` itself._
|
1223
|
+
|
1106
1224
|
`:classic`—reproduces the default behaviour in Tabulo v1; this is like the `:ascii` option,
|
1107
1225
|
but without a bottom border:
|
1108
1226
|
|
@@ -1156,16 +1274,16 @@ every Nth row. For example:
|
|
1156
1274
|
If you want a line before every row, pass `1` to `row_divider_frequency`. For example:
|
1157
1275
|
|
1158
1276
|
```
|
1159
|
-
> puts Tabulo::Table.new(1..3, :itself, :even?, :odd?,
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1277
|
+
> puts Tabulo::Table.new(1..3, :itself, :even?, :odd?, row_divider_frequency: 1)
|
1278
|
+
+--------------+--------------+--------------+
|
1279
|
+
| itself | even? | odd? |
|
1280
|
+
+--------------+--------------+--------------+
|
1281
|
+
| 1 | false | true |
|
1282
|
+
+--------------+--------------+--------------+
|
1283
|
+
| 2 | true | false |
|
1284
|
+
+--------------+--------------+--------------+
|
1285
|
+
| 3 | false | true |
|
1286
|
+
+--------------+--------------+--------------+
|
1169
1287
|
```
|
1170
1288
|
|
1171
1289
|
<a name="freezing-a-table"></a>
|
@@ -1341,15 +1459,13 @@ The gem is available as open source under the terms of the [MIT
|
|
1341
1459
|
License](http://opensource.org/licenses/MIT).
|
1342
1460
|
|
1343
1461
|
[Gem Version]: https://rubygems.org/gems/tabulo
|
1344
|
-
[Documentation]: http://www.rubydoc.info/gems/tabulo/2.
|
1345
|
-
[Build Status]: https://
|
1346
|
-
[Coverage Status]: https://coveralls.io/
|
1347
|
-
[Code Climate]: https://codeclimate.com/github/matt-harvey/tabulo
|
1462
|
+
[Documentation]: http://www.rubydoc.info/gems/tabulo/2.7.1
|
1463
|
+
[Build Status]: https://github.com/matt-harvey/tabulo/actions/workflows/tests.yml
|
1464
|
+
[Coverage Status]: https://coveralls.io/github/matt-harvey/tabulo
|
1348
1465
|
[Awesome Ruby]: https://github.com/markets/awesome-ruby#cli-utilities
|
1349
1466
|
|
1350
1467
|
[GV img]: https://img.shields.io/gem/v/tabulo.svg
|
1351
|
-
[DC img]: https://img.shields.io/badge/documentation-v2.
|
1352
|
-
[BS img]: https://
|
1468
|
+
[DC img]: https://img.shields.io/badge/documentation-v2.7.1-blue.svg
|
1469
|
+
[BS img]: https://github.com/matt-harvey/tabulo/actions/workflows/tests.yml/badge.svg
|
1353
1470
|
[CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg
|
1354
|
-
[CC img]: https://codeclimate.com/github/matt-harvey/tabulo/badges/gpa.svg
|
1355
1471
|
[AR img]: https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.1
|
data/lib/tabulo/cell.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require "unicode/display_width"
|
2
4
|
|
3
5
|
module Tabulo
|
@@ -19,6 +21,7 @@ module Tabulo
|
|
19
21
|
styler:,
|
20
22
|
truncation_indicator:,
|
21
23
|
value:,
|
24
|
+
wrap_preserve:,
|
22
25
|
width:)
|
23
26
|
|
24
27
|
@alignment = alignment
|
@@ -30,6 +33,7 @@ module Tabulo
|
|
30
33
|
@styler = styler
|
31
34
|
@truncation_indicator = truncation_indicator
|
32
35
|
@value = value
|
36
|
+
@wrap_preserve = wrap_preserve
|
33
37
|
@width = width
|
34
38
|
end
|
35
39
|
|
@@ -100,30 +104,86 @@ module Tabulo
|
|
100
104
|
end
|
101
105
|
|
102
106
|
def calculate_subcells
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
subsubcell_width
|
112
|
-
|
113
|
-
|
107
|
+
case @wrap_preserve
|
108
|
+
when :rune
|
109
|
+
line_index = 0
|
110
|
+
formatted_content.split(Util::NEWLINE, -1).flat_map do |substr|
|
111
|
+
subsubcells, subsubcell, subsubcell_width = [], String.new(""), 0
|
112
|
+
|
113
|
+
substr.scan(/\X/).each do |rune|
|
114
|
+
rune_width = Unicode::DisplayWidth.of(rune)
|
115
|
+
if subsubcell_width + rune_width > @width
|
116
|
+
subsubcells << style_and_align_cell_content(subsubcell, line_index)
|
117
|
+
subsubcell_width = 0
|
118
|
+
subsubcell.clear
|
119
|
+
line_index += 1
|
120
|
+
end
|
121
|
+
|
122
|
+
subsubcell << rune
|
123
|
+
subsubcell_width += rune_width
|
114
124
|
end
|
115
125
|
|
116
|
-
|
117
|
-
|
126
|
+
subsubcells << style_and_align_cell_content(subsubcell, line_index)
|
127
|
+
line_index += 1
|
128
|
+
subsubcells
|
118
129
|
end
|
130
|
+
when :word
|
131
|
+
line_index = 0
|
132
|
+
formatted_content.split(Util::NEWLINE, -1).flat_map do |substr|
|
133
|
+
subsubcells, subsubcell, subsubcell_width = [], String.new(""), 0
|
134
|
+
|
135
|
+
substr.split(/(?<= |\-|\—|\–)\b/).each do |word|
|
136
|
+
# Each word looks like "this " or like "this-".
|
137
|
+
word_width = Unicode::DisplayWidth.of(word)
|
138
|
+
combined_width = subsubcell_width + word_width
|
139
|
+
if combined_width - 1 == @width && word[-1] == " "
|
140
|
+
# do nothing, as we're on the final word of the line and
|
141
|
+
# the space at the end will be chopped off.
|
142
|
+
elsif combined_width > @width
|
143
|
+
content = style_and_align_cell_content(subsubcell, line_index)
|
144
|
+
if content.strip.length != 0
|
145
|
+
subsubcells << content
|
146
|
+
subsubcell_width = 0
|
147
|
+
subsubcell.clear
|
148
|
+
line_index += 1
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
if word_width >= @width
|
153
|
+
word.scan(/\X/).each do |rune|
|
154
|
+
rune_width = Unicode::DisplayWidth.of(rune)
|
155
|
+
if subsubcell_width + rune_width > @width
|
156
|
+
if rune != " "
|
157
|
+
content = style_and_align_cell_content(subsubcell, line_index)
|
158
|
+
subsubcells << content
|
159
|
+
subsubcell_width = 0
|
160
|
+
subsubcell.clear
|
161
|
+
line_index += 1
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
subsubcell << rune
|
166
|
+
subsubcell_width += rune_width
|
167
|
+
end
|
168
|
+
else
|
169
|
+
subsubcell << word
|
170
|
+
subsubcell_width += word_width
|
171
|
+
end
|
172
|
+
end
|
119
173
|
|
120
|
-
|
121
|
-
|
122
|
-
|
174
|
+
content = style_and_align_cell_content(subsubcell, line_index)
|
175
|
+
subsubcells << content
|
176
|
+
line_index += 1
|
177
|
+
subsubcells
|
178
|
+
end
|
123
179
|
end
|
124
180
|
end
|
125
181
|
|
126
182
|
def style_and_align_cell_content(content, line_index)
|
183
|
+
if @wrap_preserve == :word
|
184
|
+
content.strip!
|
185
|
+
end
|
186
|
+
|
127
187
|
padding = Util.max(@width - Unicode::DisplayWidth.of(content), 0)
|
128
188
|
left_padding, right_padding =
|
129
189
|
case real_alignment
|
data/lib/tabulo/column.rb
CHANGED
@@ -22,6 +22,7 @@ module Tabulo
|
|
22
22
|
right_padding:,
|
23
23
|
styler:,
|
24
24
|
truncation_indicator:,
|
25
|
+
wrap_preserve:,
|
25
26
|
width:)
|
26
27
|
|
27
28
|
@align_body = align_body
|
@@ -50,6 +51,7 @@ module Tabulo
|
|
50
51
|
@padding_character = padding_character
|
51
52
|
@styler = styler || -> (_, s) { s }
|
52
53
|
@truncation_indicator = truncation_indicator
|
54
|
+
@wrap_preserve = wrap_preserve
|
53
55
|
@width = width
|
54
56
|
end
|
55
57
|
|
@@ -67,6 +69,7 @@ module Tabulo
|
|
67
69
|
styler: @header_styler,
|
68
70
|
truncation_indicator: @truncation_indicator,
|
69
71
|
value: @header,
|
72
|
+
wrap_preserve: @wrap_preserve,
|
70
73
|
width: @width,
|
71
74
|
)
|
72
75
|
end
|
@@ -85,6 +88,7 @@ module Tabulo
|
|
85
88
|
styler: @styler,
|
86
89
|
truncation_indicator: @truncation_indicator,
|
87
90
|
value: body_cell_value(source, row_index: row_index, column_index: column_index),
|
91
|
+
wrap_preserve: @wrap_preserve,
|
88
92
|
width: @width,
|
89
93
|
)
|
90
94
|
end
|
data/lib/tabulo/table.rb
CHANGED
@@ -35,17 +35,17 @@ module Tabulo
|
|
35
35
|
# be unique. Each element of the Array will be used to create a column whose content is
|
36
36
|
# created by calling the corresponding method on each element of sources. Note
|
37
37
|
# the {#add_column} method is a much more flexible way to set up columns on the table.
|
38
|
-
# @param [:left, :right, :center, :auto] align_body
|
38
|
+
# @param [:left, :right, :center, :auto] align_body Determines the alignment of body cell
|
39
39
|
# (i.e. non-header) content within columns in this Table. Can be overridden for individual columns
|
40
40
|
# using the <tt>align_body</tt> option passed to {#add_column}. If passed <tt>:auto</tt>,
|
41
41
|
# alignment is determined by cell content, with numbers aligned right, booleans
|
42
42
|
# center-aligned, and other values left-aligned.
|
43
|
-
# @param [:left, :right, :center] align_header
|
43
|
+
# @param [:left, :right, :center] align_header Determines the alignment of header text
|
44
44
|
# for columns in this Table. Can be overridden for individual columns using the
|
45
45
|
# <tt>align_header</tt> option passed to {#add_column}
|
46
|
-
# @param [:left, :right, :center] align_header
|
46
|
+
# @param [:left, :right, :center] align_header Determines the alignment of the table
|
47
47
|
# title, if present.
|
48
|
-
# @param [:ascii, :markdown, :modern, :blank, nil] border
|
48
|
+
# @param [:ascii, :markdown, :modern, :blank, nil] border Determines the characters used
|
49
49
|
# for the Table border, including both the characters around the outside of table, and the lines drawn
|
50
50
|
# within the table to separate columns from each other and the header row from the Table body.
|
51
51
|
# If <tt>nil</tt>, then the value of {DEFAULT_BORDER} will be used.
|
@@ -63,7 +63,7 @@ module Tabulo
|
|
63
63
|
# borders and intersection characters consisting of whitespace only
|
64
64
|
# - `:classic` Like `:ascii`, but does not have a horizontal line at the bottom of the
|
65
65
|
# table. This reproduces the default behaviour in `tabulo` v1.
|
66
|
-
# @param [nil, #to_proc] border_styler
|
66
|
+
# @param [nil, #to_proc] border_styler A lambda or other callable object taking
|
67
67
|
# a single parameter, representing a section of the table's borders (which for this purpose
|
68
68
|
# include any horizontal and vertical lines inside the table), and returning a string.
|
69
69
|
# If passed <tt>nil</tt>, then no additional styling will be applied to borders. If passed a
|
@@ -72,7 +72,7 @@ module Tabulo
|
|
72
72
|
# <tt>border_styler</tt> is not taken into consideration by the internal table rendering calculations
|
73
73
|
# Thus it can be used to apply ANSI escape codes to border characters, to colour the borders
|
74
74
|
# for example, without breaking the table formatting.
|
75
|
-
# @param [nil, Integer, Array] column_padding
|
75
|
+
# @param [nil, Integer, Array] column_padding Determines the amount of blank space with which to pad
|
76
76
|
# either side of each column. If passed an Integer, then the given amount of padding is
|
77
77
|
# applied to each side of each column. If passed a two-element Array, then the first element of the
|
78
78
|
# Array indicates the amount of padding to apply to the left of each column, and the second
|
@@ -80,26 +80,26 @@ module Tabulo
|
|
80
80
|
# individual columns using the `padding` option of {#add_column}.
|
81
81
|
# @param [Integer, nil] column_width The default column width for columns in this
|
82
82
|
# table, not excluding padding. If <tt>nil</tt>, then {DEFAULT_COLUMN_WIDTH} will be used.
|
83
|
-
# @param [nil, #to_proc] formatter
|
83
|
+
# @param [nil, #to_proc] formatter The default formatter for columns in this
|
84
84
|
# table. See `formatter` option of {#add_column} for details.
|
85
85
|
# @param [:start, nil, Integer] header_frequency (:start) Controls the display of column headers.
|
86
86
|
# If passed <tt>:start</tt>, headers will be shown at the top of the table only. If passed <tt>nil</tt>,
|
87
87
|
# headers will not be shown. If passed an Integer N (> 0), headers will be shown at the top of the table,
|
88
88
|
# then repeated every N rows.
|
89
|
-
# @param [nil, #to_proc] header_styler
|
89
|
+
# @param [nil, #to_proc] header_styler The default header styler for columns in this
|
90
90
|
# table. See `header_styler` option of {#add_column} for details.
|
91
|
-
# @param [nil, Integer] row_divider_frequency
|
91
|
+
# @param [nil, Integer] row_divider_frequency Controls the display of horizontal row dividers within
|
92
92
|
# the table body. If passed <tt>nil</tt>, dividers will not be shown. If passed an Integer N (> 0),
|
93
93
|
# dividers will be shown after every N rows. The characters used to form the dividers are
|
94
94
|
# determined by the `border` option, and are the same as those used to form the bottom edge of the
|
95
95
|
# header row.
|
96
|
-
# @param [nil, #to_proc] styler
|
96
|
+
# @param [nil, #to_proc] styler The default styler for columns in this table. See `styler`
|
97
97
|
# option of {#add_column} for details.
|
98
|
-
# @param [nil, String] title
|
98
|
+
# @param [nil, String] title If passed a String, will arrange for a title to be shown at the top
|
99
99
|
# of the table. Note: If the `border` option is set to `:markdown`, adding a title to the table
|
100
100
|
# will cause it to cease being valid Markdown when rendered, since Markdown engines do not generally
|
101
101
|
# support adding a caption element (i.e. title) to tables.
|
102
|
-
# @param [nil, #to_proc] title_styler
|
102
|
+
# @param [nil, #to_proc] title_styler A lambda or other callable object that will
|
103
103
|
# determine the colors or other styling applied to the table title. Can be passed
|
104
104
|
# <tt>nil</tt>, or can be passed a callable that takes either 1 or 2 parametes:
|
105
105
|
# * If passed <tt>nil</tt>, then no additional styling will be applied to the title.
|
@@ -124,6 +124,16 @@ module Tabulo
|
|
124
124
|
# cell's content has been truncated. If omitted or passed <tt>nil</tt>,
|
125
125
|
# defaults to {DEFAULT_TRUNCATION_INDICATOR}. If passed something other than <tt>nil</tt> or
|
126
126
|
# a single-character String, raises {InvalidTruncationIndicatorError}.
|
127
|
+
# @param [Symbol] wrap_preserve Specifies what unit of text the wrapping mechanism will try to
|
128
|
+
# preserve intact when wrapping column content when the column width is reached.
|
129
|
+
# * If passed `:rune` (the default), then it will wrap at the "character" level (approximately
|
130
|
+
# speaking, the Unicode grapheme cluster level). This means the maximum number of what
|
131
|
+
# readers usually think of as "characters" will be fit on each line, within the column's allocated
|
132
|
+
# width, before contininuing to a new line, even if it means splitting a word in the middle.
|
133
|
+
# * If passed `:word`, then it will wrap in such a way as to avoid splitting words, where
|
134
|
+
# "words" are defined as units of text separated by spaces or dashes (hyphens, m-dashes and
|
135
|
+
# n-dashes). Whitespace will be used to pad lines as required. Already-hyphenated may will be split
|
136
|
+
# at the hyphen, however hyphens will not be inserted in non-hyphenated words.
|
127
137
|
# @param [nil, Integer] wrap_body_cells_to Controls wrapping behaviour for table cells (excluding
|
128
138
|
# headers), if their content is longer than the column's fixed width. If passed <tt>nil</tt>, content will
|
129
139
|
# be wrapped for as many rows as required to accommodate it. If passed an Integer N (> 0), content will be
|
@@ -141,7 +151,7 @@ module Tabulo
|
|
141
151
|
def initialize(sources, *columns, align_body: :auto, align_header: :center, align_title: :center,
|
142
152
|
border: nil, border_styler: nil, column_padding: nil, column_width: nil, formatter: :to_s.to_proc,
|
143
153
|
header_frequency: :start, header_styler: nil, row_divider_frequency: nil, styler: nil,
|
144
|
-
title: nil, title_styler: nil, truncation_indicator: nil, wrap_body_cells_to: nil,
|
154
|
+
title: nil, title_styler: nil, truncation_indicator: nil, wrap_preserve: :rune, wrap_body_cells_to: nil,
|
145
155
|
wrap_header_cells_to: nil)
|
146
156
|
|
147
157
|
@sources = sources
|
@@ -167,6 +177,7 @@ module Tabulo
|
|
167
177
|
@title_styler = title_styler
|
168
178
|
@truncation_indicator = validate_character(truncation_indicator,
|
169
179
|
DEFAULT_TRUNCATION_INDICATOR, InvalidTruncationIndicatorError, "truncation indicator")
|
180
|
+
@wrap_preserve = wrap_preserve
|
170
181
|
@wrap_body_cells_to = wrap_body_cells_to
|
171
182
|
@wrap_header_cells_to = wrap_header_cells_to
|
172
183
|
|
@@ -184,24 +195,24 @@ module Tabulo
|
|
184
195
|
# a method to be called on each item in the table sources to provide the content
|
185
196
|
# for this column. If a String is passed as the label, then it will be converted to
|
186
197
|
# a Symbol for the purpose of serving as this label.
|
187
|
-
# @param [:left, :center, :right, :auto, nil] align_body
|
198
|
+
# @param [:left, :center, :right, :auto, nil] align_body Specifies how the cell body contents
|
188
199
|
# should be aligned. If <tt>nil</tt> is passed, then the alignment is determined
|
189
200
|
# by the Table-level setting passed to the <tt>align_body</tt> option on Table initialization
|
190
201
|
# (which itself defaults to <tt>:auto</tt>). Otherwise this option determines the alignment of
|
191
202
|
# this column. If <tt>:auto</tt> is passed, the alignment is determined by the type of the cell
|
192
203
|
# value, with numbers aligned right, booleans center-aligned, and other values left-aligned.
|
193
204
|
# Note header text alignment is configured separately using the :align_header param.
|
194
|
-
# @param [:left, :center, :right, nil] align_header
|
205
|
+
# @param [:left, :center, :right, nil] align_header Specifies how the header text
|
195
206
|
# should be aligned. If <tt>nil</tt> is passed, then the alignment is determined
|
196
207
|
# by the Table-level setting passed to the <tt>align_header</tt> (which itself defaults
|
197
208
|
# to <tt>:center</tt>). Otherwise, this option determines the alignment of the header
|
198
209
|
# content for this column.
|
199
|
-
# @param [Symbol, String, Integer, nil] before
|
210
|
+
# @param [Symbol, String, Integer, nil] before The label of the column before (i.e. to
|
200
211
|
# the left of) which the new column should inserted. If <tt>nil</tt> is passed, it will be
|
201
212
|
# inserted after all other columns. If there is no column with the given label, then an
|
202
213
|
# {InvalidColumnLabelError} will be raised. A non-Integer labelled column can be identified
|
203
214
|
# in either String or Symbol form for this purpose.
|
204
|
-
# @param [#to_proc] formatter
|
215
|
+
# @param [#to_proc] formatter A lambda or other callable object that
|
205
216
|
# will be passed the calculated value of each cell to determine how it should be displayed. This
|
206
217
|
# is distinct from the extractor and the styler (see below).
|
207
218
|
# For example, if the extractor for this column generates a Date, then the formatter might format
|
@@ -219,7 +230,7 @@ module Tabulo
|
|
219
230
|
# whether the {Cell} is an odd- or even-numbered {Row}, to arrange for different formatting
|
220
231
|
# to be applied to alternating rows.
|
221
232
|
# See the documentation for {CellData} for more.
|
222
|
-
# @param [nil, #to_s] header
|
233
|
+
# @param [nil, #to_s] header Text to be displayed in the column header. If passed nil,
|
223
234
|
# the column's label will also be used as its header text.
|
224
235
|
# @param [nil, #to_proc] header_styler (nil) A lambda or other callable object that will
|
225
236
|
# determine the colors or other styling applied to the header content. Can be passed
|
@@ -249,14 +260,14 @@ module Tabulo
|
|
249
260
|
#
|
250
261
|
# Note that if the header content is truncated, then any <tt>header_styler</tt> will be applied to the
|
251
262
|
# truncation indicator character as well as to the truncated content.
|
252
|
-
# @param [nil, Integer, Array] padding
|
263
|
+
# @param [nil, Integer, Array] padding Determines the amount of blank space with which to
|
253
264
|
# pad either side of the column. If passed nil, then the `column_padding` setting of the
|
254
265
|
# {Table} will determine the column's padding. (See {#initialize}.) Otherwise, this option
|
255
266
|
# overrides, for this column, the `column_padding` that was set at the table level: if passed an Integer,
|
256
267
|
# then the given amount of padding is applied to either side of the column; or if passed a two-element Array,
|
257
268
|
# then the first element of the Array indicates the amount of padding to apply to the left of the column,
|
258
269
|
# and the second element indicates the amount to apply to the right.
|
259
|
-
# @param [nil, #to_proc] styler
|
270
|
+
# @param [nil, #to_proc] styler A lambda or other callable object that will determine
|
260
271
|
# the colors or other styling applied to the formatted value of the cell. Can be passed
|
261
272
|
# <tt>nil</tt>, or can be passed a callable that takes either 2 or 3 parameters:
|
262
273
|
# * If passed <tt>nil</tt>, then no additional styling will be applied to the cell content
|
@@ -288,9 +299,14 @@ module Tabulo
|
|
288
299
|
#
|
289
300
|
# Note that if the content of a cell is truncated, then the whatever styling is applied by the
|
290
301
|
# <tt>styler</tt> to the cell content will also be applied to the truncation indicator character.
|
291
|
-
# @param [Integer] width
|
302
|
+
# @param [Integer] width Specifies the width of the column, excluding padding. If
|
292
303
|
# nil, then the column will take the width provided by the `column_width` param
|
293
304
|
# with which the Table was initialized.
|
305
|
+
# @param [Symbol] wrap_preserve Specifies how to wrap column content when the column width is reached.
|
306
|
+
# * If passed `nil`, or not provided, then the value passed to the `wrap_preserve` param of
|
307
|
+
# {#initialize} will be used.
|
308
|
+
# * If passed `rune` or word, then the option passed to {#initialize} will be overridden for
|
309
|
+
# this column. See the documentation under {#initialize} for the behaviour of each option.
|
294
310
|
# @param [#to_proc] extractor A block or other callable that will be passed each of the {Table}
|
295
311
|
# sources to determine the value in each cell of this column.
|
296
312
|
# * If this is not provided, then the column label will be treated as a method to be called on
|
@@ -305,7 +321,7 @@ module Tabulo
|
|
305
321
|
# Table. (This is case-sensitive, but is insensitive to whether a String or Symbol is passed
|
306
322
|
# to the label parameter.)
|
307
323
|
def add_column(label, align_body: nil, align_header: nil, before: nil, formatter: nil,
|
308
|
-
header: nil, header_styler: nil, padding: nil, styler: nil, width: nil, &extractor)
|
324
|
+
header: nil, header_styler: nil, padding: nil, styler: nil, width: nil, wrap_preserve: nil, &extractor)
|
309
325
|
|
310
326
|
column_label = normalize_column_label(label)
|
311
327
|
|
@@ -333,6 +349,7 @@ module Tabulo
|
|
333
349
|
right_padding: right_padding,
|
334
350
|
styler: styler || @styler,
|
335
351
|
truncation_indicator: @truncation_indicator,
|
352
|
+
wrap_preserve: wrap_preserve || @wrap_preserve,
|
336
353
|
width: width || @column_width,
|
337
354
|
)
|
338
355
|
|
@@ -412,7 +429,7 @@ module Tabulo
|
|
412
429
|
# Produce a horizontal dividing line suitable for printing at the top, bottom or middle
|
413
430
|
# of the table.
|
414
431
|
#
|
415
|
-
# @param [:top, :middle, :bottom, :title_top, :title_bottom] position
|
432
|
+
# @param [:top, :middle, :bottom, :title_top, :title_bottom] position
|
416
433
|
# Specifies the position for which the resulting horizontal dividing line is intended to
|
417
434
|
# be printed. This determines the border characters that are used to construct the line.
|
418
435
|
# The `:title_top` and `:title_bottom` options are used internally for adding borders
|
@@ -451,7 +468,7 @@ module Tabulo
|
|
451
468
|
# is called. If the source Enumerable changes between that point, and the point when
|
452
469
|
# the Table is printed, then columns will *not* be resized yet again on printing.
|
453
470
|
#
|
454
|
-
# @param [nil, Numeric] max_table_width
|
471
|
+
# @param [nil, Numeric] max_table_width With no args, or if passed <tt>:auto</tt>,
|
455
472
|
# stops the total table width (including padding and borders) from expanding beyond the
|
456
473
|
# bounds of the terminal screen.
|
457
474
|
# If passed <tt>nil</tt>, the table width will not be capped.
|
@@ -523,13 +540,13 @@ module Tabulo
|
|
523
540
|
# new Table, which contains the names of "fields" (corresponding to the original Table's
|
524
541
|
# column headings). If this is not provided, then by default this column will be made just
|
525
542
|
# wide enough to accommodate its contents.
|
526
|
-
# @option opts [String] :field_names_header
|
543
|
+
# @option opts [String] :field_names_header By default the left-most column will have a
|
527
544
|
# blank header; but this can be overridden by passing a String to this option.
|
528
|
-
# @option opts [:left, :center, :right] :field_names_header_alignment
|
545
|
+
# @option opts [:left, :center, :right] :field_names_header_alignment Specifies how the
|
529
546
|
# header text of the left-most column (if it has header text) should be aligned.
|
530
|
-
# @option opts [:left, :center, :right] :field_names_body_alignment
|
547
|
+
# @option opts [:left, :center, :right] :field_names_body_alignment Specifies how the
|
531
548
|
# body text of the left-most column should be aligned.
|
532
|
-
# @option opts [#to_proc] :headers
|
549
|
+
# @option opts [#to_proc] :headers A lambda or other callable object that
|
533
550
|
# will be passed in turn each of the elements of the current Table's <tt>sources</tt>
|
534
551
|
# Enumerable, to determine the text to be displayed in the header of each column of the
|
535
552
|
# new Table (other than the left-most column's header, which is determined as described
|
@@ -651,7 +668,8 @@ module Tabulo
|
|
651
668
|
styler: styler,
|
652
669
|
truncation_indicator: @truncation_indicator,
|
653
670
|
value: @title,
|
654
|
-
width: title_cell_width
|
671
|
+
width: title_cell_width,
|
672
|
+
wrap_preserve: @wrap_preserve,
|
655
673
|
)
|
656
674
|
cells = [title_cell]
|
657
675
|
max_cell_height = cells.map(&:height).max
|
data/lib/tabulo/util.rb
CHANGED
@@ -3,6 +3,8 @@ module Tabulo
|
|
3
3
|
# @!visibility private
|
4
4
|
module Util
|
5
5
|
|
6
|
+
NEWLINE = /\r\n|\n|\r/
|
7
|
+
|
6
8
|
# @!visibility private
|
7
9
|
def self.condense_lines(lines)
|
8
10
|
join_lines(lines.reject(&:empty?))
|
@@ -34,7 +36,7 @@ module Tabulo
|
|
34
36
|
# @return [Integer] the length of the longest segment of str when split by newlines
|
35
37
|
def self.wrapped_width(str)
|
36
38
|
return 0 if str.empty?
|
37
|
-
segments = str.split(
|
39
|
+
segments = str.split(NEWLINE)
|
38
40
|
segments.inject(1) do |longest_length_so_far, segment|
|
39
41
|
Util.max(longest_length_so_far, Unicode::DisplayWidth.of(segment))
|
40
42
|
end
|
data/lib/tabulo/version.rb
CHANGED
data/tabulo.gemspec
CHANGED
@@ -29,13 +29,13 @@ Gem::Specification.new do |spec|
|
|
29
29
|
}
|
30
30
|
|
31
31
|
spec.add_runtime_dependency "tty-screen", "0.8.1"
|
32
|
-
spec.add_runtime_dependency "unicode-display_width", "1.
|
32
|
+
spec.add_runtime_dependency "unicode-display_width", "2.1.0"
|
33
33
|
|
34
34
|
spec.add_development_dependency "bundler"
|
35
35
|
spec.add_development_dependency "rake", "~> 12.3.3"
|
36
36
|
spec.add_development_dependency "rspec", "~> 3.9"
|
37
37
|
spec.add_development_dependency "simplecov"
|
38
|
-
spec.add_development_dependency "
|
38
|
+
spec.add_development_dependency "simplecov-lcov"
|
39
39
|
spec.add_development_dependency "yard"
|
40
40
|
spec.add_development_dependency "redcarpet"
|
41
41
|
spec.add_development_dependency "github-markup"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabulo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Harvey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-screen
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 2.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 2.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: simplecov-lcov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -172,10 +172,11 @@ extensions: []
|
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
174
|
- ".ackrc"
|
175
|
+
- ".github/workflows/tests.yml"
|
175
176
|
- ".gitignore"
|
176
177
|
- ".rdoc_options"
|
177
178
|
- ".rspec"
|
178
|
-
- ".
|
179
|
+
- ".simplecov"
|
179
180
|
- ".yardopts"
|
180
181
|
- CHANGELOG.md
|
181
182
|
- Gemfile
|
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
221
|
- !ruby/object:Gem::Version
|
221
222
|
version: '0'
|
222
223
|
requirements: []
|
223
|
-
rubygems_version: 3.
|
224
|
+
rubygems_version: 3.2.29
|
224
225
|
signing_key:
|
225
226
|
specification_version: 4
|
226
227
|
summary: Terminal table generator
|