Skip to content

Commit 5de0643

Browse files
committed
fix: test error in log_update.dart
1 parent dee092f commit 5de0643

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

lib/src/log_update.dart

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ import 'package:ansi_slice/ansi_slice.dart';
55
import 'package:ansi_strip/ansi_strip.dart';
66
import 'package:ansi_wrap/ansi_wrap.dart';
77

8-
int getWidth(IOSink stream) {
9-
return stdout.terminalColumns;
8+
int getWidth(Stdout sink) {
9+
if (sink.hasTerminal) {
10+
return sink.terminalColumns;
11+
}
12+
return 80;
13+
}
14+
15+
int getHeight(Stdout sink) {
16+
if (sink.hasTerminal) {
17+
return sink.terminalLines;
18+
}
19+
return 24;
1020
}
1121

12-
String fitToTerminalHeight(IOSink stream, String text) {
13-
final terminalHeight = stdout.terminalLines;
22+
String fitToTerminalHeight(Stdout sink, String text) {
23+
final terminalHeight = getHeight(sink);
1424
final lines = text.split('\n');
1525

1626
final toRemove = lines.length - terminalHeight;
@@ -24,7 +34,7 @@ String fitToTerminalHeight(IOSink stream, String text) {
2434
);
2535
}
2636

27-
Render createLogUpdate(IOSink stream, {bool showCursor = true}) {
37+
Render createLogUpdate(Stdout stream, {bool showCursor = true}) {
2838
return Render(stream, showCursor);
2939
}
3040

@@ -35,41 +45,41 @@ class Render {
3545
int previousLineCount = 0;
3646
int previousWidth;
3747
String previousOutput = '';
38-
final IOSink stream;
48+
final Stdout sink;
3949
final bool showCursor;
4050

41-
Render(this.stream, this.showCursor) : previousWidth = getWidth(stream);
51+
Render(this.sink, this.showCursor) : previousWidth = getWidth(sink);
4252

4353
void call(String output) {
4454
if (!showCursor) {
45-
stream.write(ansiEscapes.cursorHide);
55+
sink.write(ansiEscapes.cursorHide);
4656
}
47-
output = fitToTerminalHeight(stream, output);
48-
final width = getWidth(stream);
57+
output = fitToTerminalHeight(sink, output);
58+
final width = getWidth(sink);
4959
if (output == previousOutput && previousWidth == width) {
5060
return;
5161
}
5262

5363
previousOutput = output;
5464
previousWidth = width;
5565
output = wrapAnsi(output, width, trim: false, hard: true, wordWrap: false);
56-
stream.write(ansiEscapes.eraseLines(previousLineCount) + output);
66+
sink.write(ansiEscapes.eraseLines(previousLineCount) + output);
5767
previousLineCount = output.split('\n').length;
5868
}
5969

6070
void clear() {
61-
stream.write(ansiEscapes.eraseLines(previousLineCount));
71+
sink.write(ansiEscapes.eraseLines(previousLineCount));
6272
previousOutput = '';
63-
previousWidth = getWidth(stream);
73+
previousWidth = getWidth(sink);
6474
previousLineCount = 0;
6575
}
6676

6777
void done() {
6878
previousOutput = '';
69-
previousWidth = getWidth(stream);
79+
previousWidth = getWidth(sink);
7080
previousLineCount = 0;
7181
if (!showCursor) {
72-
stream.write(ansiEscapes.cursorShow);
82+
sink.write(ansiEscapes.cursorShow);
7383
}
7484
}
7585
}

pubspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ dependencies:
1616
ansi_wrap: ^0.1.2+1
1717
args: ^2.3.1
1818
glob: ^2.0.1
19-
indent: ^2.0.0
2019
path: ^1.8.0
2120
verbose: ^0.1.0
2221
yaml: ^3.1.1

0 commit comments

Comments
 (0)