Skip to content

Commit 01db06b

Browse files
committed
feat: enhance line position
1 parent 77df551 commit 01db06b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/src/application/components/checkbox.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ final class Checkbox<T>
134134
buffer.writeAnsiAll([
135135
AsciiControl.lineFeed,
136136
SetStyles(Style.foreground(Color.brightBlack)),
137-
Print(
138-
'(Press ↑/↓ to navigate, space to select, enter to confirm)'),
137+
Print('(Press ↑/↓ to navigate, space to select, enter to confirm)'),
139138
SetStyles.reset,
140139
]);
141140

lib/src/application/components/task.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ final class StepManager with TerminalTools {
4646
/// Add new step to the task.
4747
Future<T> step<T>(String message, {FutureOr<T> Function()? callback}) {
4848
if (isInitialStep) {
49+
_terminal.enableRawMode();
4950
createSpace(_terminal, 1);
5051
_position = readCursorPosition(_terminal);
5152
isInitialStep = false;
@@ -63,7 +64,7 @@ final class StepManager with TerminalTools {
6364
final buffer = StringBuffer();
6465

6566
buffer.writeAnsiAll([
66-
CursorPosition.moveTo(_position!.$2, _position!.$1),
67+
CursorPosition.moveToColumn(_position!.$1),
6768
SetStyles(Style.foreground(Color.green)),
6869
Print(_loadingSteps[_loadingStep]),
6970
SetStyles.reset
@@ -90,6 +91,7 @@ final class StepManager with TerminalTools {
9091

9192
_timer?.cancel();
9293
stdout.write(buffer.toString());
94+
_terminal.disableRawMode();
9395
}
9496

9597
/// Finishes the task with an error message.
@@ -106,6 +108,7 @@ final class StepManager with TerminalTools {
106108

107109
_timer?.cancel();
108110
stdout.write(buffer.toString());
111+
_terminal.disableRawMode();
109112
}
110113

111114
/// Finishes the task with an error message.
@@ -122,10 +125,17 @@ final class StepManager with TerminalTools {
122125

123126
_timer?.cancel();
124127
stdout.write(buffer.toString());
128+
_terminal.disableRawMode();
125129
}
126130

127131
List<Sequence> _messageSequence(String message) {
128-
return [Print(message), SetStyles.reset, AsciiControl.lineFeed];
132+
return [
133+
Print(message),
134+
SetStyles.reset,
135+
CursorVisibility.show,
136+
AsciiControl.lineFeed,
137+
const CursorPosition.moveToColumn(0)
138+
];
129139
}
130140

131141
void _drawLoader(void Function() render) {
@@ -163,7 +173,6 @@ final class StepTask<T> {
163173
SetStyles(Style.foreground(Color.brightBlack)),
164174
Print(' $_message'),
165175
SetStyles.reset,
166-
AsciiControl.lineFeed,
167176
]);
168177

169178
stdout.write(buffer.toString());

0 commit comments

Comments
 (0)