Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mason_logger): windows progress animation #620

Merged
merged 8 commits into from Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/mason_logger/lib/src/mason_logger.dart
Expand Up @@ -3,7 +3,6 @@ import 'dart:convert';
import 'dart:io' as io;

import 'package:mason_logger/mason_logger.dart';
import 'package:mason_logger/src/stdio_overrides.dart';

part 'progress.dart';

Expand Down
4 changes: 1 addition & 3 deletions packages/mason_logger/lib/src/progress.dart
Expand Up @@ -52,11 +52,9 @@ class Progress {
..reset()
..start();

final stdioType = StdioOverrides.current?.stdioType ?? io.stdioType;

// The animation is only shown when it would be meaningful.
// Do not animate if the stdio type is not a terminal.
if (stdioType(_stdout) != io.StdioType.terminal) {
if (!_stdout.hasTerminal) {
final frames = _options.animation.frames;
final char = frames.isEmpty ? '' : frames.first;
final prefix = char.isEmpty ? char : '${lightGreen.wrap(char)} ';
Expand Down
49 changes: 0 additions & 49 deletions packages/mason_logger/lib/src/stdio_overrides.dart

This file was deleted.

1 change: 1 addition & 0 deletions packages/mason_logger/test/src/mason_logger_test.dart
Expand Up @@ -503,6 +503,7 @@ void main() {

group('.progress', () {
test('writes lines to stdout', () async {
when(() => stdout.hasTerminal).thenReturn(true);
await IOOverrides.runZoned(
() async {
const time = '(0.Xs)';
Expand Down
25 changes: 3 additions & 22 deletions packages/mason_logger/test/src/progress_test.dart
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:io';

import 'package:mason_logger/mason_logger.dart';
import 'package:mason_logger/src/stdio_overrides.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

Expand All @@ -13,12 +12,11 @@ class MockStdin extends Mock implements Stdin {}
void main() {
group('Progress', () {
late Stdout stdout;
late StdioType Function(dynamic) stdioType;

setUp(() {
stdout = MockStdout();
when(() => stdout.supportsAnsiEscapes).thenReturn(true);
stdioType = (dynamic _) => StdioType.terminal;
when(() => stdout.hasTerminal).thenReturn(true);
});

test('writes ms when elapsed time is less than 0.1s', () async {
Expand All @@ -38,6 +36,7 @@ void main() {
});

test('writes static message when stdioType is not terminal', () async {
when(() => stdout.hasTerminal).thenReturn(false);
await _runZoned(
() async {
const message = 'test message';
Expand All @@ -54,7 +53,6 @@ void main() {
]);
},
stdout: () => stdout,
stdioType: () => (dynamic _) => StdioType.other,
zoneValues: {AnsiCode: true},
);
});
Expand Down Expand Up @@ -95,7 +93,6 @@ void main() {
},
stdout: () => stdout,
stdin: () => stdin,
stdioType: () => stdioType,
);
});

Expand Down Expand Up @@ -135,7 +132,6 @@ void main() {
},
stdout: () => stdout,
stdin: () => stdin,
stdioType: () => stdioType,
);
});

Expand Down Expand Up @@ -170,7 +166,6 @@ void main() {
).called(1);
},
stdout: () => stdout,
stdioType: () => stdioType,
zoneValues: {AnsiCode: true},
);
});
Expand All @@ -185,7 +180,6 @@ void main() {
verifyNever(() => stdout.write(any()));
},
stdout: () => stdout,
stdioType: () => stdioType,
zoneValues: {AnsiCode: true},
);
});
Expand Down Expand Up @@ -231,7 +225,6 @@ void main() {
).called(1);
},
stdout: () => stdout,
stdioType: () => stdioType,
zoneValues: {AnsiCode: true},
);
});
Expand Down Expand Up @@ -286,7 +279,6 @@ void main() {
).called(1);
},
stdout: () => stdout,
stdioType: () => stdioType,
zoneValues: {AnsiCode: true},
);
});
Expand All @@ -301,7 +293,6 @@ void main() {
verifyNever(() => stdout.write(any()));
},
stdout: () => stdout,
stdioType: () => stdioType,
zoneValues: {AnsiCode: true},
);
});
Expand Down Expand Up @@ -344,7 +335,6 @@ void main() {
).called(1);
},
stdout: () => stdout,
stdioType: () => stdioType,
zoneValues: {AnsiCode: true},
);
});
Expand All @@ -359,7 +349,6 @@ void main() {
verifyNever(() => stdout.write(any()));
},
stdout: () => stdout,
stdioType: () => stdioType,
zoneValues: {AnsiCode: true},
);
});
Expand All @@ -370,19 +359,11 @@ void main() {
T _runZoned<T>(
T Function() body, {
Map<Object?, Object?>? zoneValues,
StdioType Function(dynamic) Function()? stdioType,
Stdin Function()? stdin,
Stdout Function()? stdout,
}) {
return runZoned(
() {
return StdioOverrides.runZoned(
() {
return IOOverrides.runZoned(body, stdout: stdout, stdin: stdin);
},
stdioType: stdioType,
);
},
() => IOOverrides.runZoned(body, stdout: stdout, stdin: stdin),
zoneValues: zoneValues,
);
}
69 changes: 0 additions & 69 deletions packages/mason_logger/test/src/stdio_overrides_test.dart

This file was deleted.