mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This turns on text wrapping for usage messages and status messages. When on a terminal, wraps to the width of the terminal. When writing to a non-terminal, wrap lines at a default column width (currently defined to be 100 chars). If --no-wrap is specified, then no wrapping occurs. If --wrap-column is specified, wraps to that column (if --wrap is on). Adds ANSI color to the doctor and analysis output on terminals. This is in this PR with the wrapping, since wrapping needs to know how to count visible characters in the presence of ANSI sequences. (This is just one more step towards re-implementing all of Curses for Flutter. :-)) Will not print ANSI sequences when sent to a non-terminal, or of --no-color is specified. Fixes ANSI color and bold sequences so that they can be combined (bold, colored text), and a small bug in indentation calculation for wrapping. Since wrapping is now turned on, also removed many redundant '\n's in the code.
85 lines
2.7 KiB
Dart
85 lines
2.7 KiB
Dart
// Copyright 2017 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter_tools/src/base/platform.dart';
|
|
import 'package:flutter_tools/src/base/terminal.dart';
|
|
import 'package:flutter_tools/src/globals.dart';
|
|
|
|
import '../src/common.dart';
|
|
import '../src/context.dart';
|
|
|
|
void main() {
|
|
group('output preferences', () {
|
|
testUsingContext('can wrap output', () async {
|
|
printStatus('0123456789' * 8);
|
|
expect(testLogger.statusText, equals(('0123456789' * 4 + '\n') * 2));
|
|
}, overrides: <Type, Generator>{
|
|
OutputPreferences: () => OutputPreferences(wrapText: true, wrapColumn: 40),
|
|
});
|
|
|
|
testUsingContext('can turn off wrapping', () async {
|
|
final String testString = '0123456789' * 20;
|
|
printStatus(testString);
|
|
expect(testLogger.statusText, equals('$testString\n'));
|
|
}, overrides: <Type, Generator>{
|
|
Platform: () => FakePlatform()..stdoutSupportsAnsi = true,
|
|
OutputPreferences: () => OutputPreferences(wrapText: false),
|
|
});
|
|
});
|
|
group('character input prompt', () {
|
|
AnsiTerminal terminalUnderTest;
|
|
|
|
setUp(() {
|
|
terminalUnderTest = TestTerminal();
|
|
});
|
|
|
|
testUsingContext('character prompt', () async {
|
|
mockStdInStream = Stream<String>.fromFutures(<Future<String>>[
|
|
Future<String>.value('d'), // Not in accepted list.
|
|
Future<String>.value('\n'), // Not in accepted list
|
|
Future<String>.value('b'),
|
|
]).asBroadcastStream();
|
|
final String choice = await terminalUnderTest.promptForCharInput(
|
|
<String>['a', 'b', 'c'],
|
|
prompt: 'Please choose something',
|
|
);
|
|
expect(choice, 'b');
|
|
expect(
|
|
testLogger.statusText,
|
|
'Please choose something [a|b|c]: d\n'
|
|
'Please choose something [a|b|c]: \n'
|
|
'\n'
|
|
'Please choose something [a|b|c]: b\n');
|
|
});
|
|
|
|
testUsingContext('default character choice without displayAcceptedCharacters', () async {
|
|
mockStdInStream = Stream<String>.fromFutures(<Future<String>>[
|
|
Future<String>.value('\n'), // Not in accepted list
|
|
]).asBroadcastStream();
|
|
final String choice = await terminalUnderTest.promptForCharInput(
|
|
<String>['a', 'b', 'c'],
|
|
prompt: 'Please choose something',
|
|
displayAcceptedCharacters: false,
|
|
defaultChoiceIndex: 1, // which is b.
|
|
);
|
|
expect(choice, 'b');
|
|
expect(
|
|
testLogger.statusText,
|
|
'Please choose something: \n'
|
|
'\n');
|
|
});
|
|
});
|
|
}
|
|
|
|
Stream<String> mockStdInStream;
|
|
|
|
class TestTerminal extends AnsiTerminal {
|
|
@override
|
|
Stream<String> get onCharInput {
|
|
return mockStdInStream;
|
|
}
|
|
}
|