mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Implements WindowsStdoutLogger (#8189)
Replaces unprintable characters with alternative symbols.
This commit is contained in:
parent
fac9efbacd
commit
071efec271
@ -105,7 +105,7 @@ Future<Null> main(List<String> args) async {
|
||||
context.putIfAbsent(Platform, () => new LocalPlatform());
|
||||
context.putIfAbsent(FileSystem, () => new LocalFileSystem());
|
||||
context.putIfAbsent(ProcessManager, () => new LocalProcessManager());
|
||||
context.putIfAbsent(Logger, () => new StdoutLogger());
|
||||
context.putIfAbsent(Logger, () => platform.isWindows ? new WindowsStdoutLogger() : new StdoutLogger());
|
||||
|
||||
// Order-independent context entries
|
||||
context.putIfAbsent(DeviceManager, () => new DeviceManager());
|
||||
|
||||
@ -6,6 +6,7 @@ import 'dart:async';
|
||||
import 'dart:convert' show ASCII, LineSplitter;
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:stack_trace/stack_trace.dart';
|
||||
|
||||
import 'io.dart';
|
||||
@ -53,6 +54,7 @@ class Status {
|
||||
typedef void _FinishCallback();
|
||||
|
||||
class StdoutLogger extends Logger {
|
||||
|
||||
Status _status;
|
||||
|
||||
@override
|
||||
@ -83,6 +85,11 @@ class StdoutLogger extends Logger {
|
||||
message = LineSplitter.split(message).map((String line) => ' ' * indent + line).join('\n');
|
||||
if (newline)
|
||||
message = '$message\n';
|
||||
writeToStdOut(message);
|
||||
}
|
||||
|
||||
@protected
|
||||
void writeToStdOut(String message) {
|
||||
stdout.write(message);
|
||||
}
|
||||
|
||||
@ -106,6 +113,24 @@ class StdoutLogger extends Logger {
|
||||
}
|
||||
}
|
||||
|
||||
/// A [StdoutLogger] which replaces Unicode characters that cannot be printed to
|
||||
/// the Windows console with alternative symbols.
|
||||
///
|
||||
/// This exists because of https://github.com/dart-lang/sdk/issues/28571.
|
||||
class WindowsStdoutLogger extends StdoutLogger {
|
||||
|
||||
@override
|
||||
void writeToStdOut(String message) {
|
||||
stdout.write(message
|
||||
.replaceAll('✗', 'X')
|
||||
.replaceAll('✓', '+')
|
||||
.replaceAll('•', '*')
|
||||
);
|
||||
// TODO(goderbauer): find a way to replace all other non-printable characters
|
||||
// with the unrepresentable character symbol '<EFBFBD>'
|
||||
}
|
||||
}
|
||||
|
||||
class BufferLogger extends Logger {
|
||||
@override
|
||||
bool get isVerbose => false;
|
||||
@ -217,7 +242,7 @@ enum _LogType {
|
||||
|
||||
class AnsiTerminal {
|
||||
AnsiTerminal() {
|
||||
// TODO(devoncarew): This detection does not work for Windows.
|
||||
// TODO(devoncarew): This detection does not work for Windows (https://github.com/dart-lang/sdk/issues/28614).
|
||||
String term = platform.environment['TERM'];
|
||||
supportsColor = term != null && term != 'dumb';
|
||||
}
|
||||
|
||||
@ -126,7 +126,7 @@ class Doctor {
|
||||
for (ValidationMessage message in result.messages) {
|
||||
String text = message.message.replaceAll('\n', '\n ');
|
||||
if (message.isError) {
|
||||
printStatus(' x $text', emphasis: true);
|
||||
printStatus(' ✗ $text', emphasis: true);
|
||||
} else {
|
||||
printStatus(' • $text');
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user