Skip to content

Commit 42fe045

Browse files
thomhurstclaude
andcommitted
fix: use delegating console for SpectreLogger configuration
Create DelegatingAnsiConsole wrapper that forwards to the current AnsiConsole.Console instance. This fixes the conflict where: - DI setup was configuring width on initial AnsiConsole.Console - ConsoleCoordinator later replaces AnsiConsole.Console entirely - SpectreLogger was left using the old console instance Now SpectreLogger uses DelegatingAnsiConsole.Instance which always delegates to the current AnsiConsole.Console, ensuring the console replacement by ConsoleCoordinator works correctly. Console width configuration is now solely handled by ConsoleCoordinator.ConfigureConsoleWidth(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 76d350e commit 42fe045

2 files changed

Lines changed: 40 additions & 10 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Spectre.Console;
2+
using Spectre.Console.Rendering;
3+
4+
namespace ModularPipelines.Console;
5+
6+
/// <summary>
7+
/// A delegating wrapper that always forwards to the current AnsiConsole.Console.
8+
/// This allows the console instance to be replaced (e.g., by ConsoleCoordinator)
9+
/// while loggers continue to use the correct console.
10+
/// </summary>
11+
internal sealed class DelegatingAnsiConsole : IAnsiConsole
12+
{
13+
public static DelegatingAnsiConsole Instance { get; } = new();
14+
15+
private DelegatingAnsiConsole()
16+
{
17+
}
18+
19+
private static IAnsiConsole Console => AnsiConsole.Console;
20+
21+
public Profile Profile => Console.Profile;
22+
23+
public IAnsiConsoleCursor Cursor => Console.Cursor;
24+
25+
public IAnsiConsoleInput Input => Console.Input;
26+
27+
public IExclusivityMode ExclusivityMode => Console.ExclusivityMode;
28+
29+
public RenderPipeline Pipeline => Console.Pipeline;
30+
31+
public void Clear(bool home) => Console.Clear(home);
32+
33+
public void Write(IRenderable renderable) => Console.Write(renderable);
34+
}

src/ModularPipelines/DependencyInjection/DependencyInjectionSetup.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
using ModularPipelines.Options.Validators;
3232
using ModularPipelines.Engine.State;
3333
using ModularPipelines.Validation;
34-
using Spectre.Console;
34+
using ModularPipelines.Console;
3535
using Vertical.SpectreLogger;
3636
using Vertical.SpectreLogger.Options;
3737

@@ -79,15 +79,11 @@ private static void RegisterBundledServices(IServiceCollection services)
7979

8080
builder.AddSpectreConsole(config =>
8181
{
82-
// Configure console width for CI environments
83-
// When output is redirected (common in CI), Spectre defaults to 80 chars
84-
// We expand this to 160 for better readability in CI logs
85-
if (System.Console.IsOutputRedirected)
86-
{
87-
AnsiConsole.Console.Profile.Width = 160;
88-
}
89-
90-
config.UseConsole(AnsiConsole.Console);
82+
// Use delegating console that forwards to current AnsiConsole.Console
83+
// This allows ConsoleCoordinator to replace the console instance later
84+
// while SpectreLogger continues to use the correct one
85+
// Note: Console width is configured by ConsoleCoordinator.ConfigureConsoleWidth()
86+
config.UseConsole(DelegatingAnsiConsole.Instance);
9187

9288
// Configure output templates without timestamps
9389
// Command logging already includes precise timestamps ([HH:mm:ss.fff])

0 commit comments

Comments
 (0)