123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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<Coord, EffectCharacter> CharacterByInputCoord = new Dictionary<Coord, EffectCharacter> ();
- 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);
- }
- }
|