Пример #1
0
        /// <summary>
        /// Full-screen constructor, when flag value is TRUE. If no - it's just constructs 120x40 window with 120x500 buffer (larger than default).
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="isFullScreen"></param>
        public SystemConsole(ConsoleController controller, bool isFullScreen) : this(controller)
        {
            if (isFullScreen)
            {
                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);
            }
            else
            {
                if (!this.IsExcutedAsChild)
                {
                    // set console (buffer) little bigger by default (not when child process of cmd...)
                    // TODO: improve this code in case of already configured larger window...
                    Console.BufferWidth  = 120;
                    Console.BufferHeight = 500;
                    Console.WindowWidth  = 120;
                    Console.WindowHeight = 40;
                }
            }

            this.WindowWidth  = Console.WindowWidth;
            this.WindowHeight = Console.WindowHeight;
        }
Пример #2
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;
        }
Пример #3
0
        /// <summary>
        /// Custom sized console
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="bufferSize">Width and height of the buffer. Must be >= window size. Will be resized automatically if not fits...</param>
        /// <param name="windowSize">Width and height of the window (In columns and rows, depends of font and screen resolution!). Cannot exceed screen size. Will be automatically trimmed.</param>
        public SystemConsole(ConsoleController controller, Point bufferSize, Point windowSize) : this(controller)
        {
            windowSize.X = Math.Min(windowSize.X, Console.LargestWindowWidth - 2);
            windowSize.Y = Math.Min(windowSize.Y, Console.LargestWindowHeight - 1);
            bufferSize.X = Math.Max(bufferSize.X, windowSize.X);
            bufferSize.Y = Math.Max(bufferSize.Y, windowSize.Y);

            Console.BufferWidth  = bufferSize.X;
            Console.WindowWidth  = windowSize.X;
            Console.BufferHeight = bufferSize.Y;
            Console.WindowHeight = windowSize.Y;

            this.WindowWidth  = Console.WindowWidth;
            this.WindowHeight = Console.WindowHeight;
        }
Пример #4
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;
        }
Пример #5
0
 private void TryLoadingColorScheme(ConsoleController controller, string configColorSchemeName)
 {
     throw new NotImplementedException();
 }