forked from pauldotknopf/dotnet-buildary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.cs
62 lines (53 loc) · 2.19 KB
/
Log.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
using System;
using System.Collections.Generic;
namespace Build.Buildary
{
public static class Log
{
internal static readonly Dictionary<MessageType, Func<bool, string>> Colors = new Dictionary<MessageType, Func<bool, string>>
{
[MessageType.Success] = Green,
[MessageType.Info] = Blue,
[MessageType.Warning] = BrightYellow,
[MessageType.Failure] = BrightRed,
};
internal enum MessageType
{
Success,
Info,
Warning,
Failure,
}
private static void WriteMessage(string message, MessageType type)
{
Console.WriteLine(Message(type, message));
}
public static void Success(string message)
{
WriteMessage(message, MessageType.Success);
}
public static void Info(string message)
{
WriteMessage(message, MessageType.Info);
}
public static void Warning(string message)
{
WriteMessage(message, MessageType.Warning);
}
public static void Failure(string message)
{
WriteMessage(message, MessageType.Failure);
}
private static string Default (bool color) => color ? "\x1b[0m" : "";
private static string Green (bool color) => color ? "\x1b[32m" : "";
private static string Blue (bool color) => color ? "\x1b[34m" : "";
private static string Magenta (bool color) => color ? "\x1b[35m" : "";
private static string Cyan (bool color) => color ? "\x1b[36m" : "";
private static string White (bool color) => color ? "\x1b[37m" : "";
private static string BrightRed (bool color) => color ? "\x1b[91m" : "";
private static string BrightYellow (bool color) => color ? "\x1b[93m" : "";
private static string BrightMagenta (bool color) => color ? "\x1b[95m" : "";
internal static string Message(MessageType messageType, string text, bool color = true) =>
$"{Colors[messageType](color)}{text}{Default(color)}";
}
}