Commit 04aeef84 authored by xster's avatar xster Committed by GitHub

Let iOS flutter run auto-sign default to first profile (#10181)

* Let run default to first profile

* fix

* review notes
parent 437d4ab1
......@@ -90,16 +90,29 @@ class AnsiTerminal {
/// Prompts the user to input a chraracter within the accepted list.
/// Reprompts if inputted character is not in the list.
///
/// `prompt` is the text displayed prior to waiting for user input each time.
/// `defaultChoiceIndex`, if given, will be the character in `acceptedCharacters`
/// in the index given if the user presses enter without any key input.
/// `displayAcceptedCharacters` prints also the accepted keys next to the `prompt` if true.
///
/// Throws a [TimeoutException] if a `timeout` is provided and its duration
/// expired without user input. Duration resets per key press.
Future<String> promptForCharInput(
List<String> acceptedCharacters, {
String prompt,
int defaultChoiceIndex,
bool displayAcceptedCharacters: true,
Duration timeout,
}) async {
assert(acceptedCharacters != null);
assert(acceptedCharacters.isNotEmpty);
List<String> charactersToDisplay = acceptedCharacters;
if (defaultChoiceIndex != null) {
assert(defaultChoiceIndex >= 0 && defaultChoiceIndex < acceptedCharacters.length);
charactersToDisplay = new List<String>.from(charactersToDisplay);
charactersToDisplay[defaultChoiceIndex] = bolden(charactersToDisplay[defaultChoiceIndex]);
acceptedCharacters.add('\n');
}
String choice;
singleCharMode = true;
while(
......@@ -110,7 +123,7 @@ class AnsiTerminal {
if (isNotEmpty(prompt)) {
printStatus(prompt, emphasis: true, newline: false);
if (displayAcceptedCharacters)
printStatus(' [${acceptedCharacters.join("|")}]', newline: false);
printStatus(' [${charactersToDisplay.join("|")}]', newline: false);
printStatus(': ', emphasis: true, newline: false);
}
Future<String> inputFuture = onCharInput.first;
......@@ -120,6 +133,8 @@ class AnsiTerminal {
printStatus(choice);
}
singleCharMode = false;
if (defaultChoiceIndex != null && choice == '\n')
choice = acceptedCharacters[defaultChoiceIndex];
return choice;
}
}
......
......@@ -153,6 +153,7 @@ Future<String> _chooseSigningIdentity(List<String> validCodeSigningIdentities) a
..add('a'),
prompt: 'Please select a certificate for code signing',
displayAcceptedCharacters: true,
defaultChoiceIndex: 0, // Just pressing enter chooses the first one.
);
if (choice == 'a')
......
......@@ -21,6 +21,7 @@ void main() {
testUsingContext('character prompt', () async {
mockStdInStream = new Stream<String>.fromFutures(<Future<String>>[
new Future<String>.value('d'), // Not in accepted list.
new Future<String>.value('\n'), // Not in accepted list
new Future<String>.value('b'),
]).asBroadcastStream();
final String choice =
......@@ -29,10 +30,32 @@ void main() {
prompt: 'Please choose something',
);
expect(choice, 'b');
expect(testLogger.statusText, '''
Please choose something [a|b|c]: d
Please choose something [a|b|c]: 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 = new Stream<String>.fromFutures(<Future<String>>[
new 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'
);
});
});
}
......
......@@ -189,7 +189,7 @@ void main() {
expect(
testLogger.statusText,
contains('Please select a certificate for code signing [1|2|3|a]: 3')
contains('Please select a certificate for code signing [<bold>1</bold>|2|3|a]: 3')
);
expect(
testLogger.statusText,
......@@ -228,6 +228,9 @@ class MockStdIn extends Mock implements IOSink {}
Stream<String> mockTerminalStdInStream;
class TestTerminal extends AnsiTerminal {
@override
String bolden(String message) => '<bold>$message</bold>';
@override
Stream<String> get onCharInput {
return mockTerminalStdInStream;
......
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