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