Skip to content

Commit 2375cbf

Browse files
committed
chore: deploy 2.3.0
1 parent 0af500f commit 2375cbf

19 files changed

+225
-103
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# 2.3.0
2+
- Implement theming components
3+
- Add `AskTheme` property in `ask` component
4+
- Add `SelectTheme` property in `select` component
5+
- Add `CheckboxTheme` property in `checkbox` component
6+
- Add `TaskTheme` property in `task` component
7+
- Add `SwapTheme` property in `swap` component
8+
- Remove useless `message` property in task component
9+
110
# 2.2.4
211
- Make `task` component as windows compatible
312
- Change default placeholder for `swap` component in example

example/task.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import 'package:commander_ui/src/level.dart';
33

44
Future<void> sleep() => Future.delayed(Duration(seconds: 1));
55

6-
Future<String> sleepWithValue() => Future.delayed(Duration(seconds: 1), () => 'Hello World !');
6+
Future<String> sleepWithValue() =>
7+
Future.delayed(Duration(seconds: 1), () => 'Hello World !');
78

89
Future<void> main() async {
910
final commander = Commander(level: Level.verbose);

lib/src/application/components/ask.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ final class Ask<T> with TerminalTools implements Component<Future<T>> {
5858

5959
void _waitResponse() {
6060
final input = _hidden ? readLineHiddenSync() : readLineSync();
61-
final response = input == null || input.isEmpty ? _resolvedDefaultValue : input;
61+
final response =
62+
input == null || input.isEmpty ? _resolvedDefaultValue : input;
6263

6364
if (_validate != null) {
6465
final result = _validate!(response);

lib/src/application/components/checkbox.dart

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import 'package:commander_ui/src/io.dart';
1010
import 'package:mansion/mansion.dart';
1111

1212
/// A component that asks the user to select one or more options.
13-
final class Checkbox<T> with TerminalTools implements Component<Future<List<T>>> {
13+
final class Checkbox<T>
14+
with TerminalTools
15+
implements Component<Future<List<T>>> {
1416
final _completer = Completer<List<T>>();
1517

1618
final Terminal _terminal;
@@ -69,14 +71,16 @@ final class Checkbox<T> with TerminalTools implements Component<Future<List<T>>>
6971
_currentIndex = _currentIndex - 1;
7072
_render();
7173
}
72-
} else if (key.controlChar == ControlCharacter.arrowDown || key.char == 'j') {
74+
} else if (key.controlChar == ControlCharacter.arrowDown ||
75+
key.char == 'j') {
7376
if (_currentIndex < _options.length - 1) {
7477
_currentIndex = _currentIndex + 1;
7578
_render();
7679
}
7780
} else if (key.char == ' ') {
7881
_onSelect();
79-
} else if ([ControlCharacter.ctrlJ, ControlCharacter.ctrlM].contains(key.controlChar)) {
82+
} else if ([ControlCharacter.ctrlJ, ControlCharacter.ctrlM]
83+
.contains(key.controlChar)) {
8084
_onSubmit();
8185
}
8286
}
@@ -110,8 +114,13 @@ final class Checkbox<T> with TerminalTools implements Component<Future<List<T>>>
110114

111115
buffer.writeAnsiAll([
112116
if (_currentIndex == index) ..._theme.currentLineColor,
113-
if (isSelected) ..._theme.selectedLineColor else ..._theme.defaultLineColor,
114-
Print(isSelected || _currentIndex == index ? _theme.selectedIcon : _theme.unselectedIcon),
117+
if (isSelected)
118+
..._theme.selectedLineColor
119+
else
120+
..._theme.defaultLineColor,
121+
Print(isSelected || _currentIndex == index
122+
? _theme.selectedIcon
123+
: _theme.unselectedIcon),
115124
if (_currentIndex == index) SetStyles.reset,
116125
]);
117126

@@ -157,7 +166,8 @@ final class Checkbox<T> with TerminalTools implements Component<Future<List<T>>>
157166
}
158167

159168
void _onSubmit() {
160-
final selectedOptions = _selectedOptions.map((index) => _options[index]).toList();
169+
final selectedOptions =
170+
_selectedOptions.map((index) => _options[index]).toList();
161171

162172
restoreCursorPosition();
163173
clearFromCursorToEnd();

lib/src/application/components/select.dart

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ final class Select<T> with TerminalTools implements Component<Future<T>> {
1414
final _completer = Completer<T>();
1515

1616
final Terminal _terminal;
17-
SelectTheme _theme;
18-
late int _displayCount;
17+
final SelectTheme _theme;
18+
late final int _displayCount;
1919

2020
int _currentIndex = 0;
2121
T? _selectedOption;
@@ -69,18 +69,22 @@ final class Select<T> with TerminalTools implements Component<Future<T>> {
6969
_currentIndex = _currentIndex - 1;
7070
_render();
7171
}
72-
} else if (key.controlChar == ControlCharacter.arrowDown || key.char == 'j') {
72+
} else if (key.controlChar == ControlCharacter.arrowDown ||
73+
key.char == 'j') {
7374
if (_currentIndex < _filteredOptions.length - 1) {
7475
_currentIndex = _currentIndex + 1;
7576
_render();
7677
}
77-
} else if ([ControlCharacter.ctrlJ, ControlCharacter.ctrlM].contains(key.controlChar)) {
78+
} else if ([ControlCharacter.ctrlJ, ControlCharacter.ctrlM]
79+
.contains(key.controlChar)) {
7880
_onSubmit();
7981
} else {
80-
if (RegExp(r'^[\p{L}\p{N}\p{P}\s\x7F]*$', unicode: true).hasMatch(key.char)) {
82+
if (RegExp(r'^[\p{L}\p{N}\p{P}\s\x7F]*$', unicode: true)
83+
.hasMatch(key.char)) {
8184
_currentIndex = 0;
8285

83-
if (key.controlChar == ControlCharacter.backspace && _filter.isNotEmpty) {
86+
if (key.controlChar == ControlCharacter.backspace &&
87+
_filter.isNotEmpty) {
8488
_filter = _filter.substring(0, _filter.length - 1);
8589
} else if (key.controlChar != ControlCharacter.backspace) {
8690
_filter = _filter + key.char;
@@ -97,7 +101,9 @@ final class Select<T> with TerminalTools implements Component<Future<T>> {
97101
List<T> _filterOptions() {
98102
return _options.where((item) {
99103
final value = _onDisplay?.call(item) ?? item.toString();
100-
return _options.isNotEmpty ? value.toLowerCase().contains(_filter.toLowerCase()) : true;
104+
return _options.isNotEmpty
105+
? value.toLowerCase().contains(_filter.toLowerCase())
106+
: true;
101107
}).toList();
102108
}
103109

@@ -112,7 +118,9 @@ final class Select<T> with TerminalTools implements Component<Future<T>> {
112118
Print(_theme.askPrefix),
113119
SetStyles.reset,
114120
Print(' $_message '),
115-
..._filter.isEmpty ? _theme.placeholderColorMessage : _theme.filterColorMessage,
121+
..._filter.isEmpty
122+
? _theme.placeholderColorMessage
123+
: _theme.filterColorMessage,
116124
_filter.isEmpty ? Print(_placeholder) : Print(_filter),
117125
SetStyles.reset,
118126
AsciiControl.lineFeed,
@@ -121,7 +129,9 @@ final class Select<T> with TerminalTools implements Component<Future<T>> {
121129
_filteredOptions.clear();
122130
_filteredOptions.addAll(_filterOptions());
123131

124-
int start = _currentIndex - _displayCount >= 0 ? _currentIndex - _displayCount + 1 : 0;
132+
int start = _currentIndex - _displayCount >= 0
133+
? _currentIndex - _displayCount + 1
134+
: 0;
125135

126136
for (final choice in _filteredOptions.skip(start).take(_displayCount)) {
127137
final isCurrent = _filteredOptions.indexOf(choice) == _currentIndex;
@@ -172,7 +182,8 @@ final class Select<T> with TerminalTools implements Component<Future<T>> {
172182
SetStyles.reset,
173183
Print(' $_message '),
174184
..._theme.resultMessageColor,
175-
Print(_onDisplay?.call(_selectedOption as T) ?? _selectedOption.toString()),
185+
Print(
186+
_onDisplay?.call(_selectedOption as T) ?? _selectedOption.toString()),
176187
SetStyles.reset,
177188
AsciiControl.lineFeed,
178189
]);

lib/src/application/components/swap.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:commander_ui/src/application/terminals/terminal.dart';
55
import 'package:commander_ui/src/application/themes/default_swap_theme.dart';
66
import 'package:commander_ui/src/application/utils/terminal_tools.dart';
77
import 'package:commander_ui/src/domains/models/component.dart';
8-
import 'package:commander_ui/src/domains/themes/checkbox_theme.dart';
98
import 'package:commander_ui/src/domains/themes/swap_theme.dart';
109
import 'package:commander_ui/src/io.dart';
1110
import 'package:mansion/mansion.dart';
@@ -60,7 +59,8 @@ final class Swap<T> with TerminalTools implements Component<Future<bool>> {
6059
} else if (key.controlChar == ControlCharacter.arrowRight) {
6160
_value = false;
6261
_render();
63-
} else if ([ControlCharacter.ctrlJ, ControlCharacter.ctrlM].contains(key.controlChar)) {
62+
} else if ([ControlCharacter.ctrlJ, ControlCharacter.ctrlM]
63+
.contains(key.controlChar)) {
6464
_onSubmit();
6565
}
6666
}
@@ -91,7 +91,7 @@ final class Swap<T> with TerminalTools implements Component<Future<bool>> {
9191

9292
for (final value in values) {
9393
buffer.writeAnsiAll([
94-
...value == _value ? _theme.selected : _theme.unselected,
94+
...value == _value ? _theme.unselected : _theme.selected,
9595
Print(value ? 'Yes' : ' No'),
9696
SetStyles.reset,
9797
]);

lib/src/application/components/task.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ final class Task with TerminalTools implements Component<Future<StepManager>> {
1313
final Terminal _terminal;
1414
final TaskTheme _theme;
1515

16-
Task(this._terminal, {TaskTheme? theme}) : _theme = theme ?? DefaultTaskTheme();
16+
Task(this._terminal, {TaskTheme? theme})
17+
: _theme = theme ?? DefaultTaskTheme();
1718

1819
@override
1920
Future<StepManager> handle() async {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// Control Modes
22
/// https://ftp.gnu.org/old-gnu/Manuals/glibc-2.2.3/html_node/libc_354.html#SEC363
33
final class ControlMode {
4-
static const int CSIZE = 0x00000300;
5-
static const int CS8 = 0x00000300;
4+
static const int cSize = 0x00000300;
5+
static const int cS8 = 0x00000300;
66
}

lib/src/application/terminals/unix_terminal.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class UnixTerminal implements Terminal {
4040
InputMode.IXON)
4141
..ref.c_oflag = origTermIOS.c_oflag & ~OutputMode.OPOST
4242
..ref.c_cflag =
43-
(origTermIOS.c_cflag & ~ControlMode.CSIZE) | ControlMode.CS8
43+
(origTermIOS.c_cflag & ~ControlMode.cSize) | ControlMode.cS8
4444
..ref.c_lflag = origTermIOS.c_lflag &
4545
~(LocalMode.ECHO |
4646
LocalMode.ICANON |

lib/src/application/themes/default_ask_theme.dart

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,38 @@ final class DefaultAskTheme implements AskTheme {
1616
(String? value) => value?.replaceAll(RegExp(r'.'), '*') ?? '';
1717

1818
@override
19-
String Function(String? value) defaultValueFormatter = (String? value) => switch (value) {
20-
String value => ' ($value)',
21-
_ => '',
22-
};
19+
String Function(String? value) defaultValueFormatter =
20+
(String? value) => switch (value) {
21+
String value => ' ($value)',
22+
_ => '',
23+
};
2324

2425
@override
2526
String? Function(String? value) inputFormatter = (String? value) => value;
2627

2728
@override
28-
List<Sequence> successPrefixColor = [SetStyles.reset, SetStyles(Style.foreground(Color.green))];
29+
List<Sequence> successPrefixColor = [
30+
SetStyles.reset,
31+
SetStyles(Style.foreground(Color.green))
32+
];
2933

3034
@override
31-
List<Sequence> errorPrefixColor = [SetStyles(Style.foreground(Color.brightRed))];
35+
List<Sequence> errorPrefixColor = [
36+
SetStyles(Style.foreground(Color.brightRed))
37+
];
3238

3339
@override
3440
List<Sequence> askPrefixColor = [SetStyles(Style.foreground(Color.yellow))];
3541

3642
@override
37-
List<Sequence> validatorColorMessage = [SetStyles(Style.foreground(Color.brightRed))];
43+
List<Sequence> validatorColorMessage = [
44+
SetStyles(Style.foreground(Color.brightRed))
45+
];
3846

3947
@override
40-
List<Sequence> defaultValueColorMessage = [SetStyles(Style.foreground(Color.brightBlack))];
48+
List<Sequence> defaultValueColorMessage = [
49+
SetStyles(Style.foreground(Color.brightBlack))
50+
];
4151

4252
@override
4353
List<Sequence> inputColor = [SetStyles(Style.foreground(Color.brightBlack))];
@@ -64,13 +74,16 @@ final class DefaultAskTheme implements AskTheme {
6474
theme.errorSuffix = errorSuffix ?? theme.errorSuffix;
6575
theme.successSuffix = successSuffix ?? theme.successSuffix;
6676
theme.secureFormatter = secureFormatter ?? theme.secureFormatter;
67-
theme.defaultValueFormatter = defaultValueFormatter ?? theme.defaultValueFormatter;
77+
theme.defaultValueFormatter =
78+
defaultValueFormatter ?? theme.defaultValueFormatter;
6879
theme.inputFormatter = inputFormatter ?? theme.inputFormatter;
6980
theme.successPrefixColor = successPrefixColor ?? theme.successPrefixColor;
7081
theme.errorPrefixColor = errorPrefixColor ?? theme.errorPrefixColor;
71-
theme.validatorColorMessage = validatorColorMessage ?? theme.validatorColorMessage;
82+
theme.validatorColorMessage =
83+
validatorColorMessage ?? theme.validatorColorMessage;
7284
theme.askPrefixColor = askPrefixColor ?? theme.askPrefixColor;
73-
theme.defaultValueColorMessage = defaultValueColorMessage ?? theme.defaultValueColorMessage;
85+
theme.defaultValueColorMessage =
86+
defaultValueColorMessage ?? theme.defaultValueColorMessage;
7487
theme.inputColor = inputColor ?? theme.inputColor;
7588

7689
return theme;

lib/src/application/themes/default_checkbox_theme.dart

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ final class DefaultCheckBoxTheme implements CheckboxTheme {
1515
String unselectedIcon = '◯';
1616

1717
@override
18-
String helpMessage = '(Press ↑/↓ to navigate, space to select, enter to confirm)';
18+
String helpMessage =
19+
'(Press ↑/↓ to navigate, space to select, enter to confirm)';
1920

2021
@override
21-
String Function(String? value) placeholderFormatter = (String? value) => switch (value) {
22-
String value => ' ($value)',
23-
_ => '',
24-
};
22+
String Function(String? value) placeholderFormatter =
23+
(String? value) => switch (value) {
24+
String value => ' ($value)',
25+
_ => '',
26+
};
2527

2628
@override
2729
List<Sequence> currentLineColor = [SetStyles(Style.foreground(Color.white))];
@@ -30,22 +32,32 @@ final class DefaultCheckBoxTheme implements CheckboxTheme {
3032
List<Sequence> selectedLineColor = [SetStyles(Style.foreground(Color.white))];
3133

3234
@override
33-
List<Sequence> defaultLineColor = [SetStyles(Style.foreground(Color.brightBlack))];
35+
List<Sequence> defaultLineColor = [
36+
SetStyles(Style.foreground(Color.brightBlack))
37+
];
3438

3539
@override
36-
List<Sequence> helpMessageColor = [SetStyles(Style.foreground(Color.brightBlack))];
40+
List<Sequence> helpMessageColor = [
41+
SetStyles(Style.foreground(Color.brightBlack))
42+
];
3743

3844
@override
39-
List<Sequence> successPrefixColor = [SetStyles(Style.foreground(Color.green))];
45+
List<Sequence> successPrefixColor = [
46+
SetStyles(Style.foreground(Color.green))
47+
];
4048

4149
@override
4250
List<Sequence> askPrefixColor = [SetStyles(Style.foreground(Color.yellow))];
4351

4452
@override
45-
List<Sequence> resultMessageColor = [SetStyles(Style.foreground(Color.brightBlack))];
53+
List<Sequence> resultMessageColor = [
54+
SetStyles(Style.foreground(Color.brightBlack))
55+
];
4656

4757
@override
48-
List<Sequence> placeholderColorMessage = [SetStyles(Style.foreground(Color.brightBlack))];
58+
List<Sequence> placeholderColorMessage = [
59+
SetStyles(Style.foreground(Color.brightBlack))
60+
];
4961

5062
DefaultCheckBoxTheme();
5163

@@ -72,15 +84,17 @@ final class DefaultCheckBoxTheme implements CheckboxTheme {
7284
theme.selectedIcon = selectedIcon ?? theme.selectedIcon;
7385
theme.unselectedIcon = unselectedIcon ?? theme.unselectedIcon;
7486
theme.helpMessage = helpMessage ?? theme.helpMessage;
75-
theme.placeholderFormatter = placeholderFormatter ?? theme.placeholderFormatter;
87+
theme.placeholderFormatter =
88+
placeholderFormatter ?? theme.placeholderFormatter;
7689
theme.currentLineColor = currentLineColor ?? theme.currentLineColor;
7790
theme.selectedLineColor = selectedLineColor ?? theme.selectedLineColor;
7891
theme.defaultLineColor = defaultLineColor ?? theme.defaultLineColor;
7992
theme.helpMessageColor = helpMessageColor ?? theme.helpMessageColor;
8093
theme.successPrefixColor = successPrefixColor ?? theme.successPrefixColor;
8194
theme.askPrefixColor = askPrefixColor ?? theme.askPrefixColor;
8295
theme.resultMessageColor = resultMessageColor ?? theme.resultMessageColor;
83-
theme.placeholderColorMessage = placeholderColorMessage ?? theme.placeholderColorMessage;
96+
theme.placeholderColorMessage =
97+
placeholderColorMessage ?? theme.placeholderColorMessage;
8498

8599
return theme;
86100
}

0 commit comments

Comments
 (0)