using System.Runtime.InteropServices; using System.Text; using System.Text.Json; using XFESystem.Console; using XFESystem.ConsoleDemo; global::System.Console.OutputEncoding = Encoding.UTF8; if (args.Length == 2 && args[0] == "--Verify") { using var captured = new StringWriter(); ConsoleDemoScenario.Run(captured); ConsoleDemoScenario.RunXfeConsoleApi(captured); var transcript = captured.ToString(); var terminal = new TerminalBuffer(80, 20); // Deliberately split every escape and surrogate boundary to exercise streaming. foreach (var character in transcript) terminal.Write(character.ToString()); terminal.Complete(); var expected = new[] { "XFESystem C# Console Demo", "RGB: #75C9F5", "Indexed: 202 / 236", "ConsoleColor ANSI: Blue", "Style: Bold + Underline", "Reset: Theme default", "Edit: OK", "Cursor: x!", "Unicode: 中文 g y", ConsoleDemoScenario.SuccessMarker, "XFEConsole API: Real NuGet 2.6.0" }; var lines = Enumerable.Range(0, expected.Length).Select(row => terminal.GetLine(row)).ToArray(); var assertions = new Dictionary { ["ExpectedTextAndControlCharacters"] = lines.SequenceEqual(expected), ["TrueColor"] = terminal.GetCell(0, 1).Style.Foreground == new TerminalColor(117, 201, 245), ["IndexedForeground"] = terminal.GetCell(0, 2).Style.Foreground == new TerminalColor(255, 95, 0), ["IndexedBackground"] = terminal.GetCell(0, 2).Style.Background == new TerminalColor(48, 48, 48), ["ConsoleColorAnsiMapping"] = terminal.GetCell(0, 3).Style.Foreground == TerminalColor.FromConsoleColor(ConsoleColor.Blue), ["BoldAndUnderline"] = terminal.GetCell(0, 4).Style is { Bold: true, Underline: true }, ["StyleReset"] = terminal.GetCell(0, 5).Style == TerminalStyle.Default, ["NoEscapeLeak"] = !terminal.GetText().Contains('\u001b'), ["RealXfeConsoleAssembly"] = typeof(XFEExtension.NetCore.XFEConsole.XFEConsole).Assembly.GetName().Name == "XFEExtension.NetCore.XFEConsole" }; var reportPath = Path.GetFullPath(args[1]); Directory.CreateDirectory(Path.GetDirectoryName(reportPath)!); var report = new ConsoleVerificationReport { Schema = "XFESystem.ConsoleDemo.HostVerification.V1", HostOnly = true, GuestExecution = false, Runtime = RuntimeInformation.FrameworkDescription, OperatingSystem = RuntimeInformation.OSDescription, Package = new ConsolePackage("XFEExtension.NetCore.XFEConsole", "2.6.0"), SystemConsoleColorPal = "Not verified by redirected text capture; requires a native console or guest PAL test", Passed = assertions.Values.All(value => value), Assertions = assertions, Lines = lines, Foreground = Enumerable.Range(0, expected.Length).Select(row => terminal.GetCell(0, row).Style.Foreground.Hex).ToArray(), Transcript = transcript }; File.WriteAllText(reportPath, JsonSerializer.Serialize(report, ConsoleReportJsonContext.Default.ConsoleVerificationReport), new UTF8Encoding(false)); global::System.Console.WriteLine($"Host console model verification: {reportPath}"); return assertions.Values.All(value => value) ? 0 : 1; } if (args.Length != 0) { global::System.Console.Error.WriteLine("Usage: XFESystem.ConsoleDemo.App [--Verify Report.json]"); return 2; } ConsoleDemoScenario.RunSystemConsoleColors(); ConsoleDemoScenario.Run(global::System.Console.Out); ConsoleDemoScenario.RunXfeConsoleApi(global::System.Console.Out); return 0;