Skip to content

Commit 44688b8

Browse files
committed
feat: deploy table component
1 parent 246536f commit 44688b8

File tree

4 files changed

+53
-5
lines changed

4 files changed

+53
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.6.0
2+
3+
- Add `Table` component
4+
15
## 1.5.1
26

37
- Fix bad selected value when searching in `select` component

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,30 @@ Future<void> main() async {
151151
print(value);
152152
}
153153
```
154+
155+
### Table component
156+
A simple example of using Commander to create a table component :
157+
158+
- ✅ Without column and line borders
159+
- ✅ With column and line borders
160+
- ✅ With column borders and without line borders
161+
- ✅ With line borders and without column borders
162+
163+
```dart
164+
Future<void> main() async {
165+
Table(
166+
columns: ['Name', 'Age', 'Country', 'City'],
167+
lineSeparator: false,
168+
columnSeparator: false,
169+
data: [
170+
['Alice', '20', 'USA', 'New York'],
171+
['Bob', '25', 'Canada', 'Toronto'],
172+
['Charlie', '30', 'France', 'Paris'],
173+
['David', '35', 'Germany', 'Berlin'],
174+
['Eve', '40', 'Italy', 'Rome'],
175+
['Frank', '45', 'Japan', 'Tokyo'],
176+
['John', '50', 'China', 'Beijing'],
177+
],
178+
);
179+
}
180+
```

lib/src/components/table.dart

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,27 @@ final class Table with Tools implements Component {
2828
final buffer = StringBuffer();
2929

3030
_drawLineSeparator(buffer,
31-
left: '┌', middle: columnSeparator ? '┬' : '─', right: '┐', separator: '─');
31+
left: '┌',
32+
middle: columnSeparator ? '┬' : '─',
33+
right: '┐',
34+
separator: '─');
3235
_drawHeader(buffer);
3336
_drawLineSeparator(buffer,
34-
left: '├', middle: columnSeparator ? '┼' : '─', right: '┤', separator: '─');
37+
left: '├',
38+
middle: columnSeparator ? '┼' : '─',
39+
right: '┤',
40+
separator: '─');
3541

3642
for (var row in data) {
3743
final currentIndex = data.indexOf(row);
3844
_drawLine(buffer, currentIndex, row);
3945
}
4046

4147
_drawLineSeparator(buffer,
42-
left: '└', middle: columnSeparator ? '┴' : '─', right: '┘', separator: '─');
48+
left: '└',
49+
middle: columnSeparator ? '┴' : '─',
50+
right: '┘',
51+
separator: '─');
4352

4453
clearFromCursorToEnd();
4554
restoreCursorPosition();
@@ -114,7 +123,15 @@ final class Table with Tools implements Component {
114123
final maxColWidths = getMaxCellWidths();
115124

116125
if (![0, data.length].contains(currentIndex) && lineSeparator) {
117-
_drawLineSeparator(buffer, left: '├', middle: lineSeparator ? columnSeparator ? '┼' : '─' : '┼', right: '┤', separator: '─');
126+
_drawLineSeparator(buffer,
127+
left: '├',
128+
middle: lineSeparator
129+
? columnSeparator
130+
? '┼'
131+
: '─'
132+
: '┼',
133+
right: '┤',
134+
separator: '─');
118135
}
119136

120137
String rowLine = '│';

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: commander_ui
22
description: Commander is a Dart library for creating user interfaces within the terminal.
3-
version: 1.5.1
3+
version: 1.6.0
44
repository: https://github.com/LeadcodeDev/commander
55

66
topics:

0 commit comments

Comments
 (0)