Skip to content

Commit 4d788b1

Browse files
authored
Reduce animations further when --no-cli-animations is set. (#133598)
1 parent d8c98c1 commit 4d788b1

File tree

9 files changed

+48
-12
lines changed

9 files changed

+48
-12
lines changed

packages/flutter_tools/lib/executable.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,16 @@ Future<void> main(List<String> args) async {
124124
windows: globals.platform.isWindows,
125125
);
126126
},
127-
Terminal: () {
127+
AnsiTerminal: () {
128128
return AnsiTerminal(
129129
stdio: globals.stdio,
130130
platform: globals.platform,
131131
now: DateTime.now(),
132-
isCliAnimationEnabled: featureFlags.isCliAnimationEnabled,
132+
// So that we don't animate anything before calling applyFeatureFlags, default
133+
// the animations to disabled in real apps.
134+
defaultCliAnimationEnabled: false,
133135
);
136+
// runner.run calls "terminal.applyFeatureFlags()"
134137
},
135138
PreRunValidator: () => PreRunValidator(fileSystem: globals.fs),
136139
},

packages/flutter_tools/lib/runner.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'src/base/logger.dart';
1818
import 'src/base/process.dart';
1919
import 'src/context_runner.dart';
2020
import 'src/doctor.dart';
21+
import 'src/features.dart';
2122
import 'src/globals.dart' as globals;
2223
import 'src/reporting/crash_reporting.dart';
2324
import 'src/reporting/reporting.dart';
@@ -44,6 +45,8 @@ Future<int> run(
4445
}
4546

