Unverified Commit e0ab6fc0 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Move outputPreferences to globals (#52846)

parent 0274f170
......@@ -15,7 +15,6 @@ import 'src/base/file_system.dart';
import 'src/base/io.dart';
import 'src/base/logger.dart';
import 'src/base/process.dart';
import 'src/base/terminal.dart';
import 'src/context_runner.dart';
import 'src/doctor.dart';
import 'src/globals.dart' as globals;
......@@ -234,7 +233,7 @@ Future<String> _doctorText() async {
try {
final BufferLogger logger = BufferLogger(
terminal: globals.terminal,
outputPreferences: outputPreferences,
outputPreferences: globals.outputPreferences,
);
await context.run<bool>(
......
......@@ -9,7 +9,6 @@ import 'package:platform/platform.dart';
import '../convert.dart';
import '../globals.dart' as globals;
import 'context.dart';
import 'io.dart' as io;
import 'logger.dart';
......@@ -33,11 +32,6 @@ String get successMark {
return globals.terminal.bolden(globals.terminal.color('✓', TerminalColor.green));
}
OutputPreferences get outputPreferences {
return context?.get<OutputPreferences>() ?? _defaultOutputPreferences;
}
final OutputPreferences _defaultOutputPreferences = OutputPreferences();
/// A class that contains the context settings for command text output to the
/// console.
class OutputPreferences {
......
......@@ -9,8 +9,8 @@ import 'package:intl/intl.dart';
import 'package:meta/meta.dart';
import '../convert.dart';
import '../globals.dart' as globals;
import 'file_system.dart';
import 'terminal.dart';
/// Convert `foo_bar` to `fooBar`.
String camelCase(String str) {
......@@ -239,7 +239,7 @@ String wrapText(String text, { int columnWidth, int hangingIndent, int indent, b
return '';
}
indent ??= 0;
columnWidth ??= outputPreferences.wrapColumn;
columnWidth ??= globals.outputPreferences.wrapColumn;
columnWidth -= indent;
assert(columnWidth >= 0);
......@@ -322,7 +322,7 @@ List<String> _wrapTextAsLines(String text, { int start = 0, int columnWidth, @re
assert(columnWidth != null);
assert(columnWidth >= 0);
assert(start >= 0);
shouldWrap ??= outputPreferences.wrapText;
shouldWrap ??= globals.outputPreferences.wrapText;
/// Returns true if the code unit at [index] in [text] is a whitespace
/// character.
......
......@@ -19,7 +19,6 @@ import 'base/logger.dart';
import 'base/os.dart';
import 'base/process.dart';
import 'base/signals.dart';
import 'base/terminal.dart';
import 'base/time.dart';
import 'base/user_messages.dart';
import 'build_system/build_system.dart';
......@@ -147,13 +146,13 @@ Future<T> runInContext<T>(
? WindowsStdoutLogger(
terminal: globals.terminal,
stdio: globals.stdio,
outputPreferences: outputPreferences,
outputPreferences: globals.outputPreferences,
timeoutConfiguration: timeoutConfiguration,
)
: StdoutLogger(
terminal: globals.terminal,
stdio: globals.stdio,
outputPreferences: outputPreferences,
outputPreferences: globals.outputPreferences,
timeoutConfiguration: timeoutConfiguration,
),
MacOSWorkflow: () => const MacOSWorkflow(),
......
......@@ -229,8 +229,8 @@ class Doctor {
buffer.write(wrapText(
lineBuffer.toString(),
hangingIndent: result.leadingBox.length + 1,
columnWidth: outputPreferences.wrapColumn,
shouldWrap: outputPreferences.wrapText,
columnWidth: globals.outputPreferences.wrapColumn,
shouldWrap: globals.outputPreferences.wrapText,
));
buffer.writeln();
......
......@@ -81,6 +81,9 @@ Xcode get xcode => context.get<Xcode>();
XCDevice get xcdevice => context.get<XCDevice>();
final OutputPreferences _defaultOutputPreferences = OutputPreferences();
OutputPreferences get outputPreferences => context.get<OutputPreferences>() ?? _defaultOutputPreferences;
final BotDetector _defaultBotDetector = BotDetector(
httpClientFactory: context.get<HttpClientFactory>() ?? () => HttpClient(),
platform: platform,
......
......@@ -15,7 +15,6 @@ import 'base/file_system.dart';
import 'base/io.dart' as io;
import 'base/logger.dart';
import 'base/signals.dart';
import 'base/terminal.dart' show outputPreferences;
import 'base/utils.dart';
import 'build_info.dart';
import 'codegen.dart';
......@@ -628,7 +627,7 @@ abstract class ResidentRunner {
logger: globals.logger,
terminal: globals.terminal,
platform: globals.platform,
outputPreferences: outputPreferences,
outputPreferences: globals.outputPreferences,
) {
if (!artifactDirectory.existsSync()) {
artifactDirectory.createSync(recursive: true);
......
......@@ -15,7 +15,6 @@ import '../base/common.dart';
import '../base/context.dart';
import '../base/io.dart' as io;
import '../base/signals.dart';
import '../base/terminal.dart';
import '../base/time.dart';
import '../base/user_messages.dart';
import '../base/utils.dart';
......@@ -128,7 +127,7 @@ abstract class FlutterCommand extends Command<void> {
ArgParser get argParser => _argParser;
final ArgParser _argParser = ArgParser(
allowTrailingOptions: false,
usageLineLength: outputPreferences.wrapText ? outputPreferences.wrapColumn : null,
usageLineLength: globals.outputPreferences.wrapText ? globals.outputPreferences.wrapColumn : null,
);
@override
......
......@@ -139,14 +139,14 @@ class FlutterCommandRunner extends CommandRunner<void> {
ArgParser get argParser => _argParser;
final ArgParser _argParser = ArgParser(
allowTrailingOptions: false,
usageLineLength: outputPreferences.wrapText ? outputPreferences.wrapColumn : null,
usageLineLength: globals.outputPreferences.wrapText ? globals.outputPreferences.wrapColumn : null,
);
@override
String get usageFooter {
return wrapText('Run "flutter help -v" for verbose help output, including less commonly used options.',
columnWidth: outputPreferences.wrapColumn,
shouldWrap: outputPreferences.wrapText,
columnWidth: globals.outputPreferences.wrapColumn,
shouldWrap: globals.outputPreferences.wrapText,
);
}
......@@ -154,8 +154,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
String get usage {
final String usageWithoutDescription = super.usage.substring(description.length + 2);
final String prefix = wrapText(description,
shouldWrap: outputPreferences.wrapText,
columnWidth: outputPreferences.wrapColumn,
shouldWrap: globals.outputPreferences.wrapText,
columnWidth: globals.outputPreferences.wrapColumn,
);
return '$prefix\n\n$usageWithoutDescription';
}
......
......@@ -291,7 +291,7 @@ class FakeFlutterCommand extends FlutterCommand {
@override
Future<FlutterCommandResult> runCommand() {
preferences = outputPreferences;
preferences = globals.outputPreferences;
return Future<FlutterCommandResult>.value(const FlutterCommandResult(ExitStatus.success));
}
......
......@@ -9,6 +9,7 @@ import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/version.dart';
import 'package:flutter_tools/src/vmservice.dart';
import 'package:json_rpc_2/json_rpc_2.dart' as rpc;
......@@ -291,7 +292,7 @@ void main() {
});
}, overrides: <Type, Generator>{
Logger: () => StdoutLogger(
outputPreferences: outputPreferences,
outputPreferences: globals.outputPreferences,
terminal: AnsiTerminal(
stdio: mockStdio,
platform: const LocalPlatform(),
......@@ -311,7 +312,7 @@ void main() {
});
}, overrides: <Type, Generator>{
Logger: () => StdoutLogger(
outputPreferences: outputPreferences,
outputPreferences: globals.outputPreferences,
terminal: AnsiTerminal(
stdio: mockStdio,
platform: const LocalPlatform(),
......@@ -332,7 +333,7 @@ void main() {
});
}, overrides: <Type, Generator>{
Logger: () => StdoutLogger(
outputPreferences: outputPreferences,
outputPreferences: globals.outputPreferences,
terminal: AnsiTerminal(
stdio: mockStdio,
platform: const LocalPlatform(),
......
......@@ -120,7 +120,7 @@ void testUsingContext(
OutputPreferences: () => OutputPreferences.test(),
Logger: () => BufferLogger(
terminal: globals.terminal,
outputPreferences: outputPreferences,
outputPreferences: globals.outputPreferences,
),
OperatingSystemUtils: () => FakeOperatingSystemUtils(),
PersistentToolState: () => buildPersistentToolState(globals.fs),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment