Skip to content

Commit 6c8002b

Browse files
committed
Add color to console output
1 parent 6f5a46d commit 6c8002b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Core/Diagnostics.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,25 @@ public ConsoleDiagnostics()
112112
Level = DiagnosticKind.Message;
113113
}
114114

115+
private string GetColorForDiagKind(DiagnosticKind kind) =>
116+
kind switch
117+
{
118+
DiagnosticKind.Debug => null,
119+
DiagnosticKind.Message => null,
120+
DiagnosticKind.Warning => "\u001b[33m", // yellow
121+
DiagnosticKind.Error => "\u001b[91m", // red
122+
_ => null
123+
};
124+
115125
public void Emit(DiagnosticInfo info)
116126
{
117127
if (info.Kind < Level)
118128
return;
119129

120130
var currentIndentation = Indents.Sum();
121-
var message = new string(' ', currentIndentation) + info.Message;
131+
var colorString = GetColorForDiagKind(info.Kind);
132+
var colorReset = colorString == null ? null : "\u001b[0m";
133+
var message = $"{new string(' ', currentIndentation)}{colorString}{info.Message}{colorReset}";
122134

123135
if (info.Kind == DiagnosticKind.Error)
124136
{

0 commit comments

Comments
 (0)