Added more extensive ANSI color printing support on terminals. (#20958)

This adds support to AnsiTerminal for colored output, and makes all tool output written to stderr (with the printError function) colored red.

No color codes are sent if the terminal doesn't support color (or isn't a terminal).

Also makes "progress" output print the elapsed time when not connected to a terminal, so that redirected output and terminal output match (redirected output doesn't print the spinner, however).

Addresses #17307
This commit is contained in:
Greg Spencer
2018-09-19 15:22:43 -07:00
committed by GitHub
parent 85b4670b2a
commit 7caa65943f
13 changed files with 450 additions and 128 deletions

View File

@@ -76,7 +76,7 @@ void testUsingContext(String description, dynamic testMethod(), {
when(mock.getAttachedDevices()).thenReturn(<IOSSimulator>[]);
return mock;
},
Logger: () => BufferLogger(),
Logger: () => BufferLogger()..supportsColor = false,
OperatingSystemUtils: () => MockOperatingSystemUtils(),
SimControl: () => MockSimControl(),
Usage: () => MockUsage(),

View File

@@ -287,11 +287,15 @@ class MemoryIOSink implements IOSink {
/// A Stdio that collects stdout and supports simulated stdin.
class MockStdio extends Stdio {
final MemoryIOSink _stdout = MemoryIOSink();
final MemoryIOSink _stderr = MemoryIOSink();
final StreamController<List<int>> _stdin = StreamController<List<int>>();
@override
IOSink get stdout => _stdout;
@override
IOSink get stderr => _stderr;
@override
Stream<List<int>> get stdin => _stdin.stream;
@@ -300,6 +304,7 @@ class MockStdio extends Stdio {
}
List<String> get writtenToStdout => _stdout.writes.map(_stdout.encoding.decode).toList();
List<String> get writtenToStderr => _stderr.writes.map(_stderr.encoding.decode).toList();
}
class MockPollingDeviceDiscovery extends PollingDeviceDiscovery {