Skip to content

Commit

Permalink
Revert "[flutter_tools] inject output preferences at the top level (#…
Browse files Browse the repository at this point in the history
…58875)" (#59197)

This reverts commit dca6320.
  • Loading branch information
jmagman committed Jun 10, 2020
1 parent 618108b commit 75fd73d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 167 deletions.
8 changes: 1 addition & 7 deletions packages/flutter_tools/lib/executable.dart
Expand Up @@ -11,7 +11,6 @@ import 'src/base/template.dart';
// The build_runner code generation is provided here to make it easier to
// avoid introducing the dependency into google3. Not all build* packages
// are synced internally.
import 'src/base/terminal.dart';
import 'src/build_runner/build_runner.dart';
import 'src/build_runner/mustache_template.dart';
import 'src/build_runner/resident_web_runner.dart';
Expand Down Expand Up @@ -136,11 +135,6 @@ Future<void> main(List<String> args) async {
stdio: globals.stdio,
terminal: globals.terminal,
outputPreferences: globals.outputPreferences,
)),
OutputPreferences: () => OutputPreferences.fromArguments(
args,
stdio: globals.stdio,
userMessages: globals.userMessages,
),
))
});
}
40 changes: 0 additions & 40 deletions packages/flutter_tools/lib/src/base/terminal.dart
Expand Up @@ -8,12 +8,9 @@ import 'package:meta/meta.dart';

import '../convert.dart';
import '../globals.dart' as globals;
import 'common.dart';
import 'io.dart' as io;
import 'io.dart';
import 'logger.dart';
import 'platform.dart';
import 'user_messages.dart';

enum TerminalColor {
red,
Expand Down Expand Up @@ -50,43 +47,6 @@ class OutputPreferences {
OutputPreferences.test({this.wrapText = false, int wrapColumn = kDefaultTerminalColumns, this.showColor = false})
: _overrideWrapColumn = wrapColumn;

/// Create an [OutputPreferences] from a list of command line arguments.
static OutputPreferences fromArguments(List<String> topLevelResults, {
@required UserMessages userMessages,
@required Stdio stdio,
}) {
// Don't set wrapColumns unless the user said to: if it's set, then all
// wrapping will occur at this width explicitly, and won't adapt if the
// terminal size changes during a run.
int wrapColumn;
final String rawWrapColumn = topLevelResults
.firstWhere((String line) => line.startsWith('--wrap-column='), orElse: () => null);
if (rawWrapColumn != null) {
final List<String> parts = rawWrapColumn.split('=');
if (parts.length > 1) {
wrapColumn = int.tryParse(parts[1]);
}
if (wrapColumn == null) {
throwToolExit(userMessages.runnerWrapColumnInvalid(rawWrapColumn));
}
}

// If we're not writing to a terminal with a defined width, then don't wrap
// anything, unless the user explicitly said to.
final bool useWrapping = !topLevelResults.contains('--no-wrap');

// If no default width was provided, first default to the terminal width. If
// that is null, use `kDefaultTerminalColumns`.
if (useWrapping && wrapColumn == null) {
wrapColumn = stdio.terminalColumns ?? kDefaultTerminalColumns;
}
return OutputPreferences(
wrapText: useWrapping,
showColor: !topLevelResults.contains('--no-color'),
wrapColumn: wrapColumn,
);
}

/// If [wrapText] is true, then any text sent to the context's [Logger]
/// instance (e.g. from the [printError] or [printStatus] functions) will be
/// wrapped (newlines added between words) to be no longer than the
Expand Down
27 changes: 27 additions & 0 deletions packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
Expand Up @@ -15,6 +15,7 @@ import '../artifacts.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../base/file_system.dart';
import '../base/terminal.dart';
import '../base/user_messages.dart';
import '../base/utils.dart';
import '../cache.dart';
Expand Down Expand Up @@ -234,6 +235,32 @@ class FlutterCommandRunner extends CommandRunner<void> {
Future<void> runCommand(ArgResults topLevelResults) async {
final Map<Type, dynamic> contextOverrides = <Type, dynamic>{};

// Don't set wrapColumns unless the user said to: if it's set, then all
// wrapping will occur at this width explicitly, and won't adapt if the
// terminal size changes during a run.
int wrapColumn;
if (topLevelResults.wasParsed('wrap-column')) {
try {
wrapColumn = int.parse(topLevelResults['wrap-column'] as String);
if (wrapColumn < 0) {
throwToolExit(userMessages.runnerWrapColumnInvalid(topLevelResults['wrap-column']));
}
} on FormatException {
throwToolExit(userMessages.runnerWrapColumnParseError(topLevelResults['wrap-column']));
}
}

// If we're not writing to a terminal with a defined width, then don't wrap
// anything, unless the user explicitly said to.
final bool useWrapping = topLevelResults.wasParsed('wrap')
? topLevelResults['wrap'] as bool
: globals.stdio.terminalColumns != null && topLevelResults['wrap'] as bool;
contextOverrides[OutputPreferences] = OutputPreferences(
wrapText: useWrapping,
showColor: topLevelResults['color'] as bool,
wrapColumn: wrapColumn,
);

if (topLevelResults['show-test-device'] as bool ||
topLevelResults['device-id'] == FlutterTesterDevices.kTesterDeviceId) {
FlutterTesterDevices.showFlutterTesterDevice = true;
Expand Down
120 changes: 0 additions & 120 deletions packages/flutter_tools/test/general.shard/output_preferences_test.dart

This file was deleted.

Expand Up @@ -239,6 +239,52 @@ void main() {
Platform: () => platform,
}, initializeFlutterRoot: false);
});

group('wrapping', () {
testUsingContext('checks that output wrapping is turned on when writing to a terminal', () async {
final FakeFlutterCommand fakeCommand = FakeFlutterCommand();
runner.addCommand(fakeCommand);
await runner.run(<String>['fake']);
expect(fakeCommand.preferences.wrapText, isTrue);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Stdio: () => FakeStdio(hasFakeTerminal: true),
}, initializeFlutterRoot: false);

testUsingContext('checks that output wrapping is turned off when not writing to a terminal', () async {
final FakeFlutterCommand fakeCommand = FakeFlutterCommand();
runner.addCommand(fakeCommand);
await runner.run(<String>['fake']);
expect(fakeCommand.preferences.wrapText, isFalse);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Stdio: () => FakeStdio(hasFakeTerminal: false),
}, initializeFlutterRoot: false);

testUsingContext('checks that output wrapping is turned off when set on the command line and writing to a terminal', () async {
final FakeFlutterCommand fakeCommand = FakeFlutterCommand();
runner.addCommand(fakeCommand);
await runner.run(<String>['--no-wrap', 'fake']);
expect(fakeCommand.preferences.wrapText, isFalse);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Stdio: () => FakeStdio(hasFakeTerminal: true),
}, initializeFlutterRoot: false);

testUsingContext('checks that output wrapping is turned on when set on the command line, but not writing to a terminal', () async {
final FakeFlutterCommand fakeCommand = FakeFlutterCommand();
runner.addCommand(fakeCommand);
await runner.run(<String>['--wrap', 'fake']);
expect(fakeCommand.preferences.wrapText, isTrue);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),
Stdio: () => FakeStdio(hasFakeTerminal: false),
}, initializeFlutterRoot: false);
});
});
}
class MockProcessManager extends Mock implements ProcessManager {}
Expand Down

0 comments on commit 75fd73d

Please sign in to comment.