X-Git-Url: http://git.sourceforge.jp/view?p=applistation%2FAppliStation.git;a=blobdiff_plain;f=all-get%2FUtil.cs;h=1f39428ec116b2fa971750e7f97c3e131e286c53;hp=de827842002244c4e6bc925f2aac217fe0d3a329;hb=14f8a3160ea7b7b37acbf5188b7b33eb5bfbaf18;hpb=d77e489a312afb2db4612269f7275c6ac1fd17cc diff --git a/all-get/Util.cs b/all-get/Util.cs index de82784..1f39428 100644 --- a/all-get/Util.cs +++ b/all-get/Util.cs @@ -5,20 +5,22 @@ namespace AllGet sealed class Util { - public static bool Confirm(string msg, bool defaultSelection) + public static char Query(string msg, string selections, char defaultSelection) { - Console.Write(msg); - string response = Console.ReadLine(); - - switch (response.ToLower()) - { - case "y": - return true; - case "n": - return false; - default: - return defaultSelection; + int resNum = -1; + while (resNum < 0) { + Console.Write(msg); + string response = Console.ReadLine(); + response = response.Trim().ToLower(); + if (response.Length < 1) return defaultSelection; + resNum = selections.ToLower().IndexOf(response[0]); } + return selections[resNum]; + } + + public static bool Confirm(string msg, bool defaultSelection) + { + return Query(msg, "yn", defaultSelection? 'y' : 'n') == 'y'; } } }