-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
124 lines (106 loc) · 3.78 KB
/
Program.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using Spectre.Console;
using Spectre.Console.Rendering;
namespace XorVisualization
{
class Program
{
class State
{
public bool A { get; set; }
public bool B { get; set; }
}
static void Main()
{
var simulationData = new[]
{
new State { A = false, B = false },
new State { A = false, B = true },
new State { A = true, B = false },
new State { A = true, B = true }
};
while (true)
{
foreach (var data in simulationData)
{
Line("XoR loop");
var xorValue = Xor(data.A, data.B);
Color Input1 = Color.Grey;
Color Input2 = Color.Grey;
Color resultColor = Color.Grey;
string Input1Text = "Off";
string Input2Text = "Off";
string resultText = "Off";
if (data.A)
{
Input1 = Color.Green;
Input1Text = "On ";
}
else
{
Input1 = Color.Red;
Input1Text = "Off";
}
if (data.B)
{
Input2 = Color.Green;
Input2Text = "ON ";
}
else
{
Input2 = Color.Red;
Input2Text = "Off";
}
if (xorValue)
{
resultColor = Color.Yellow;
resultText = "On ";
}
else
{
resultColor = Color.Grey;
resultText = "Off";
}
var items = new Grid()
.AddColumn(new GridColumn().NoWrap().PadRight(4))
.AddColumn(new GridColumn().NoWrap().PadRight(4))
.AddRow(
CreatePanel("Input1", BoxBorder.Double, Input1, Input1Text),
CreatePanel("Input2", BoxBorder.Double, Input2, Input2Text)
);
var result = CreatePanel("Result", BoxBorder.Double, resultColor, resultText);
AnsiConsole.Write(
new Padder(
new Columns(items).PadRight(2),
new Padding(2, 0, 0, 0)));
Console.WriteLine();
AnsiConsole.Write(
new Padder(
new Columns(result).PadRight(2),
new Padding(2, 0, 0, 0)));
// Toggle the inputs for the next iteration
var temp = data.A;
data.A = xorValue;
data.B = temp;
Thread.Sleep(1000);
Console.Clear();
}
}
}
static bool Xor(bool a, bool b)
{
return a ^ b;
}
static IRenderable CreatePanel(string name, BoxBorder border, Color color, string text)
{
return new Panel($"[{color.ToString()}]--{text}--[/]")
.Header($" [{color}]{name}[/] ", Justify.Center)
.Border(border)
.BorderStyle(color);
}
private static void Line(string title)
{
AnsiConsole.WriteLine($"----------{title}----------");
AnsiConsole.WriteLine();
}
}
}