Beispiel #1
0
        /// <summary>
        /// The most safe constructor - uses default window and buffer sizes
        /// </summary>
        /// <param name="controller"></param>
        public SystemConsole(ConsoleController controller)
        {
            controller.Requires(nameof(controller)).IsNotNull();

            this._controller = controller;

            Console.OutputEncoding = Encoding.Unicode;
            Console.InputEncoding  = Encoding.Unicode;

            this.WindowWidth  = Console.WindowWidth;
            this.WindowHeight = Console.WindowHeight;
        }
Beispiel #2
0
        /// <summary>
        /// The most safe constructor - uses default window and buffer sizes
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="config"></param>
        public SystemConsole(ConsoleController controller, ConsoleStartConfiguration config = null)  // TODO: refactor to some more common calculation code?
        {
            controller.Requires(nameof(controller)).IsNotNull();
            config              = config ?? ConsoleStartConfiguration.Colorfull; // surprise ;-)
            this._controller    = controller;
            this._configuration = config;

            if (config.TryVirtualConsole)
            {
                this.TryTurningVirtualConsoleMode();
            }

            if (!string.IsNullOrWhiteSpace(config.ColorSchemeName))
            {
                this.TryLoadingColorScheme(controller, config.ColorSchemeName);
            }

            Console.OutputEncoding = Encoding.Unicode;
            Console.InputEncoding  = Encoding.Unicode;



            if (config.RunFullScreen)
            {
                this.SetConsoleWindowToFullScreen();

                // now can calculate how large could be full-screen buffer

                // SG: (-2) On Win8 the only working way to keep borders on the screen :(
                // (-1) required on Win10 though :(
                this.WindowSize = new Point(Console.LargestWindowWidth - 2, Console.LargestWindowHeight - 1);

                // setting full-screen
                Console.BufferWidth  = this.WindowSize.X;
                Console.WindowWidth  = this.WindowSize.X;
                Console.BufferHeight = this.WindowSize.Y;
                Console.WindowHeight = this.WindowSize.Y;

                Console.SetWindowPosition(0, 0); // move again
            }
            else
            {
                if (!this.IsExcutedAsChild)
                {
                    // set console (buffer) little bigger by default (not when child process of cmd... - in such case keep the size)
                    // TODO: improve this code in case of already configured larger window...

                    int currentBufferWidth  = Console.BufferWidth;
                    int currentBufferHeight = Console.BufferHeight;
                    int currentWindowWidth  = Console.WindowWidth;
                    int currentWindowHeight = Console.WindowHeight;

                    // window cannot be greater than buffer, also - cannot create buffer smaller that current window (because it's window to the buffer)
                    int targetBufferWidth  = Math.Max(Math.Max((int)currentBufferWidth, (int)config.DesiredBufferRowWidth), (int)config.DesiredRowWidth);
                    int targetRowWidth     = Math.Min(Math.Max((int)currentWindowWidth, (int)config.DesiredRowWidth), targetBufferWidth);
                    int targetBufferHeight = Math.Max(Math.Max((int)currentBufferHeight, (int)config.DesiredBufferRowCount), (int)config.DesiredRowCount);
                    int targetRowCount     = Math.Min(Math.Max((int)currentWindowHeight, (int)config.DesiredRowCount), targetBufferHeight);


                    Console.WindowWidth  = Math.Min(targetRowWidth, Console.LargestWindowWidth - 2);
                    Console.WindowHeight = Math.Min(targetRowCount, Console.LargestWindowHeight - 1);

                    Console.BufferWidth  = targetBufferWidth;
                    Console.BufferHeight = targetBufferHeight;
                }
            }

            // read parameters after resizing
            this.WindowWidth  = Console.WindowWidth;
            this.WindowHeight = Console.WindowHeight;
        }