Browse Source

Add color to console output

pull/1926/head
duckdoom5 4 months ago
parent
commit
6c8002b844
  1. 14
      src/Core/Diagnostics.cs

14
src/Core/Diagnostics.cs

@ -112,13 +112,25 @@ namespace CppSharp
Level = DiagnosticKind.Message; Level = DiagnosticKind.Message;
} }
private string GetColorForDiagKind(DiagnosticKind kind) =>
kind switch
{
DiagnosticKind.Debug => null,
DiagnosticKind.Message => null,
DiagnosticKind.Warning => "\u001b[33m", // yellow
DiagnosticKind.Error => "\u001b[91m", // red
_ => null
};
public void Emit(DiagnosticInfo info) public void Emit(DiagnosticInfo info)
{ {
if (info.Kind < Level) if (info.Kind < Level)
return; return;
var currentIndentation = Indents.Sum(); var currentIndentation = Indents.Sum();
var message = new string(' ', currentIndentation) + info.Message; var colorString = GetColorForDiagKind(info.Kind);
var colorReset = colorString == null ? null : "\u001b[0m";
var message = $"{new string(' ', currentIndentation)}{colorString}{info.Message}{colorReset}";
if (info.Kind == DiagnosticKind.Error) if (info.Kind == DiagnosticKind.Error)
{ {

Loading…
Cancel
Save