-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.cs
83 lines (78 loc) · 2.13 KB
/
Utility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public static class Utility
{
public static string GetSecretInput(string prompt)
{
bool isPrompt = true;
string asterics = "";
StringBuilder input = new StringBuilder();
while (true)
{
if (isPrompt)
Console.WriteLine(prompt);
isPrompt = false;
ConsoleKeyInfo inputkey = Console.ReadKey(true);
if (inputkey.Key == ConsoleKey.Enter)
{
if (input.Length == 6)
{
break;
}
else
{
PrintError("\nPlease enter 6 digits.", false);
isPrompt = true;
input.Clear();
continue;
}
}
if (inputkey.Key == ConsoleKey.Backspace && input.Length > 0)
{
input.Remove(input.Length - 1, 1);
}
else if (inputkey.Key != ConsoleKey.Backspace)
{
input.Append(inputkey.KeyChar);
Console.Write(asterics + "*");
}
}
return input.ToString();
}
public static void PrintError(string message, bool sucess = true)
{
if (sucess)
{
Console.ForegroundColor = ConsoleColor.Yellow;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
}
Console.WriteLine(message);
Console.ResetColor();
PressEnterToContinue();
}
public static string GetUserInput(string Prompt)
{
Console.WriteLine($"Enter {Prompt}");
return Console.ReadLine();
}
public static void PressEnterToContinue()
{
Console.WriteLine("\n\n Press Enter TO continue");
Console.ReadLine();
}
public static void PrintDotAnimation(int timer = 10)
{
for (int i = 0; i < timer; i++)
{
Console.Write(".");
Thread.Sleep(200);
}
Console.Clear();
}
}