[flutter_tools] flutter run should allow exit when make choose for devices. (#64403)

This commit is contained in:
includecmath
2020-09-03 08:30:04 +08:00
committed by GitHub
parent 0b4dad6553
commit 6d46ff7e9b
4 changed files with 49 additions and 10 deletions

View File

@@ -285,6 +285,7 @@ class AnsiTerminal implements Terminal {
if (displayAcceptedCharacters) {
logger.printStatus(' [${charactersToDisplay.join("|")}]', newline: false);
}
// prompt ends with ': '
logger.printStatus(': ', emphasis: true, newline: false);
}
choice = await keystrokes.first;

View File

@@ -256,7 +256,7 @@ class UserMessages {
'Found $count devices with name or id matching $deviceId:';
String get flutterMultipleDevicesFound => 'Multiple devices found:';
String flutterChooseDevice(int option, String name, String deviceId) => '[$option]: $name ($deviceId)';
String get flutterChooseOne => 'Please choose one:';
String get flutterChooseOne => 'Please choose one (To quit, press "q/Q")';
String get flutterSpecifyDeviceWithAllOption =>
'More than one device connected; please specify a device with '
"the '-d <deviceId>' flag, or use '-d all' to act on all devices.";

View File

@@ -14,6 +14,7 @@ import 'android/android_sdk.dart';
import 'android/android_workflow.dart';
import 'application_package.dart';
import 'artifacts.dart';
import 'base/common.dart';
import 'base/config.dart';
import 'base/context.dart';
import 'base/dds.dart';
@@ -283,6 +284,9 @@ abstract class DeviceManager {
Future<Device> _chooseOneOfAvailableDevices(List<Device> devices) async {
_displayDeviceOptions(devices);
final String userInput = await _readUserInput(devices.length);
if (userInput.toLowerCase() == 'q') {
throwToolExit('');
}
return devices[int.parse(userInput)];
}
@@ -297,7 +301,8 @@ abstract class DeviceManager {
Future<String> _readUserInput(int deviceCount) async {
globals.terminal.usesTerminalUi = true;
final String result = await globals.terminal.promptForCharInput(
<String>[ for (int i = 0; i < deviceCount; i++) '$i' ],
<String>[ for (int i = 0; i < deviceCount; i++) '$i', 'q', 'Q'],
displayAcceptedCharacters: false,
logger: globals.logger,
prompt: userMessages.flutterChooseOne);
return result;