-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsoleLogs.cs
More file actions
154 lines (128 loc) · 4.89 KB
/
ConsoleLogs.cs
File metadata and controls
154 lines (128 loc) · 4.89 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
namespace ConsoleAddonLibary
{
public static class ConsoleLogs
{
public static ConsoleColor SystemColor { get; private set; }
public static ConsoleColor ErrorColor { get; private set; }
public static ConsoleColor InfoColor { get; private set; }
public const ConsoleColor DefaultSystemColor = ConsoleColor.Yellow;
public const ConsoleColor DefaultErrorColor = ConsoleColor.Red;
public const ConsoleColor DefaultInfoColor = ConsoleColor.Green;
static ConsoleLogs() { SetDefaultColors(); }
//The methods are responsible for displaying messages with a certain color of their type:
//SystemLog methods:
/// <summary>
/// Your text are used SystemColor.
/// </summary>
public static void SystemLog(string message)
{
PrintMessageWithColor(message, SystemColor);
}
/// <summary>
/// All text are used SystemColor. Use this method for complex log messages
/// </summary>
/// <param name="messages">A method that outputs several messages to the console</param>
public static void SystemLog(Action messages)
{
PrintMessageWithColor(messages, SystemColor);
}
//ErrorLogMethods:
//InfoLogMethods:
/// <summary>
/// Your text are used ErrorColor.
/// </summary>
public static void ErrorLog(string message)
{
PrintMessageWithColor(message, ErrorColor);
}
/// <summary>
/// All text are used ErrorColor. Use this method for complex log messages
/// </summary>
/// <param name="messages">A method that outputs several messages to the console</param>
public static void ErrorLog(Action messages)
{
PrintMessageWithColor(messages, ErrorColor);
}
//InfoLogMethods:
/// <summary>
/// Your text are used InfoColor.
/// </summary>
public static void InfoLog(string message)
{
PrintMessageWithColor(message, InfoColor);
}
/// <summary>
/// All text are used InfoColor. Use this method for complex log messages
/// </summary>
/// <param name="messages">A method that outputs several messages to the console</param>
public static void InfoLog(Action messages)
{
PrintMessageWithColor(messages, InfoColor);
}
//Methods for text color management:
public static void SetSystemColor(ConsoleColor color) { SystemColor = color; }
public static void SetErrorColor(ConsoleColor color) { ErrorColor = color; }
public static void SetInfoColor(ConsoleColor color) { InfoColor = color; }
public static void SetDefaultColors()
{
SystemColor = DefaultSystemColor;
ErrorColor = DefaultErrorColor;
InfoColor = DefaultInfoColor;
}
public static void PrintMessageWithColor(string message, ConsoleColor consoleColor)
{
ConsoleColor lastConsoleColor = Console.ForegroundColor;
Console.ForegroundColor = consoleColor;
Console.WriteLine(message);
Console.ForegroundColor = lastConsoleColor;
}
public static void PrintMessageWithColor(Action messages, ConsoleColor consoleColor)
{
Console.ForegroundColor = consoleColor;
messages.Invoke();
Console.ResetColor();
}
public static void GradualPrinting(string message, PrintingSpeed speed)
{
int printspeed = GetSpeed(speed);
foreach (var symbol in message)
{
Console.Write(symbol);
if (symbol == ' ')
{
Thread.Sleep(printspeed * 2);
}
else
{
Thread.Sleep(printspeed);
}
}
Console.WriteLine();
}
private static int GetSpeed(PrintingSpeed speed)
{
switch (speed)
{
case PrintingSpeed.low: return 200;
case PrintingSpeed.normal: return 100;
case PrintingSpeed.fast: return 60;
case PrintingSpeed.veryFast: return 30;
}
return 0;
}
public static void PrintSelected(Action messages)
{
ConsoleColor BGLastColor = Console.BackgroundColor;
Console.BackgroundColor = ConsoleColor.DarkCyan;
messages.Invoke();
Console.BackgroundColor = BGLastColor;
}
}
}
public enum PrintingSpeed
{
low,
normal,
fast,
veryFast
}