Merged in settingsmanager_bugfix (pull request #319)
RTM: Settingsmanager : handle more than 9 users
This commit is contained in:
commit
0ddf145ef9
1 file changed
+18
-7
@@ -25,19 +25,30 @@ namespace bts.test {
|
||||
public static T prompt<T>(string prompt, params T[] options) {
|
||||
return ConsoleEx.prompt(prompt, (IEnumerable<T>)options);
|
||||
}
|
||||
private static (bool,int) read_small_number() {
|
||||
var key = Console.ReadKey();
|
||||
return (Int32.TryParse(key.KeyChar.ToString(), out int value), value);
|
||||
}
|
||||
private static (bool,int) read_big_number() {
|
||||
var line = Console.ReadLine();
|
||||
return (Int32.TryParse(line, out int value), value);
|
||||
}
|
||||
private static int read_number(int max) {
|
||||
do {
|
||||
(var success,var value) = max > 9 ? read_big_number() : read_small_number();
|
||||
if (success && value >= 0 && value <= max) {
|
||||
return value;
|
||||
}
|
||||
}while(true);
|
||||
}
|
||||
|
||||
public static T prompt<T>(string prompt, IEnumerable<T> options) {
|
||||
WriteLine(prompt, ConsoleColor.Yellow);
|
||||
for (int x = 0; x < options.Count(); ++x) {
|
||||
Write($"{x}. ", ConsoleColor.Yellow);
|
||||
WriteLine(options.ElementAt(x).ToString());
|
||||
}
|
||||
int response = 0;
|
||||
bool success = false;
|
||||
while(!success) {
|
||||
var key = Console.ReadKey();
|
||||
success = Int32.TryParse(key.KeyChar.ToString(), out response);
|
||||
if (response > options.Count()) success = false;
|
||||
}
|
||||
int response = read_number(options.Count());
|
||||
var value = options.ElementAt(response);
|
||||
Console.WriteLine(" >> " + value.ToString());
|
||||
Console.WriteLine();
|
||||
|
||||
Reference in new issue
Block a user