Добавленно TUI
This commit is contained in:
45
TUI/InputHelper.cs
Normal file
45
TUI/InputHelper.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
|
||||
namespace su.divan2000.UtilsTUI
|
||||
{
|
||||
public static class InputHelper
|
||||
{
|
||||
public static double AskDouble(string prompt)
|
||||
{
|
||||
double val;
|
||||
while (true)
|
||||
{
|
||||
Console.Write(prompt);
|
||||
if (double.TryParse(Console.ReadLine(), out val))
|
||||
return val;
|
||||
|
||||
Console.WriteLine("Некорректный ввод. Введите число в формате 1.0, 2.5 и т.д.");
|
||||
}
|
||||
}
|
||||
|
||||
public static int AskInt(string prompt)
|
||||
{
|
||||
int val;
|
||||
while (true)
|
||||
{
|
||||
Console.Write(prompt);
|
||||
if (int.TryParse(Console.ReadLine(), out val))
|
||||
return val;
|
||||
|
||||
Console.WriteLine("Некорректный ввод. Введите целое число.");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AskYesNo(string prompt)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Console.Write(prompt);
|
||||
string? s = Console.ReadLine()?.Trim().ToLower();
|
||||
if (s == "да") return true;
|
||||
if (s == "нет") return false;
|
||||
Console.WriteLine("Введите 'да' или 'нет'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user