Skip to content

Commit 0f32d9c

Browse files
Merge 6655b4e into master
2 parents c985326 + 6655b4e commit 0f32d9c

7 files changed

+108
-31
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 0.6.0
1+
# 0.6.1
22

33
- Added `rowDividers` argument
44

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# [Tabular](https://github.com/rtmigo/tabular_dart#tabular)
22

3-
Dart library for easily displaying tabular data in a visually appealing
3+
Dart library for displaying tabular data in a visually appealing
44
ASCII table format.
55

66
Tabular is specifically designed to create tables in the Markdown format that
@@ -125,7 +125,7 @@ tabular(data, border: Border.vertical);
125125
| Winter | 12 | December | 31 | 258 |
126126
```
127127

128-
Adding horizontal borders is also possible, but it can make the table not
128+
In the same way, you can add `Border.horizontal`, but it can make the table not
129129
conform to the Markdown standard.
130130

131131
## Add horizontal dividers

analysis_options.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ analyzer:
1313
errors:
1414
# There are a number of deprecated members used through this package
1515
deprecated_member_use_from_same_package: ignore
16-
exclude:
17-
- test/**
16+
#exclude:
17+
# - test/**
1818

lib/src/inner.dart

+16-14
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,22 @@ List<Side> createColToAlign<T>(CellsMatrix matrix, Map<dynamic, Side>? align) {
394394
///
395395
/// [rowDividers] contains the indices of the [rows], which must be preceded by a horizontal
396396
/// divider. By default, there is only index 1, which corresponds to the divider between
397-
/// the header and the body of the table.
397+
/// the header and the body of the table. `rowDividers: null` will cause dividers to be added
398+
/// between all rows.
398399
String tabular(
399400
List<List<dynamic>> rows,
400-
{Map<dynamic, Side>? align,
401-
Map<dynamic, FormatCell>? format,
402-
List<Sort>? sort,
403-
markdownAlign = false,
404-
Border border = Border.none,
405-
Style style = Style.markdown,
406-
List<int> rowDividers = const [1],
407-
@Deprecated('Use border=Border.vertical argument') // since 2021-04-28
408-
outerBorder = false}) {
409-
//return Tabular(rows, align: align, format: format, sort: sort, markdownAlign: markdownAlign, outerBorder: outerBorder).toString();
410-
411-
if (outerBorder) {
401+
{ Map<dynamic, Side>? align,
402+
Map<dynamic, FormatCell>? format,
403+
List<Sort>? sort,
404+
markdownAlign = false,
405+
Border border = Border.none,
406+
Style style = Style.markdown,
407+
List<int>? rowDividers = const [1],
408+
409+
@Deprecated('Use border=Border.vertical argument') // since 2021-04-28
410+
outerBorder = false
411+
}) {
412+
if (outerBorder && border==Border.none) {
412413
border = Border.vertical;
413414
}
414415

@@ -477,7 +478,8 @@ String tabular(
477478
for (var row in matrix.rows) {
478479
iRow++;
479480

480-
if (rowDividers.contains(iRow)) {
481+
482+
if (iRow>0 && (rowDividers==null || rowDividers.contains(iRow))) {
481483
formattedRows.add(bar);
482484
}
483485

pubspec.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: tabular
2-
description: Dart library for easily displaying tabular data in a visually appealing ASCII table format.
3-
version: 0.6.0
2+
description: Dart library for displaying tabular data in a visually appealing ASCII table format.
3+
version: 0.6.1
44
repository: https://github.com/rtmigo/tabular_dart
55

6-
76
environment:
87
sdk: ">=2.12.0 <3.0.0"
98

test/split_test.dart

+85-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import 'package:test/test.dart';
77
import 'common.dart';
88

99
void main() {
10-
1110
test('default split', () {
1211
var t = tabular(sundata);
1312

14-
expect(t.spaceToDot(), testTrim('''
13+
expect(
14+
t.spaceToDot(),
15+
testTrim('''
1516
Season.|..#.|.Name......|.Days.|...Sun
1617
-------|----|-----------|------|------
1718
Winter.|..1.|.January...|...31.|....94
@@ -26,15 +27,19 @@ void main() {
2627
Autumn.|.10.|.October...|...31.|..5041
2728
Autumn.|.11.|.November..|...30.|..2302
2829
Winter.|.12.|.December..|...31.|...258
29-
'''.trim().noSpaces()));
30+
'''
31+
.trim()
32+
.noSpaces()));
3033
});
3134

3235
test('no split', () {
3336
var t = tabular(sundata, rowDividers: []);
3437

3538
//print(t.spaceToDot());
3639

37-
expect(t.spaceToDot(), testTrim('''
40+
expect(
41+
t.spaceToDot(),
42+
testTrim('''
3843
Season.|..#.|.Name......|.Days.|...Sun
3944
Winter.|..1.|.January...|...31.|....94
4045
Winter.|..2.|.February..|...28.|...123
@@ -48,15 +53,19 @@ void main() {
4853
Autumn.|.10.|.October...|...31.|..5041
4954
Autumn.|.11.|.November..|...30.|..2302
5055
Winter.|.12.|.December..|...31.|...258
51-
'''.trim().noSpaces()));
56+
'''
57+
.trim()
58+
.noSpaces()));
5259
});
5360

5461
test('multiple split', () {
5562
var t = tabular(sundata, rowDividers: [1, 3, 6, 9, 12]);
5663

5764
//print(t.spaceToDot());
5865

59-
expect(t.spaceToDot(), testTrim('''
66+
expect(
67+
t.spaceToDot(),
68+
testTrim('''
6069
Season.|..#.|.Name......|.Days.|...Sun
6170
-------|----|-----------|------|------
6271
Winter.|..1.|.January...|...31.|....94
@@ -75,8 +84,77 @@ void main() {
7584
Autumn.|.11.|.November..|...30.|..2302
7685
-------|----|-----------|------|------
7786
Winter.|.12.|.December..|...31.|...258
78-
'''.trim().noSpaces()));
87+
'''
88+
.trim()
89+
.noSpaces()));
7990
});
8091

92+
test('null', () {
93+
var t = tabular(sundata, rowDividers: null);
94+
95+
print(t.spaceToDot());
96+
97+
expect(
98+
t.spaceToDot(),
99+
testTrim('''
100+
Season.|..#.|.Name......|.Days.|...Sun
101+
-------|----|-----------|------|------
102+
Winter.|..1.|.January...|...31.|....94
103+
-------|----|-----------|------|------
104+
Winter.|..2.|.February..|...28.|...123
105+
-------|----|-----------|------|------
106+
Spring.|..3.|.March.....|...31.|....42
107+
-------|----|-----------|------|------
108+
Spring.|..4.|.April.....|...30.|...243
109+
-------|----|-----------|------|------
110+
Spring.|..5.|.May.......|...31.|..5523
111+
-------|----|-----------|------|------
112+
Summer.|..6.|.June......|...30.|.11251
113+
-------|----|-----------|------|------
114+
Summer.|..7.|.July......|...31.|.17451
115+
-------|----|-----------|------|------
116+
Summer.|..8.|.August....|...31.|.18707
117+
-------|----|-----------|------|------
118+
Autumn.|..9.|.September.|...30.|..7025
119+
-------|----|-----------|------|------
120+
Autumn.|.10.|.October...|...31.|..5041
121+
-------|----|-----------|------|------
122+
Autumn.|.11.|.November..|...30.|..2302
123+
-------|----|-----------|------|------
124+
Winter.|.12.|.December..|...31.|...258
125+
'''
126+
.trim()
127+
.noSpaces()));
128+
});
81129

130+
test('dividers with sorting', () {
131+
var t = tabular(sundata, rowDividers: [1, 3, 6, 9, 12], sort: [Sort('Sun')]);
132+
133+
// rows order changed, divider positions unchanged
134+
135+
expect(
136+
t.spaceToDot(),
137+
testTrim('''
138+
Season.|..#.|.Name......|.Days.|...Sun
139+
-------|----|-----------|------|------
140+
Spring.|..3.|.March.....|...31.|....42
141+
Winter.|..1.|.January...|...31.|....94
142+
-------|----|-----------|------|------
143+
Winter.|..2.|.February..|...28.|...123
144+
Spring.|..4.|.April.....|...30.|...243
145+
Winter.|.12.|.December..|...31.|...258
146+
-------|----|-----------|------|------
147+
Autumn.|.11.|.November..|...30.|..2302
148+
Autumn.|.10.|.October...|...31.|..5041
149+
Spring.|..5.|.May.......|...31.|..5523
150+
-------|----|-----------|------|------
151+
Autumn.|..9.|.September.|...30.|..7025
152+
Summer.|..6.|.June......|...30.|.11251
153+
Summer.|..7.|.July......|...31.|.17451
154+
-------|----|-----------|------|------
155+
Summer.|..8.|.August....|...31.|.18707
156+
'''
157+
.trim()
158+
.noSpaces()));
159+
});
82160
}

test/test_common_test.dart

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import 'common.dart';
77

88
void main() {
99
test('tst', () {
10-
List<String> lst;
11-
1210
expect(removeCommonBlanksAtLeft(['ABCD', 'DEF']), ['ABCD', 'DEF']);
1311

1412
// two blanks each

0 commit comments

Comments
 (0)