private void ConsoleResizeListener(CancellationPipe cancel)
        {
            int  consoleWidth  = Console.WindowWidth;
            int  consoleHeight = Console.WindowHeight;
            bool trigger       = false;
            int  trigger_inc   = 0;

            while (!cancel.Cancelled)
            {
                int readWidth  = Console.WindowWidth;
                int readHeight = Console.WindowHeight;
                if (readWidth != consoleWidth || readHeight != consoleHeight)
                {
                    trigger = true;
                    foreach (var listener in changeListeners)
                    {
                        listener(consoleWidth, consoleHeight, readWidth, readHeight);
                    }
                    consoleWidth  = readWidth;
                    consoleHeight = readHeight;
                }
                else if (trigger && ++trigger_inc >= 5)
                {
                    foreach (var listener in completeListeners)
                    {
                        listener(consoleWidth, consoleHeight);
                    }
                    trigger = false;
                }
                System.Threading.Thread.Sleep(50);
            }
        }
 public void EnableResizeListener()
 {
     if (cancel != null)
     {
         return;
     }
     // Set up console window resize listener
     cancel         = new CancellationPipe();
     resizeListener = new Task(() => ConsoleResizeListener(cancel)); // Start resize listener asynchronously
     resizeListener.Start();
 }