Skip to content

Commit

Permalink
Fix build breaks from Cathode update.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp committed Jan 1, 2024
1 parent c087e5f commit 38b8c83
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
24 changes: 11 additions & 13 deletions src/benchmarks/CelerityBenchmarkLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ internal sealed class CelerityBenchmarkLogger : ILogger

private static readonly bool _interactive = Terminal.StandardOut.IsInteractive;

private static readonly ImmutableDictionary<LogKind, (byte R, byte G, byte B)> _colors =
new Dictionary<LogKind, (byte, byte, byte)>
private static readonly ImmutableDictionary<LogKind, Color> _colors =
new Dictionary<LogKind, Color>
{
[LogKind.Default] = (135, 135, 175),
[LogKind.Help] = (175, 95, 0),
[LogKind.Header] = (175, 255, 0),
[LogKind.Result] = (135, 135, 255),
[LogKind.Statistic] = (175, 175, 255),
[LogKind.Info] = (255, 255, 255),
[LogKind.Error] = (255, 0, 0),
[LogKind.Hint] = (0, 175, 135),
[LogKind.Default] = Color.FromArgb(135, 135, 175),
[LogKind.Help] = Color.FromArgb(175, 95, 0),
[LogKind.Header] = Color.FromArgb(175, 255, 0),
[LogKind.Result] = Color.FromArgb(135, 135, 255),
[LogKind.Statistic] = Color.FromArgb(175, 175, 255),
[LogKind.Info] = Color.FromArgb(255, 255, 255),
[LogKind.Error] = Color.FromArgb(255, 0, 0),
[LogKind.Hint] = Color.FromArgb(0, 175, 135),
}.ToImmutableDictionary();

private CelerityBenchmarkLogger()
Expand All @@ -29,15 +29,13 @@ private CelerityBenchmarkLogger()

