Support disabling animations in the CLI (#132239)
This commit is contained in:
@@ -259,8 +259,12 @@ class CommandHelpOption {
|
||||
message.write(''.padLeft(width - parentheticalText.length));
|
||||
message.write(_terminal.color(parentheticalText, TerminalColor.grey));
|
||||
|
||||
// Terminals seem to require this because we have both bolded and colored
|
||||
// a line. Otherwise the next line comes out bold until a reset bold.
|
||||
// Some terminals seem to have a buggy implementation of the SGR ANSI escape
|
||||
// codes and seem to require that we explicitly request "normal intensity"
|
||||
// at the end of the line to prevent the next line comes out bold, despite
|
||||
// the fact that the line already contains a "normal intensity" code.
|
||||
// This doesn't make much sense but has been reproduced by multiple users.
|
||||
// See: https://github.com/flutter/flutter/issues/52204
|
||||
if (_terminal.supportsColor) {
|
||||
message.write(AnsiTerminal.resetBold);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ abstract class Logger {
|
||||
/// If true, silences the logger output.
|
||||
bool quiet = false;
|
||||
|
||||
/// If true, this logger supports color output.
|
||||
/// If true, this logger supports ANSI sequences and animations are enabled.
|
||||
bool get supportsColor;
|
||||
|
||||
/// If true, this logger is connected to a terminal.
|
||||
@@ -443,7 +443,7 @@ class StdoutLogger extends Logger {
|
||||
bool get isVerbose => false;
|
||||
|
||||
@override
|
||||
bool get supportsColor => terminal.supportsColor;
|
||||
bool get supportsColor => terminal.supportsColor && terminal.isCliAnimationEnabled;
|
||||
|
||||
@override
|
||||
bool get hasTerminal => _stdio.stdinHasTerminal;
|
||||
@@ -772,7 +772,7 @@ class BufferLogger extends Logger {
|
||||
bool get isVerbose => _verbose;
|
||||
|
||||
@override
|
||||
bool get supportsColor => terminal.supportsColor;
|
||||
bool get supportsColor => terminal.supportsColor && terminal.isCliAnimationEnabled;
|
||||
|
||||
final StringBuffer _error = StringBuffer();
|
||||
final StringBuffer _warning = StringBuffer();
|
||||
|
||||
@@ -76,8 +76,14 @@ abstract class Terminal {
|
||||
factory Terminal.test({bool supportsColor, bool supportsEmoji}) = _TestTerminal;
|
||||
|
||||
/// Whether the current terminal supports color escape codes.
|
||||
///
|
||||
/// Check [isCliAnimationEnabled] as well before using `\r` or ANSI sequences
|
||||
/// to perform animations.
|
||||
bool get supportsColor;
|
||||
|
||||
/// Whether to show animations on this terminal.
|
||||
bool get isCliAnimationEnabled;
|
||||
|
||||
/// Whether the current terminal can display emoji.
|
||||
bool get supportsEmoji;
|
||||
|
||||
@@ -152,6 +158,7 @@ class AnsiTerminal implements Terminal {
|
||||
required io.Stdio stdio,
|
||||
required Platform platform,
|
||||
DateTime? now, // Time used to determine preferredStyle. Defaults to 0001-01-01 00:00.
|
||||
this.isCliAnimationEnabled = true,
|
||||
})
|
||||
: _stdio = stdio,
|
||||
_platform = platform,
|
||||
@@ -199,6 +206,9 @@ class AnsiTerminal implements Terminal {
|
||||
@override
|
||||
bool get supportsColor => _platform.stdoutSupportsAnsi;
|
||||
|
||||
@override
|
||||
final bool isCliAnimationEnabled;
|
||||
|
||||
// Assume unicode emojis are supported when not on Windows.
|
||||
// If we are on Windows, unicode emojis are supported in Windows Terminal,
|
||||
// which sets the WT_SESSION environment variable. See:
|
||||
@@ -275,14 +285,14 @@ class AnsiTerminal implements Terminal {
|
||||
}
|
||||
|
||||
@override
|
||||
String clearScreen() => supportsColor ? clear : '\n\n';
|
||||
String clearScreen() => supportsColor && isCliAnimationEnabled ? clear : '\n\n';
|
||||
|
||||
/// Returns ANSI codes to clear [numberOfLines] lines starting with the line
|
||||
/// the cursor is on.
|
||||
///
|
||||
/// If the terminal does not support ANSI codes, returns an empty string.
|
||||
String clearLines(int numberOfLines) {
|
||||
if (!supportsColor) {
|
||||
if (!supportsColor || !isCliAnimationEnabled) {
|
||||
return '';
|
||||
}
|
||||
return cursorBeginningOfLineCode +
|
||||
@@ -402,6 +412,9 @@ class _TestTerminal implements Terminal {
|
||||
@override
|
||||
final bool supportsColor;
|
||||
|
||||
@override
|
||||
bool get isCliAnimationEnabled => supportsColor;
|
||||
|
||||
@override
|
||||
final bool supportsEmoji;
|
||||
|
||||
|
||||
@@ -47,6 +47,9 @@ abstract class FeatureFlags {
|
||||
/// Whether WebAssembly compilation for Flutter Web is enabled.
|
||||
bool get isFlutterWebWasmEnabled => false;
|
||||
|
||||
/// Whether animations are used in the command line interface.
|
||||
bool get isCliAnimationEnabled => true;
|
||||
|
||||
/// Whether a particular feature is enabled for the current channel.
|
||||
///
|
||||
/// Prefer using one of the specific getters above instead of this API.
|
||||
@@ -64,6 +67,7 @@ const List<Feature> allFeatures = <Feature>[
|
||||
flutterFuchsiaFeature,
|
||||
flutterCustomDevicesFeature,
|
||||
flutterWebWasm,
|
||||
cliAnimation,
|
||||
];
|
||||
|
||||
/// All current Flutter feature flags that can be configured.
|
||||
@@ -122,7 +126,7 @@ const Feature flutterFuchsiaFeature = Feature(
|
||||
);
|
||||
|
||||
const Feature flutterCustomDevicesFeature = Feature(
|
||||
name: 'Early support for custom device types',
|
||||
name: 'early support for custom device types',
|
||||
configSetting: 'enable-custom-devices',
|
||||
environmentOverride: 'FLUTTER_CUSTOM_DEVICES',
|
||||
master: FeatureChannelSetting(
|
||||
@@ -146,6 +150,14 @@ const Feature flutterWebWasm = Feature(
|
||||
),
|
||||
);
|
||||
|
||||
/// The [Feature] for CLI animations.
|
||||
///
|
||||
/// The TERM environment variable set to "dumb" turns this off.
|
||||
const Feature cliAnimation = Feature.fullyEnabled(
|
||||
name: 'animations in the command line interface',
|
||||
configSetting: 'cli-animations',
|
||||
);
|
||||
|
||||
/// A [Feature] is a process for conditionally enabling tool features.
|
||||
///
|
||||
/// All settings are optional, and if not provided will generally default to
|
||||
@@ -229,9 +241,9 @@ class Feature {
|
||||
];
|
||||
// Add channel info for settings only on some channels.
|
||||
if (channels.length == 1) {
|
||||
buffer.write('\nThis setting applies to only the ${channels.single} channel.');
|
||||
buffer.write('\nThis setting applies only to the ${channels.single} channel.');
|
||||
} else if (channels.length == 2) {
|
||||
buffer.write('\nThis setting applies to only the ${channels.join(' and ')} channels.');
|
||||
buffer.write('\nThis setting applies only to the ${channels.join(' and ')} channels.');
|
||||
}
|
||||
if (extraHelpText != null) {
|
||||
buffer.write(' $extraHelpText');
|
||||
|
||||
@@ -47,6 +47,14 @@ class FlutterFeatureFlags implements FeatureFlags {
|
||||
@override
|
||||
bool get isFlutterWebWasmEnabled => isEnabled(flutterWebWasm);
|
||||
|
||||
@override
|
||||
bool get isCliAnimationEnabled {
|
||||
if (_platform.environment['TERM'] == 'dumb') {
|
||||
return false;
|
||||
}
|
||||
return isEnabled(cliAnimation);
|
||||
}
|
||||
|
||||
@override
|
||||
bool isEnabled(Feature feature) {
|
||||
final String currentChannel = _flutterVersion.channel;
|
||||
|
||||
@@ -25,8 +25,7 @@ const String _kFlutterFirstRunMessage = '''
|
||||
║ Flutter tool. ║
|
||||
║ ║
|
||||
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
|
||||
║ Note: The Google Privacy Policy describes how data is handled in this ║
|
||||
║ service. ║
|
||||
║ The Google Privacy Policy describes how data is handled in this service. ║
|
||||
║ ║
|
||||
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
|
||||
║ crash reports to Google. ║
|
||||
@@ -36,6 +35,8 @@ const String _kFlutterFirstRunMessage = '''
|
||||
║ ║
|
||||
║ See Google's privacy policy: ║
|
||||
║ https://policies.google.com/privacy ║
|
||||
║ ║
|
||||
║ To disable animations in this tool, use 'flutter config --no-animations'. ║
|
||||
╚════════════════════════════════════════════════════════════════════════════╝
|
||||
''';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user