-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.cs
More file actions
56 lines (45 loc) · 1.66 KB
/
Copy pathInput.cs
File metadata and controls
56 lines (45 loc) · 1.66 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplicationBuilder
{
static class Input
{
public static string Read()
{
string text = Console.ReadLine();
return text;
}
public static string Read(string fieldInfo, ConsoleColor fg = ConsoleColor.Gray, ConsoleColor bg = ConsoleColor.Black)
{
Output.Write(fieldInfo, fg, bg);
return Read();
}
public static string ReadPassword(string fieldInfo = "", char passwordChar = '*', ConsoleColor fg = ConsoleColor.Gray, ConsoleColor bg = ConsoleColor.Black)
{
string password = string.Empty;
ConsoleKeyInfo input;
Output.Write(fieldInfo, fg, bg);
while (true)
{
input = Console.ReadKey(true);
if (input.Key is ConsoleKey.Enter) break;
else if (input.Key is ConsoleKey.Backspace)
{
if (string.IsNullOrEmpty(password)) continue;
password = password.Remove(password.Length - 1);
Console.SetCursorPosition($"{fieldInfo}{password}".Length, Console.CursorTop);
Console.Write(" ");
Console.SetCursorPosition($"{fieldInfo}{password}".Length, Console.CursorTop);
continue;
}
password += input.KeyChar.ToString();
Console.Write(passwordChar);
}
Console.WriteLine();
return password;
}
}
}