From 57b3422795985d1d393a8e426b8b9a11bb0119ae Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Sat, 1 Apr 2017 17:47:09 -0700 Subject: [PATCH] Bold each line individually (#9069) This should make the message in Travis logs look better. --- packages/flutter_tools/lib/executable.dart | 2 +- packages/flutter_tools/lib/src/base/logger.dart | 16 ++++++++++++---- .../lib/src/runner/flutter_command.dart | 2 +- packages/flutter_tools/lib/src/usage.dart | 10 ++++++---- packages/flutter_tools/test/src/context.dart | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/flutter_tools/lib/executable.dart b/packages/flutter_tools/lib/executable.dart index a5715874fd..887a3909b9 100644 --- a/packages/flutter_tools/lib/executable.dart +++ b/packages/flutter_tools/lib/executable.dart @@ -294,7 +294,7 @@ Future _doctorText() async { Future _exit(int code) async { if (flutterUsage.isFirstRun) - flutterUsage.printUsage(); + flutterUsage.printWelcome(); // Send any last analytics calls that are in progress without overly delaying // the tool's exit (we wait a maximum of 250ms). diff --git a/packages/flutter_tools/lib/src/base/logger.dart b/packages/flutter_tools/lib/src/base/logger.dart index 048758e8d6..639eda79b8 100644 --- a/packages/flutter_tools/lib/src/base/logger.dart +++ b/packages/flutter_tools/lib/src/base/logger.dart @@ -277,14 +277,22 @@ class AnsiTerminal { bool supportsColor; - String bolden(String str) => supportsColor ? '$_bold$str$_reset' : str; + String bolden(String message) { + if (!supportsColor) + return message; + final StringBuffer result = new StringBuffer(); + for (String line in message.split('\n')) + result.writeln('$_bold$line$_reset'); + return result.toString(); + } String clearScreen() => supportsColor ? _clear : '\n\n'; set singleCharMode(bool value) { - // TODO(goderbauer): instead of trying to set lineMode and then catching [_ENOTTY] or [_INVALID_HANDLE], - // we should check beforehand if stdin is connected to a terminal or not - // (requires https://github.com/dart-lang/sdk/issues/29083 to be resolved). + // TODO(goderbauer): instead of trying to set lineMode and then catching + // [_ENOTTY] or [_INVALID_HANDLE], we should check beforehand if stdin is + // connected to a terminal or not. + // (Requires https://github.com/dart-lang/sdk/issues/29083 to be resolved.) try { // The order of setting lineMode and echoMode is important on Windows. if (value) { diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index be46185530..9485618db3 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -116,7 +116,7 @@ abstract class FlutterCommand extends Command { final UsageTimer analyticsTimer = usagePath == null ? null : flutterUsage.startTimer(name); if (flutterUsage.isFirstRun) - flutterUsage.printUsage(); + flutterUsage.printWelcome(); return verifyThenRunCommand().whenComplete(() { final int ms = stopwatch.elapsedMilliseconds; diff --git a/packages/flutter_tools/lib/src/usage.dart b/packages/flutter_tools/lib/src/usage.dart index ccef45bc16..4f72326011 100644 --- a/packages/flutter_tools/lib/src/usage.dart +++ b/packages/flutter_tools/lib/src/usage.dart @@ -47,7 +47,7 @@ class Usage { Analytics _analytics; - bool _printedUsage = false; + bool _printedWelcome = false; bool _suppressAnalytics = false; bool get isFirstRun => _analytics.firstRun; @@ -108,10 +108,12 @@ class Usage { await _analytics.waitForLastPing(timeout: const Duration(milliseconds: 250)); } - void printUsage() { - if (_printedUsage) + void printWelcome() { + // This gets called if it's the first run by the selected command, if any, + // and on exit, in case there was no command. + if (_printedWelcome) return; - _printedUsage = true; + _printedWelcome = true; printStatus(''); printStatus(''' diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index 30cbdb36cf..c679f946a1 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -218,7 +218,7 @@ class MockUsage implements Usage { Future ensureAnalyticsSent() => new Future.value(); @override - void printUsage() { } + void printWelcome() { } } class _MockUsageTimer implements UsageTimer {