Skip to content

Commit 9540fac

Browse files
committed
feat: make task as windows compatible
1 parent 01db06b commit 9540fac

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/src/application/components/task.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ final class StepManager with TerminalTools {
4040
int _loadingStep = 0;
4141
bool isInitialStep = true;
4242
final bool _colored;
43+
int _line_count = 0;
4344

4445
StepManager(this._terminal, this._colored);
4546

4647
/// Add new step to the task.
4748
Future<T> step<T>(String message, {FutureOr<T> Function()? callback}) {
4849
if (isInitialStep) {
49-
_terminal.enableRawMode();
5050
createSpace(_terminal, 1);
5151
_position = readCursorPosition(_terminal);
5252
isInitialStep = false;
@@ -81,8 +81,12 @@ final class StepManager with TerminalTools {
8181
void success(String message) {
8282
final buffer = StringBuffer();
8383

84+
if (Platform.isWindows) {
85+
_line_count += 1;
86+
}
87+
8488
buffer.writeAnsiAll([
85-
CursorPosition.moveTo(_position!.$2, _position!.$1),
89+
CursorPosition.moveTo(_position!.$2 + _line_count, _position!.$1),
8690
SetStyles(Style.foreground(Color.green)),
8791
Print('✔ '),
8892
if (!_colored) SetStyles.reset,
@@ -91,15 +95,18 @@ final class StepManager with TerminalTools {
9195

9296
_timer?.cancel();
9397
stdout.write(buffer.toString());
94-
_terminal.disableRawMode();
9598
}
9699

97100
/// Finishes the task with an error message.
98101
void warn(String message) {
99102
final buffer = StringBuffer();
100103

104+
if (Platform.isWindows) {
105+
_line_count += 1;
106+
}
107+
101108
buffer.writeAnsiAll([
102-
CursorPosition.moveTo(_position!.$2, _position!.$1),
109+
CursorPosition.moveTo(_position!.$2 + _line_count, _position!.$1),
103110
SetStyles(Style.foreground(Color.yellow)),
104111
Print('⚠ '),
105112
if (!_colored) SetStyles.reset,
@@ -108,15 +115,18 @@ final class StepManager with TerminalTools {
108115

109116
_timer?.cancel();
110117
stdout.write(buffer.toString());
111-
_terminal.disableRawMode();
112118
}
113119

114120
/// Finishes the task with an error message.
115121
void error(String message) {
116122
final buffer = StringBuffer();
117123

124+
if (Platform.isWindows) {
125+
_line_count += 1;
126+
}
127+
118128
buffer.writeAnsiAll([
119-
CursorPosition.moveTo(_position!.$2, _position!.$1),
129+
CursorPosition.moveTo(_position!.$2 + _line_count, _position!.$1),
120130
SetStyles(Style.foreground(Color.red)),
121131
Print('✘ '),
122132
if (!_colored) SetStyles.reset,
@@ -125,7 +135,6 @@ final class StepManager with TerminalTools {
125135

126136
_timer?.cancel();
127137
stdout.write(buffer.toString());
128-
_terminal.disableRawMode();
129138
}
130139

131140
List<Sequence> _messageSequence(String message) {

0 commit comments

Comments
 (0)