mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

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
65 lines
1.9 KiB
Dart
65 lines
1.9 KiB
Dart
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'artifacts.dart';
|
|
import 'base/config.dart';
|
|
import 'base/context.dart';
|
|
import 'base/logger.dart';
|
|
import 'base/terminal.dart';
|
|
import 'cache.dart';
|
|
|
|
Logger get logger => context[Logger];
|
|
Cache get cache => Cache.instance;
|
|
Config get config => Config.instance;
|
|
Artifacts get artifacts => Artifacts.instance;
|
|
|
|
/// Display an error level message to the user. Commands should use this if they
|
|
/// fail in some way.
|
|
///
|
|
/// Set [emphasis] to true to make the output bold if it's supported.
|
|
/// Set [color] to a [TerminalColor] to color the output, if the logger
|
|
/// supports it. The [color] defaults to [TerminalColor.red].
|
|
void printError(
|
|
String message, {
|
|
StackTrace stackTrace,
|
|
bool emphasis,
|
|
TerminalColor color,
|
|
}) {
|
|
logger.printError(
|
|
message,
|
|
stackTrace: stackTrace,
|
|
emphasis: emphasis ?? false,
|
|
color: color,
|
|
);
|
|
}
|
|
|
|
/// Display normal output of the command. This should be used for things like
|
|
/// progress messages, success messages, or just normal command output.
|
|
///
|
|
/// Set `emphasis` to true to make the output bold if it's supported.
|
|
///
|
|
/// Set `newline` to false to skip the trailing linefeed.
|
|
///
|
|
/// If `indent` is provided, each line of the message will be prepended by the
|
|
/// specified number of whitespaces.
|
|
void printStatus(
|
|
String message, {
|
|
bool emphasis,
|
|
bool newline,
|
|
TerminalColor color,
|
|
int indent,
|
|
}) {
|
|
logger.printStatus(
|
|
message,
|
|
emphasis: emphasis ?? false,
|
|
color: color,
|
|
newline: newline ?? true,
|
|
indent: indent,
|
|
);
|
|
}
|
|
|
|
/// Use this for verbose tracing output. Users can turn this output on in order
|
|
/// to help diagnose issues with the toolchain or with their setup.
|
|
void printTrace(String message) => logger.printTrace(message);
|