namespace Terminal.Gui.TextEffects; public class TerminalConfig { public int TabWidth { get; set; } = 4; public bool XtermColors { get; set; } = false; public bool NoColor { get; set; } = false; public bool WrapText { get; set; } = false; public float FrameRate { get; set; } = 100.0f; public int CanvasWidth { get; set; } = -1; public int CanvasHeight { get; set; } = -1; public string AnchorCanvas { get; set; } = "sw"; public string AnchorText { get; set; } = "sw"; public bool IgnoreTerminalDimensions { get; set; } = false; } public class Canvas { public int Top { get; private set; } public int Right { get; private set; } public int Bottom { get; private set; } = 1; public int Left { get; private set; } = 1; public int CenterRow => (Top + Bottom) / 2; public int CenterColumn => (Right + Left) / 2; public Coord Center => new Coord (CenterColumn, CenterRow); public int Width => Right - Left + 1; public int Height => Top - Bottom + 1; public Canvas (int top, int right) { Top = top; Right = right; } public bool IsCoordInCanvas (Coord coord) { return coord.Column >= Left && coord.Column <= Right && coord.Row >= Bottom && coord.Row <= Top; } public Coord GetRandomCoord (bool outsideScope = false) { var random = new Random (); if (outsideScope) { switch (random.Next (4)) { case 0: return new Coord (random.Next (Left, Right + 1), Top + 1); case 1: return new Coord (random.Next (Left, Right + 1), Bottom - 1); case 2: return new Coord (Left - 1, random.Next (Bottom, Top + 1)); case 3: return new Coord (Right + 1, random.Next (Bottom, Top + 1)); } } return new Coord ( random.Next (Left, Right + 1), random.Next (Bottom, Top + 1)); } } public class TerminalA { public TerminalConfig Config { get; } public Canvas Canvas { get; private set; } private Dictionary CharacterByInputCoord = new Dictionary (); public TerminalA (string input, TerminalConfig config = null) { Config = config ?? new TerminalConfig (); var dimensions = GetTerminalDimensions (); Canvas = new Canvas (dimensions.height, dimensions.width); ProcessInput (input); } private void ProcessInput (string input) { // Handling input processing logic similar to Python's version } public string GetPipedInput () { // C# way to get piped input or indicate there's none return Console.IsInputRedirected ? Console.In.ReadToEnd () : string.Empty; } public void Print (string output, bool enforceFrameRate = true) { if (enforceFrameRate) EnforceFrameRate (); // Move cursor to top and clear the current console line Console.SetCursorPosition (0, 0); Console.Write (output); Console.ResetColor (); } private void EnforceFrameRate () { // Limit the printing speed based on the Config.FrameRate } private (int width, int height) GetTerminalDimensions () { // Return terminal dimensions or defaults if not determinable return (Console.WindowWidth, Console.WindowHeight); } }