-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvancedConsole.cs
More file actions
179 lines (178 loc) · 4.8 KB
/
AdvancedConsole.cs
File metadata and controls
179 lines (178 loc) · 4.8 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
namespace AdvancedConsole
{
public delegate void KeyEventHandler(AdvancedConsole context, ConsoleKeyInfo k);
public delegate void InputEventHandler(AdvancedConsole context, string s);
public delegate void Something(AdvancedConsole context);
public class AdvancedConsole
{
private Stack<ConsoleColors> m_historyColors;
public AdvancedConsole()
{
m_historyColors = new Stack<ConsoleColors>();
}
~AdvancedConsole()
{
try
{
while(true)
{
m_historyColors.Pop().Apply();
}
} catch(Exception)
{
//
}
}
public AdvancedConsole SetBackground(ConsoleColor back)
{
m_historyColors.Push(new ConsoleColors());
Console.BackgroundColor = back;
return this;
}
public AdvancedConsole SetForeground(ConsoleColor fore)
{
m_historyColors.Push(new ConsoleColors());
Console.ForegroundColor = fore;
return this;
}
public AdvancedConsole RestoreColors()
{
m_historyColors.Pop().Apply();
return this;
}
public AdvancedConsole RestoreBack()
{
m_historyColors.Pop().ApplyBackgroundColor();
return this;
}
public AdvancedConsole RestoreFore()
{
m_historyColors.Pop().ApplyForegroundCOlor();
return this;
}
public AdvancedConsole Out(object any)
{
Console.Write(any);
return this;
}
public AdvancedConsole Out(string any)
{
Console.Write(any);
return this;
}
public AdvancedConsole Out(int any)
{
Console.Write(any);
return this;
}
public AdvancedConsole Out(long any)
{
Console.Write(any);
return this;
}
public AdvancedConsole Out(float any)
{
Console.Write(any);
return this;
}
public AdvancedConsole Out(double any)
{
Console.Write(any);
return this;
}
public AdvancedConsole Out(char any)
{
Console.Write(any);
return this;
}
public AdvancedConsole Out(byte any)
{
Console.Write(any);
return this;
}
public AdvancedConsole Out(bool any)
{
Console.Write(any);
return this;
}
public AdvancedConsole In(InputEventHandler handler)
{
handler(this, Console.ReadLine());
return this;
}
public AdvancedConsole WaitForKey(ConsoleKey key)
{
while (Console.ReadKey(true).Key != key) ;
return this;
}
public AdvancedConsole WaitForKey(KeyEventHandler handler)
{
handler(this, Console.ReadKey(true));
return this;
}
public AdvancedConsole WaitForKeys(params ConsoleKey[] keys)
{
bool jmp_out = false;
while(!jmp_out)
{
ConsoleKeyInfo keyInfo = Console.ReadKey(true);
foreach(ConsoleKey k in keys)
{
if(k == keyInfo.Key)
{
jmp_out = true;
}
}
}
return this;
}
public AdvancedConsole MoveCursorTo(int x, int y)
{
Console.CursorTop = y;
Console.CursorLeft = x;
return this;
}
public AdvancedConsole CursorSize(int s)
{
Console.CursorSize = s;
return this;
}
public AdvancedConsole HideCursor()
{
Console.CursorVisible = false;
return this;
}
public AdvancedConsole ShowCursor()
{
Console.CursorVisible = true;
return this;
}
public AdvancedConsole ToggleCursorVisible()
{
Console.CursorVisible = !Console.CursorVisible;
return this;
}
public AdvancedConsole EndLine()
{
Console.WriteLine();
return this;
}
public AdvancedConsole Execute(Something fun)
{
fun(this);
return this;
}
public AdvancedConsole Outf(string s, params object[] cons)
{
Console.Write(s, cons);
return this;
}
public AdvancedConsole Clear()
{
Console.Clear();
return this;
}
}
}