Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write all informational messages to stderr #499

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/D2L.Bmx/ConsoleWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ internal class ConsoleWriter : IConsoleWriter {
// https://github.com/dotnet/runtime/blob/v9.0.0-preview.6.24327.7/src/libraries/Common/src/System/Console/ConsoleUtils.cs#L32-L34
private readonly bool _noColor
= Environment.GetEnvironmentVariable( "NO_COLOR" ) == "1" || !VirtualTerminal.TryEnableOnStderr();
private readonly IAnsiConsole _ansiConsole = AnsiConsole.Create( new() {
Out = new AnsiConsoleOutput( Console.Error ),
} );

void IConsoleWriter.WriteParameter( string description, string value, ParameterSource source ) {
string valueColor = _noColor ? "default" : "cyan2";
string sourceColor = _noColor ? "default" : "grey";
AnsiConsole.MarkupLine( $"[default]{description}:[/] [{valueColor}]{value}[/] [{sourceColor}](from {source})[/]" );
_ansiConsole.MarkupLine( $"[default]{description}:[/] [{valueColor}]{value}[/] [{sourceColor}](from {source})[/]" );
}

void IConsoleWriter.WriteUpdateMessage( string text ) {
Expand All @@ -33,18 +36,18 @@ void IConsoleWriter.WriteUpdateMessage( string text ) {
string color = _noColor ? "default" : "black on white";
foreach( string line in lines ) {
string paddedLine = line.PadRight( maxLineLength );
AnsiConsole.MarkupLine( $"[{color}]{paddedLine}[/]" );
_ansiConsole.MarkupLine( $"[{color}]{paddedLine}[/]" );
}
Console.Error.WriteLine();
}

void IConsoleWriter.WriteWarning( string text ) {
string color = _noColor ? "default" : "yellow";
AnsiConsole.MarkupLine( $"[{color}]{text}[/]" );
_ansiConsole.MarkupLine( $"[{color}]{text}[/]" );
}

void IConsoleWriter.WriteError( string text ) {
string color = _noColor ? "default" : "red";
AnsiConsole.MarkupLine( $"[{color}]{text}[/]" );
_ansiConsole.MarkupLine( $"[{color}]{text}[/]" );
}
}
Loading