示例#1
0
        /// <summary>
        /// Consctructs the Console Color map.
        /// </summary>
        private void ConstructMap()
        {
            ConsoleHostNativeMethods.CONSOLE_SCREEN_BUFFER_INFO_EX screenBufferInfo = DotConsoleNative.GetConsoleScreenBufferInfoExtended(consoleHandle);

            colorMap.Add(ConsoleColor.Black, Convert(screenBufferInfo.black.Color));
            colorMap.Add(ConsoleColor.White, Convert(screenBufferInfo.white.Color));
            colorMap.Add(ConsoleColor.Red, Convert(screenBufferInfo.red.Color));
            colorMap.Add(ConsoleColor.Green, Convert(screenBufferInfo.green.Color));
            colorMap.Add(ConsoleColor.Blue, Convert(screenBufferInfo.blue.Color));
            colorMap.Add(ConsoleColor.Gray, Convert(screenBufferInfo.gray.Color));
            colorMap.Add(ConsoleColor.Cyan, Convert(screenBufferInfo.cyan.Color));
            colorMap.Add(ConsoleColor.Magenta, Convert(screenBufferInfo.magenta.Color));

            colorMap.Add(ConsoleColor.DarkRed, Convert(screenBufferInfo.darkRed.Color));
            colorMap.Add(ConsoleColor.DarkGreen, Convert(screenBufferInfo.darkGreen.Color));
            colorMap.Add(ConsoleColor.DarkBlue, Convert(screenBufferInfo.darkBlue.Color));
            colorMap.Add(ConsoleColor.DarkGray, Convert(screenBufferInfo.darkGray.Color));
            colorMap.Add(ConsoleColor.DarkYellow, Convert(screenBufferInfo.darkYellow.Color));
            colorMap.Add(ConsoleColor.DarkCyan, Convert(screenBufferInfo.darkCyan.Color));
            colorMap.Add(ConsoleColor.DarkMagenta, Convert(screenBufferInfo.darkMagenta.Color));
        }
示例#2
0
        /// <summary>
        /// Send the updated Color to the console host under the specified ConsoleColor key.
        /// </summary>
        /// <param name="keyColor"></param>
        /// <param name="targetColor"></param>
        private void MapToConsoleHost(ConsoleColor keyColor, Color targetColor)
        {
            ConsoleHostNativeMethods.CONSOLE_SCREEN_BUFFER_INFO_EX screenBufferInfo = DotConsoleNative.GetConsoleScreenBufferInfoExtended(consoleHandle);

            switch (keyColor)
            {
            case ConsoleColor.Black:
                screenBufferInfo.black.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.White:
                screenBufferInfo.white.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.Blue:
                screenBufferInfo.blue.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.Cyan:
                screenBufferInfo.cyan.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.Red:
                screenBufferInfo.red.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.Green:
                screenBufferInfo.green.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.Magenta:
                screenBufferInfo.magenta.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.Gray:
                screenBufferInfo.gray.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.Yellow:
                screenBufferInfo.yellow.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.DarkYellow:
                screenBufferInfo.darkYellow.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.DarkRed:
                screenBufferInfo.darkRed.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.DarkGreen:
                screenBufferInfo.darkGreen.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.DarkBlue:
                screenBufferInfo.darkBlue.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.DarkMagenta:
                screenBufferInfo.darkMagenta.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.DarkGray:
                screenBufferInfo.darkGray.Color = Convert(colorMap[keyColor]);
                break;

            case ConsoleColor.DarkCyan:
                screenBufferInfo.darkCyan.Color = Convert(colorMap[keyColor]);
                break;
            }

            // SUPER WHACKY CODE HERE.
            // WHY???!!!
            // This looks to me like a bug but it's needed since buffer info seems to shrink one line at a time in every direction :|
            screenBufferInfo.window.Bottom++;
            screenBufferInfo.window.Right++;

            DotConsoleNative.SetConsoleScreenBufferInfoExtended(consoleHandle, screenBufferInfo);
        }