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:
@@ -13,6 +13,7 @@ import '../base/context.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
@@ -746,15 +747,18 @@ class NotifyingLogger extends Logger {
|
||||
Stream<LogMessage> get onMessage => _messageController.stream;
|
||||
|
||||
@override
|
||||
void printError(String message, { StackTrace stackTrace, bool emphasis = false }) {
|
||||
void printError(String message, { StackTrace stackTrace, bool emphasis = false, TerminalColor color }) {
|
||||
_messageController.add(LogMessage('error', message, stackTrace));
|
||||
}
|
||||
|
||||
@override
|
||||
void printStatus(
|
||||
String message,
|
||||
{ bool emphasis = false, bool newline = true, String ansiAlternative, int indent }
|
||||
) {
|
||||
String message, {
|
||||
bool emphasis = false,
|
||||
TerminalColor color,
|
||||
bool newline = true,
|
||||
int indent,
|
||||
}) {
|
||||
_messageController.add(LogMessage('status', message));
|
||||
}
|
||||
|
||||
@@ -868,7 +872,7 @@ class _AppRunLogger extends Logger {
|
||||
int _nextProgressId = 0;
|
||||
|
||||
@override
|
||||
void printError(String message, { StackTrace stackTrace, bool emphasis = false }) {
|
||||
void printError(String message, { StackTrace stackTrace, bool emphasis, TerminalColor color}) {
|
||||
if (parent != null) {
|
||||
parent.printError(message, stackTrace: stackTrace, emphasis: emphasis);
|
||||
} else {
|
||||
@@ -889,14 +893,22 @@ class _AppRunLogger extends Logger {
|
||||
|
||||
@override
|
||||
void printStatus(
|
||||
String message, {
|
||||
bool emphasis = false, bool newline = true, String ansiAlternative, int indent
|
||||
}) {
|
||||
String message, {
|
||||
bool emphasis = false,
|
||||
TerminalColor color,
|
||||
bool newline = true,
|
||||
int indent,
|
||||
}) {
|
||||
if (parent != null) {
|
||||
parent.printStatus(message, emphasis: emphasis, newline: newline,
|
||||
ansiAlternative: ansiAlternative, indent: indent);
|
||||
parent.printStatus(
|
||||
message,
|
||||
emphasis: emphasis,
|
||||
color: color,
|
||||
newline: newline,
|
||||
indent: indent,
|
||||
);
|
||||
} else {
|
||||
_sendLogEvent(<String, dynamic>{ 'log': message });
|
||||
_sendLogEvent(<String, dynamic>{'log': message});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../bundle.dart' as bundle;
|
||||
import '../cache.dart';
|
||||
@@ -188,9 +189,6 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
||||
return result;
|
||||
}
|
||||
|
||||
static const String _bold = '\u001B[0;1m';
|
||||
static const String _reset = '\u001B[0m';
|
||||
|
||||
String _vmServiceToString(VMService vmService, {int tabDepth = 0}) {
|
||||
final Uri addr = vmService.httpAddress;
|
||||
final String embedder = vmService.vm.embedder;
|
||||
@@ -218,7 +216,7 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
||||
final String tabs = '\t' * tabDepth;
|
||||
final String extraTabs = '\t' * (tabDepth + 1);
|
||||
final StringBuffer stringBuffer = StringBuffer(
|
||||
'$tabs$_bold$embedder at $addr$_reset\n'
|
||||
'$tabs${terminal.bolden('$embedder at $addr')}\n'
|
||||
'${extraTabs}RSS: $maxRSS\n'
|
||||
'${extraTabs}Native allocations: $heapSize\n'
|
||||
'${extraTabs}New Spaces: $newUsed of $newCap\n'
|
||||
@@ -257,7 +255,7 @@ class FuchsiaReloadCommand extends FlutterCommand {
|
||||
final String tabs = '\t' * tabDepth;
|
||||
final String extraTabs = '\t' * (tabDepth + 1);
|
||||
return
|
||||
'$tabs$_bold$shortName$_reset\n'
|
||||
'$tabs${terminal.bolden(shortName)}\n'
|
||||
'${extraTabs}Isolate number: $number\n'
|
||||
'${extraTabs}Observatory: $isolateAddr\n'
|
||||
'${extraTabs}Debugger: $debuggerAddr\n'
|
||||
|
||||
Reference in New Issue
Block a user