private void Write(LogKind kind, string text, bool eol)
{
var (r, g, b) = _colors[kind];

static void WriteControl(string sequence)
{
if (_interactive)
Terminal.Out(sequence);
}

WriteControl(ControlSequences.SetForegroundColor(r, g, b));
WriteControl(ControlSequences.SetForegroundColor(_colors[kind]));
Terminal.Out(text);
WriteControl(ControlSequences.ResetAttributes());

Expand Down
19 changes: 7 additions & 12 deletions src/driver/Diagnostics/TerminalDiagnosticStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ public override async ValueTask WriteAsync(
_ when !_interactive => null,
DiagnosticPart.Severity or DiagnosticPart.Caret => severity switch
{
DiagnosticSeverity.Warning =>
ControlSequences.SetForegroundColor(_warningColor.R, _warningColor.G, _warningColor.B),
DiagnosticSeverity.Error =>
ControlSequences.SetForegroundColor(_errorColor.R, _errorColor.G, _errorColor.B),
null => ControlSequences.SetForegroundColor(_noteColor.R, _noteColor.G, _noteColor.B),
DiagnosticSeverity.Warning => ControlSequences.SetForegroundColor(_warningColor),
DiagnosticSeverity.Error => ControlSequences.SetForegroundColor(_errorColor),
null => ControlSequences.SetForegroundColor(_noteColor),
_ => throw new UnreachableException(),
},
DiagnosticPart.Separator =>
ControlSequences.SetForegroundColor(_separatorColor.R, _separatorColor.G, _separatorColor.B),
DiagnosticPart.Path =>
ControlSequences.SetForegroundColor(_locationColor.R, _locationColor.G, _locationColor.B),
DiagnosticPart.Range => ControlSequences.SetForegroundColor(_spanColor.R, _spanColor.G, _spanColor.B),
DiagnosticPart.Margin =>
ControlSequences.SetForegroundColor(_marginColor.R, _marginColor.G, _marginColor.B),
DiagnosticPart.Separator => ControlSequences.SetForegroundColor(_separatorColor),
DiagnosticPart.Path => ControlSequences.SetForegroundColor(_locationColor),
DiagnosticPart.Range => ControlSequences.SetForegroundColor(_spanColor),
DiagnosticPart.Margin => ControlSequences.SetForegroundColor(_marginColor),
DiagnosticPart.TargetLine => ControlSequences.SetDecorations(intense: true),
_ => null,
};
Expand Down
9 changes: 4 additions & 5 deletions src/driver/Logging/TerminalLanguageServiceLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public override void Log(LogLevel logLevel, string eventName, string message, Ex
var writer = _provider.Writer;

writer.Write("[");
writer.WriteControl(
ControlSequences.SetForegroundColor(_timestampColor.R, _timestampColor.G, _timestampColor.B));
writer.WriteControl(ControlSequences.SetForegroundColor(_timestampColor));
writer.Write($"{DateTime.Now:HH:mm:ss.fff}");
writer.WriteControl(ControlSequences.ResetAttributes());
writer.Write("]");
Expand All @@ -55,19 +54,19 @@ public override void Log(LogLevel logLevel, string eventName, string message, Ex
};

writer.Write("[");
writer.WriteControl(ControlSequences.SetForegroundColor(color.R, color.G, color.B));
writer.WriteControl(ControlSequences.SetForegroundColor(color));
writer.Write(level);
writer.WriteControl(ControlSequences.ResetAttributes());
writer.Write("]");

writer.Write("[");
writer.WriteControl(ControlSequences.SetForegroundColor(_nameColor.R, _nameColor.G, _nameColor.B));
writer.WriteControl(ControlSequences.SetForegroundColor(_nameColor));
writer.Write(_name);
writer.WriteControl(ControlSequences.ResetAttributes());
writer.Write("]");

writer.Write("[");
writer.WriteControl(ControlSequences.SetForegroundColor(_eventColor.R, _eventColor.G, _eventColor.B));
writer.WriteControl(ControlSequences.SetForegroundColor(_eventColor));
writer.Write(eventName);
writer.WriteControl(ControlSequences.ResetAttributes());
writer.Write("] ");
Expand Down
6 changes: 4 additions & 2 deletions src/driver/Verbs/InfoVerb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ protected override async ValueTask<int> RunAsync(CancellationToken cancellationT
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
async ValueTask WriteSectionAsync(string header, IEnumerable<(string Name, object Value)> table)
{
await Out.WriteControlAsync(ControlSequences.SetForegroundColor(175, 255, 0), cancellationToken);
await Out.WriteControlAsync(
ControlSequences.SetForegroundColor(Color.FromArgb(175, 255, 0)), cancellationToken);
await Out.WriteLineAsync(header, cancellationToken);
await Out.WriteControlAsync(ControlSequences.ResetAttributes(), cancellationToken);

foreach (var (name, value) in table)
{
await Out.WriteControlAsync(ControlSequences.SetForegroundColor(215, 215, 255), cancellationToken);
await Out.WriteControlAsync(
ControlSequences.SetForegroundColor(Color.FromArgb(215, 215, 255)), cancellationToken);
await Out.WriteAsync($"{name}: ", cancellationToken);
await Out.WriteControlAsync(ControlSequences.ResetAttributes(), cancellationToken);
await Out.WriteLineAsync(value, cancellationToken);
Expand Down
3 changes: 1 addition & 2 deletions src/driver/Verbs/Verb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public async ValueTask<int> RunWithHandlerAsync(CancellationToken cancellationTo
}
catch (DriverException ex)
{
await Error.WriteControlAsync(
ControlSequences.SetForegroundColor(_errorColor.R, _errorColor.G, _errorColor.B), cancellationToken);
await Error.WriteControlAsync(ControlSequences.SetForegroundColor(_errorColor), cancellationToken);
await Error.WriteLineAsync(ex.Message, cancellationToken);
await Error.WriteControlAsync(ControlSequences.ResetAttributes(), cancellationToken);

Expand Down

0 comments on commit 38b8c83

Please sign in to comment.