-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.cs
53 lines (49 loc) · 1.13 KB
/
Menu.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
namespace TohoLauncher;
public class Menu
{
public static string Select(string[] options)
{
if (!options.Any())
throw new ArgumentException("No options to select from");
int position = 0;
var length = options.Length;
while (true)
{
Draw(options, position);
var key = Console.ReadKey().Key;
switch (key)
{
case ConsoleKey.Escape:
Console.Clear();
return string.Empty;
case ConsoleKey.Z:
case ConsoleKey.Enter:
Console.Clear();
return options[position];
case ConsoleKey.UpArrow:
position = position - 1 < 0 ? length - 1 : position - 1;
break;
case ConsoleKey.DownArrow:
position = position + 1 >= length ? 0 : position + 1;
break;
default:
break;
}
}
}
private static void Draw(string[] options, int position)
{
Console.Clear();
for (int i = 0; i < options.Length; i++)
{
if (i == position)
{
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
}
Console.WriteLine(options[i]);
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.White;
}
}
}