Skip to content

Commit 722e85a

Browse files
committed
feat: prepare 1.3.0 version
1 parent fcfe114 commit 722e85a

File tree

5 files changed

+108
-56
lines changed

5 files changed

+108
-56
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.3.0
2+
3+
- Add select max result into configurable option
4+
- Add delayed component into readme
5+
- Add progress component into readme
6+
17
## 1.2.0
28

39
- Implement switch component

README.md

Lines changed: 92 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ user input.
1010
To use Commander in your Dart project, add this to your `pubspec.yaml` file :
1111
```yaml
1212
dependencies:
13-
commander_ui: ^1.1.0
13+
commander_ui: ^1.3.0
1414
```
1515
1616
Then run `pub get` to install the dependencies.
@@ -26,16 +26,21 @@ A simple example of using Commander to create an input component :
2626
- ❌ Default value
2727

2828
```dart
29-
StdinBuffer.initialize();
30-
31-
final input = Input(
32-
answer: 'Please give us your name',
33-
placeholder: 'firstname lastname',
34-
validate: (value) => switch(value) {
35-
String value when value.trim().isNotEmpty => Ok(null),
36-
_ => Err('Please provide a valid name')
37-
}
38-
);
29+
Future<void> main() async {
30+
final input = Input(
31+
answer: 'Please give us your name',
32+
placeholder: 'firstname lastname',
33+
validate: (value) =>
34+
switch(value) {
35+
String value when value
36+
.trim()
37+
.isNotEmpty => Ok(null),
38+
_ => Err('Please provide a valid name')
39+
}
40+
);
41+
42+
print(await input.handle());
43+
}
3944
```
4045

4146
### Select component
@@ -46,47 +51,88 @@ A simple example of using Commander to create an option selection component :
4651
- ✅ Selected line custom style
4752
- ✅ Unselected line custom style
4853
- ✅ Display transformer
49-
- ❌ Count limitation (actually defined as 5)
54+
- ✅ Max display count (default as 5)
5055

5156
```dart
52-
StdinBuffer.initialize();
53-
54-
final select = Select(
55-
answer: "Please select your best hello",
56-
options: List.generate(20, (index) => Item('${index + 1}. Hello World', index + 1)),
57-
placeholder: 'Type to filter',
58-
selectedLineStyle: (line) => '${AsciiColors.green('❯')} ${AsciiColors.lightCyan(line)}',
59-
unselectedLineStyle: (line) => ' $line',
60-
onDisplay: (item) => item.name
61-
);
62-
63-
final selected = switch(await select.handle()) {
64-
Ok(:final value) => 'My value is ${value.value}',
65-
Err(:final error) => Exception('Error: $error'),
66-
_ => 'Unknown',
67-
};
68-
69-
print(selected);
57+
Future<void> main() async {
58+
final select = Select(
59+
answer: "Please select your best hello",
60+
options: List.generate(20, (index) => Item('${index + 1}. Hello World', index + 1)),
61+
placeholder: 'Type to filter',
62+
selectedLineStyle: (line) => '${AsciiColors.green('❯')} ${AsciiColors.lightCyan(line)}',
63+
unselectedLineStyle: (line) => ' $line',
64+
onDisplay: (item) => item.name,
65+
displayCount: 4
66+
);
67+
68+
final selected = switch(await select.handle()) {
69+
Ok(:final value) => 'My value is ${value.value}',
70+
Err(:final error) => Exception('Error: $error'),
71+
_ => 'Unknown',
72+
};
73+
74+
print(selected);
75+
}
7076
```
7177

7278
### Switching component
7379
A simple example of using Commander to create a switch component :
7480