4647
return runInContext<int>(() async {
48+
globals.terminal.applyFeatureFlags(featureFlags);
49+
4750
reportCrashes ??= !await globals.isRunningOnBot;
4851
final FlutterCommandRunner runner = FlutterCommandRunner(verboseHelp: verboseHelp);
4952
commands().forEach(runner.addCommand);

packages/flutter_tools/lib/src/base/context.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import 'dart:collection';
77

88
import 'package:meta/meta.dart';
99

10+
// TODO(ianh): We should remove AppContext's mechanism and replace it with
11+
// passing dependencies directly in constructors, methods, etc.
12+
1013
/// Generates an [AppContext] value.
1114
///
1215
/// Generators are allowed to return `null`, in which case the context will

packages/flutter_tools/lib/src/base/terminal.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import '../convert.dart';
6+
import '../features.dart';
67
import 'io.dart' as io;
78
import 'logger.dart';
89
import 'platform.dart';
@@ -69,6 +70,7 @@ class OutputPreferences {
6970
}
7071

7172
/// The command line terminal, if available.
73+
// TODO(ianh): merge this with AnsiTerminal, the abstraction isn't giving us anything.
7274
abstract class Terminal {
7375
/// Create a new test [Terminal].
7476
///
@@ -81,9 +83,12 @@ abstract class Terminal {
8183
/// to perform animations.
8284
bool get supportsColor;
8385

84-
/// Whether to show animations on this terminal.
86+
/// Whether animations should be used in the output.
8587
bool get isCliAnimationEnabled;
8688

89+
/// Configures isCliAnimationEnabled based on a [FeatureFlags] object.
90+
void applyFeatureFlags(FeatureFlags flags);
91+
8792
/// Whether the current terminal can display emoji.
8893
bool get supportsEmoji;
8994

@@ -158,11 +163,12 @@ class AnsiTerminal implements Terminal {
158163
required io.Stdio stdio,
159164
required Platform platform,
160165
DateTime? now, // Time used to determine preferredStyle. Defaults to 0001-01-01 00:00.
161-
this.isCliAnimationEnabled = true,
166+
bool defaultCliAnimationEnabled = true,
162167
})
163168
: _stdio = stdio,
164169
_platform = platform,
165-
_now = now ?? DateTime(1);
170+
_now = now ?? DateTime(1),
171+
_isCliAnimationEnabled = defaultCliAnimationEnabled;
166172

167173
final io.Stdio _stdio;
168174
final Platform _platform;
@@ -207,7 +213,14 @@ class AnsiTerminal implements Terminal {
207213
bool get supportsColor => _platform.stdoutSupportsAnsi;
208214

209215
@override
210-
final bool isCliAnimationEnabled;
216+
bool get isCliAnimationEnabled => _isCliAnimationEnabled;
217+
218+
bool _isCliAnimationEnabled;
219+
220+
@override
221+
void applyFeatureFlags(FeatureFlags flags) {
222+
_isCliAnimationEnabled = flags.isCliAnimationEnabled;
223+
}
211224

212225
// Assume unicode emojis are supported when not on Windows.
213226
// If we are on Windows, unicode emojis are supported in Windows Terminal,
@@ -419,7 +432,14 @@ class _TestTerminal implements Terminal {
419432
final bool supportsColor;
420433

421434
@override
422-
bool get isCliAnimationEnabled => supportsColor;
435+
bool get isCliAnimationEnabled => supportsColor && _isCliAnimationEnabled;
436+
437+
bool _isCliAnimationEnabled = true;
438+
439+
@override
440+
void applyFeatureFlags(FeatureFlags flags) {
441+
_isCliAnimationEnabled = flags.isCliAnimationEnabled;
442+
}
423443

424444
@override
425445
final bool supportsEmoji;

packages/flutter_tools/lib/src/context_runner.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
6-
75
import 'dart:async';
86

97
import 'package:process/process.dart';
@@ -84,6 +82,8 @@ Future<T> runInContext<T>(
8482
return runner();
8583
}
8684

85+
// TODO(ianh): We should split this into two, one for tests (which should be
86+
// in test/), and one for production (which should be in executable.dart).
8787
return context.run<T>(
8888
name: 'global fallbacks',
8989
body: runnerWrapper,

packages/flutter_tools/lib/src/features.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import 'base/context.dart';
66

77
/// The current [FeatureFlags] implementation.
8-
///
9-
/// If not injected, a default implementation is provided.
108
FeatureFlags get featureFlags => context.get<FeatureFlags>()!;
119

1210
/// The interface used to determine if a particular [Feature] is enabled.

packages/flutter_tools/lib/src/globals.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ import 'runner/flutter_command.dart';
4949
import 'runner/local_engine.dart';
5050
import 'version.dart';
5151

52+
// TODO(ianh): We should remove all the global variables and replace them with
53+
// arguments (to constructors, methods, etc, as appropriate).
54+
5255
Artifacts? get artifacts => context.get<Artifacts>();
5356
BuildSystem get buildSystem => context.get<BuildSystem>()!;
5457
Cache get cache => context.get<Cache>()!;

packages/flutter_tools/test/commands.shard/hermetic/custom_devices_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:flutter_tools/src/cache.dart';
2020
import 'package:flutter_tools/src/commands/custom_devices.dart';
2121
import 'package:flutter_tools/src/custom_devices/custom_device_config.dart';
2222
import 'package:flutter_tools/src/custom_devices/custom_devices_config.dart';
23+
import 'package:flutter_tools/src/features.dart';
2324
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
2425

2526
import '../../src/common.dart';
@@ -241,6 +242,11 @@ class FakeTerminal implements Terminal {
241242
@override
242243
bool get isCliAnimationEnabled => terminal.isCliAnimationEnabled;
243244

245+
@override
246+
void applyFeatureFlags(FeatureFlags flags) {
247+
// ignored
248+
}
249+
244250
@override
245251
bool get supportsEmoji => terminal.supportsEmoji;
246252

packages/flutter_tools/test/general.shard/base/logger_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ void main() {
12921292
terminal: AnsiTerminal(
12931293
stdio: fakeStdio,
12941294
platform: _kNoAnsiPlatform,
1295-
isCliAnimationEnabled: false,
1295+
defaultCliAnimationEnabled: false,
12961296
),
12971297
stdio: fakeStdio,
12981298
stopwatchFactory: FakeStopwatchFactory(stopwatch: FakeStopwatch()),

0 commit comments

Comments
 (0)