using XFEExtension.NetCore.XFEConsole.Terminal;
using XFEConsoleApi = XFEExtension.NetCore.XFEConsole.XFEConsole;
namespace XFESystem.ConsoleDemo;
/// <summary>
/// Shared application body for hosted and statically compiled guest tests.
/// The ANSI path uses the real XFEConsole NuGet package without probing host APIs.
/// </summary>
public static class ConsoleDemoScenario
{
public const string SuccessMarker = "XFE_CSHARP_CONSOLE_DEMO_OK";
public static void Run(TextWriter output)
{
ArgumentNullException.ThrowIfNull(output);
Line(output, "XFESystem C# Console Demo");
Line(output, new XFETerminalStyle
{
Foreground = XFETerminalColor.FromRgb(117, 201, 245)
}.Apply("RGB: #75C9F5"));
Line(output, new XFETerminalStyle
{
Foreground = XFETerminalColor.FromIndex(202),
Background = XFETerminalColor.FromIndex(236)
}.Apply("Indexed: 202 / 236"));
Line(output, new XFETerminalStyle
{
Foreground = XFETerminalColor.FromConsoleColor(ConsoleColor.Blue)
}.Apply("ConsoleColor ANSI: Blue"));
Line(output, new XFETerminalStyle
{
Foreground = XFETerminalColor.FromRgb(172, 153, 234),
Bold = true,
Underline = true
}.Apply("Style: Bold + Underline"));
Line(output, "Reset: Theme default");
Line(output, "Edit: abc\bD\rEdit: OK\u001b[K");
Line(output, "Cursor: xy\u001b[1D!");
Line(output, "Unicode: 中文 g y");
Line(output, SuccessMarker);
}
/// <summary>Exercise runtime Console PAL calls, separately from ANSI parsing.</summary>
public static void RunSystemConsoleColors()
{
var foreground = global::System.Console.ForegroundColor;
var background = global::System.Console.BackgroundColor;
try
{
global::System.Console.ForegroundColor = ConsoleColor.Cyan;
global::System.Console.BackgroundColor = ConsoleColor.DarkBlue;
global::System.Console.WriteLine("Console.ForegroundColor: Cyan / DarkBlue");
global::System.Console.ResetColor();
}
catch
{
Restore();
throw;
}
Restore();
void Restore()
{
global::System.Console.ForegroundColor = foreground;
global::System.Console.BackgroundColor = background;
}
}
/// <summary>
/// Direct XFEConsole API test. This path retains the package's remote-console
/// dependencies during AOT; a bare-metal port must supply their runtime imports.
/// No remote connection is opened by this method.
/// </summary>
public static void RunXfeConsoleApi(TextWriter output)
{
ArgumentNullException.ThrowIfNull(output);
var oldWriter = XFEConsoleApi.CurrentConsoleTextWriter;
var oldDebug = XFEConsoleApi.ShowInDebug;
var oldLocal = XFEConsoleApi.ShowInLocalConsole;
var oldLog = XFEConsoleApi.EnableLog;
try
{
XFEConsoleApi.CurrentConsoleTextWriter = new(output);
XFEConsoleApi.ShowInDebug = false;
XFEConsoleApi.ShowInLocalConsole = true;
XFEConsoleApi.EnableLog = false;
XFEConsoleApi.WriteLine("XFEConsole API: Real NuGet 2.6.0");
}
catch
{
Restore();
throw;
}
Restore();
void Restore()
{
XFEConsoleApi.CurrentConsoleTextWriter = oldWriter;
XFEConsoleApi.ShowInDebug = oldDebug;
XFEConsoleApi.ShowInLocalConsole = oldLocal;
XFEConsoleApi.EnableLog = oldLog;
}
}
private static void Line(TextWriter output, string text)
{
output.Write(text);
output.Write("\r\n");
}
}
using XFEExtension.NetCore.XFEConsole.Terminal;
using XFEConsoleApi = XFEExtension.NetCore.XFEConsole.XFEConsole;
namespace XFESystem.ConsoleDemo;
/// <summary>
/// Shared application body for hosted and statically compiled guest tests.
/// The ANSI path uses the real XFEConsole NuGet package without probing host APIs.
/// </summary>
public static class ConsoleDemoScenario
{
public const string SuccessMarker = "XFE_CSHARP_CONSOLE_DEMO_OK";
public static void Run(TextWriter output)
{
ArgumentNullException.ThrowIfNull(output);
Line(output, "XFESystem C# Console Demo");
Line(output, new XFETerminalStyle
{
Foreground = XFETerminalColor.FromRgb(117, 201, 245)
}.Apply("RGB: #75C9F5"));
Line(output, new XFETerminalStyle
{
Foreground = XFETerminalColor.FromIndex(202),
Background = XFETerminalColor.FromIndex(236)
}.Apply("Indexed: 202 / 236"));
Line(output, new XFETerminalStyle
{
Foreground = XFETerminalColor.FromConsoleColor(ConsoleColor.Blue)
}.Apply("ConsoleColor ANSI: Blue"));
Line(output, new XFETerminalStyle
{
Foreground = XFETerminalColor.FromRgb(172, 153, 234),
Bold = true,
Underline = true
}.Apply("Style: Bold + Underline"));
Line(output, "Reset: Theme default");
Line(output, "Edit: abc\bD\rEdit: OK\u001b[K");
Line(output, "Cursor: xy\u001b[1D!");
Line(output, "Unicode: 中文 g y");
Line(output, SuccessMarker);
}
/// <summary>Exercise runtime Console PAL calls, separately from ANSI parsing.</summary>
public static void RunSystemConsoleColors()
{
var foreground = global::System.Console.ForegroundColor;
var background = global::System.Console.BackgroundColor;
try
{
global::System.Console.ForegroundColor = ConsoleColor.Cyan;
global::System.Console.BackgroundColor = ConsoleColor.DarkBlue;
global::System.Console.WriteLine("Console.ForegroundColor: Cyan / DarkBlue");
global::System.Console.ResetColor();
}
catch
{
Restore();
throw;
}
Restore();
void Restore()
{
global::System.Console.ForegroundColor = foreground;
global::System.Console.BackgroundColor = background;
}
}
/// <summary>
/// Direct XFEConsole API test. This path retains the package's remote-console
/// dependencies during AOT; a bare-metal port must supply their runtime imports.
/// No remote connection is opened by this method.
/// </summary>
public static void RunXfeConsoleApi(TextWriter output)
{
ArgumentNullException.ThrowIfNull(output);
var oldWriter = XFEConsoleApi.CurrentConsoleTextWriter;
var oldDebug = XFEConsoleApi.ShowInDebug;
var oldLocal = XFEConsoleApi.ShowInLocalConsole;
var oldLog = XFEConsoleApi.EnableLog;
try
{
XFEConsoleApi.CurrentConsoleTextWriter = new(output);
XFEConsoleApi.ShowInDebug = false;
XFEConsoleApi.ShowInLocalConsole = true;
XFEConsoleApi.EnableLog = false;
XFEConsoleApi.WriteLine("XFEConsole API: Real NuGet 2.6.0");
}
catch
{
Restore();
throw;
}
Restore();
void Restore()
{
XFEConsoleApi.CurrentConsoleTextWriter = oldWriter;
XFEConsoleApi.ShowInDebug = oldDebug;
XFEConsoleApi.ShowInLocalConsole = oldLocal;
XFEConsoleApi.EnableLog = oldLog;
}
}
private static void Line(TextWriter output, string text)
{
output.Write(text);
output.Write("\r\n");
}
}