7581
```dart
76-
StdinBuffer.initialize();
77-
78-
final switch = Switch(
79-
answer: 'Do you love cat ?',
80-
defaultValue: false,
81-
);
82-
83-
final result = switch(await switch.handle()) {
84-
Ok(:final value) => value.value
85-
? 'I love cat 😍'
86-
: 'I hate cat 😕',
87-
Err(:final error) => Exception('Error: $error'),
88-
_ => 'Unknown',
89-
};
90-
91-
print(result);
82+
Future<void> main() async {
83+
final component = Switch(
84+
answer: 'Do you love cat ?',
85+
defaultValue: false,
86+
);
87+
88+
final value = await component.handle();
89+
90+
final result = switch(value) {
91+
Ok(:final value) => value.value
92+
? 'I love cat 😍'
93+
: 'I hate cat 😕',
94+
Err(:final error) => Exception('Error: $error'),
95+
_ => 'Unknown',
96+
};
97+
}
98+
```
99+
### Delayed component
100+
A simple example of using Commander to create a delayed component :
101+
102+
```dart
103+
Future<void> main() async {
104+
final delayed = Delayed();
105+
106+
delayed.step('Fetching data from remote api...');
107+
await wait();
108+
delayed.step('Find remote location...');
109+
await wait();
110+
delayed.step('Extract data...');
111+
await wait();
112+
delayed.success('Data are available !');
113+
}
114+
115+
Future<void> wait() =>
116+
Future.delayed(Duration(seconds: Random().nextInt(3) + 1));
117+
```
118+
119+
### Progress component
120+
A simple example of using Commander to create a progress component :
121+
122+
```dart
123+
void main() async {
124+
final progress = ProgressBar(max: 50);
125+
126+
for (int i = 0; i < 50; i++) {
127+
progress.next(message: [Print('Downloading file ${i + 1}/50...')]);
128+
await Future.delayed(Duration(milliseconds: 50));
129+
}
130+
131+
progress.done(message: [
132+
SetStyles(Style.foreground(Color.green)),
133+
Print('✔'),
134+
SetStyles.reset,
135+
Print(' Download complete!')
136+
]);
137+
}
92138
```

example/select.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Future<void> main() async {
44
final select = Select(
55
answer: 'What is your name?',
66
options: ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank', 'John'],
7-
displayElementCount: 2);
7+
displayCount: 2);
88

99
final value = await select.handle();
1010
print(value);

lib/src/components/select.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import 'package:mansion/mansion.dart';
99
final class Select<T> with Tools implements Component<T> {
1010
String filter = '';
1111
int currentIndex = 0;
12-
int displayElementCount;
12+
int displayCount;
1313
bool isRendering = false;
1414

1515
final List<T> options;
@@ -37,7 +37,7 @@ final class Select<T> with Tools implements Component<T> {
3737
Select({
3838
required this.answer,
3939
required this.options,
40-
this.displayElementCount = 5,
40+
this.displayCount = 5,
4141
this.onDisplay,
4242
this.placeholder,
4343
List<Sequence>? noResultFoundMessage,
@@ -209,16 +209,16 @@ final class Select<T> with Tools implements Component<T> {
209209
} else {
210210
copy.add(AsciiControl.lineFeed);
211211

212-
int start = currentIndex - displayElementCount + 1 >= 0
213-
? currentIndex - displayElementCount + 1
212+
int start = currentIndex - displayCount + 1 >= 0
213+
? currentIndex - displayCount + 1
214214
: 0;
215215
if (currentIndex >= filteredArr.length &&
216-
filteredArr.length > displayElementCount) {
217-
start = filteredArr.length - displayElementCount;
216+
filteredArr.length > displayCount) {
217+
start = filteredArr.length - displayCount;
218218
} else {}
219219

220-
int end = start + displayElementCount <= filteredArr.length
221-
? start + displayElementCount
220+
int end = start + displayCount <= filteredArr.length
221+
? start + displayCount
222222
: filteredArr.length;
223223

224224
for (int i = start; i < end; i++) {

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.2.0
3+
version: 1.3.0
44
repository: https://github.com/LeadcodeDev/commander
55

66
topics:

0 commit comments

Comments
 (0)