Skip to content

Commit e0a6200

Browse files
Refactor SpectreConsoleNotifier to improve output handling
- Updated methods in `SpectreConsoleNotifier` to use a new `WriteLine` method for consistent output formatting, providing both markup and plain text options. - Enhanced error, warning, and informational messages to ensure proper display in interactive and non-interactive environments. - Aimed to improve user experience by standardizing console notifications and ensuring clarity in message presentation.
1 parent 2c20000 commit e0a6200

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

CognitiveCodeAnalysisConsoleApp/src/Infrastructure/SpectreConsoleNotifier.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,49 @@ namespace CognitiveCodeAnalysisConsoleApp.Infrastructure;
99
internal sealed class SpectreConsoleNotifier : IConsoleNotifier
1010
{
1111
public void WriteError(string message)
12-
=> AnsiConsole.MarkupLine($"[red]Error: {Markup.Escape(message)}[/]");
12+
=> WriteLine(
13+
$"[red]Error: {Markup.Escape(message)}[/]",
14+
$"Error: {message}"
15+
);
1316

1417
public void WriteWarning(string message)
15-
=> AnsiConsole.MarkupLine($"[yellow]Warning: {Markup.Escape(message)}[/]");
18+
=> WriteLine(
19+
$"[yellow]Warning: {Markup.Escape(message)}[/]",
20+
$"Warning: {message}"
21+
);
1622

1723
public void WriteNoSourceFilesFound(string absoluteSourcePath)
18-
=> AnsiConsole.MarkupLine($"[yellow]No C# files found in {Markup.Escape(absoluteSourcePath)}.[/]");
24+
=> WriteLine(
25+
$"[yellow]No C# files found in {Markup.Escape(absoluteSourcePath)}.[/]",
26+
$"No C# files found in {absoluteSourcePath}."
27+
);
1928

2029
public void WriteReportGenerated(string reportType, string fullPath)
21-
=> AnsiConsole.MarkupLine($"[green]{Markup.Escape(reportType)} report generated:[/] {Markup.Escape(fullPath)}");
30+
=> WriteLine(
31+
$"[green]{Markup.Escape(reportType)} report generated:[/] {Markup.Escape(fullPath)}",
32+
$"{reportType} report generated: {fullPath}"
33+
);
2234

2335
public void WriteConfigUsed(string configSourceDisplay)
24-
=> AnsiConsole.MarkupLine($"[grey]Config:[/] {Markup.Escape(configSourceDisplay)}");
36+
=> WriteLine(
37+
$"[grey]Config: {Markup.Escape(configSourceDisplay)}[/]",
38+
$"Config: {configSourceDisplay}"
39+
);
2540

2641
public void WriteConfigFileCreated(string fullPath)
27-
=> AnsiConsole.MarkupLine($"[green]Config file created:[/] {Markup.Escape(fullPath)}");
42+
=> WriteLine(
43+
$"[green]Config file created:[/] {Markup.Escape(fullPath)}",
44+
$"Config file created: {fullPath}"
45+
);
46+
47+
private static void WriteLine(string markup, string plain)
48+
{
49+
if (AnsiConsole.Profile.Capabilities.Interactive)
50+
{
51+
AnsiConsole.MarkupLine(markup);
52+
return;
53+
}
54+
55+
Console.WriteLine(plain);
56+
}
2857
}

0 commit comments

Comments
 (0)