InputElement.cs
829 Bytes
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
using System;
namespace Flicker
{
public class InputElement : Element
{
public InputElement(out string result, string label)
: base(0, 0, 0, 0)
{
Visible = false;
Console.Clear();
Tools.Console.Fill(0, 1, Console.BufferWidth, Console.BufferHeight - 2, '\u2588');
Tools.Console.WriteAt(0, 0, label);
result = Console.ReadLine();
}
}
public class InputElement<T> : Element
{
public InputElement(out T result, string label)
: base(0, 0, 0, 0)
{
Visible = false;
Console.Clear();
Tools.Console.Fill(0, 1, Console.BufferWidth, Console.BufferHeight - 2, '\u2588');
Tools.Console.WriteAt(0, 0, label);
var input = Console.ReadLine();
try
{
result = (T)Convert.ChangeType(input, typeof(T));
}
catch
{
// Fail silently
result = default(T);
}
}
}
}