public ColorManager GetManager(ConcurrentDictionary <Color, ConsoleColor> colorMap, ConcurrentDictionary <ConsoleColor, Color> consoleColorMap, int maxColorChanges, int initialColorChangeCountValue, bool isInCompatibilityMode)
        {
            ColorStore  colorStore  = new ColorStore(colorMap, consoleColorMap);
            ColorMapper colorMapper = new ColorMapper();

            return(new ColorManager(colorStore, colorMapper, maxColorChanges, initialColorChangeCountValue, isInCompatibilityMode));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a collection of all 16 colors in the console buffer.
        /// </summary>
        /// <returns>Returns all 16 COLORREFs in the console buffer as a dictionary keyed by the COLORREF's alias
        /// in the buffer's ColorTable.</returns>
        public Dictionary <string, COLORREF> GetBufferColors()
        {
            Dictionary <string, COLORREF> colors = new Dictionary <string, COLORREF>();
            IntPtr hConsoleOutput = ColorMapper.GetStdHandle(ColorMapper.STD_OUTPUT_HANDLE);    // 7
            CONSOLE_SCREEN_BUFFER_INFO_EX csbe = this.GetBufferInfo(hConsoleOutput);

            colors.Add("black", csbe.black);
            colors.Add("darkBlue", csbe.darkBlue);
            colors.Add("darkGreen", csbe.darkGreen);
            colors.Add("darkCyan", csbe.darkCyan);
            colors.Add("darkRed", csbe.darkRed);
            colors.Add("darkMagenta", csbe.darkMagenta);
            colors.Add("darkYellow", csbe.darkYellow);
            colors.Add("gray", csbe.gray);
            colors.Add("darkGray", csbe.darkGray);
            colors.Add("blue", csbe.blue);
            colors.Add("green", csbe.green);
            colors.Add("cyan", csbe.cyan);
            colors.Add("red", csbe.red);
            colors.Add("magenta", csbe.magenta);
            colors.Add("yellow", csbe.yellow);
            colors.Add("white", csbe.white);

            return(colors);
        }
Esempio n. 3
0
        /// <summary>
        /// Manages the number of different colors that the Windows console is able to display in a given session.
        /// </summary>
        /// <param name="colorStore">The ColorStore instance in which the ColorManager will store colors.</param>
        /// <param name="colorMapper">The ColorMapper instance the ColorManager will use to relate different color
        /// types to one another.</param>
        /// <param name="maxColorChanges">The maximum number of color changes allowed by the ColorManager.  It's
        /// necessary to keep track of this, because the Windows console can only display 16 different colors in
        /// a given session.</param>
        /// <param name="initialColorChangeCountValue">The number of color changes which have already occurred.</param>
        public ColorManager(ColorStore colorStore, ColorMapper colorMapper, int maxColorChanges, int initialColorChangeCountValue, bool isInCompatibilityMode)
        {
            this.colorStore  = colorStore;
            this.colorMapper = colorMapper;

            this.colorChangeCount      = initialColorChangeCountValue;
            this.maxColorChanges       = maxColorChanges;
            this.IsInCompatibilityMode = isInCompatibilityMode;
        }
Esempio n. 4
0
        private void SetBufferInfo(IntPtr hConsoleOutput, CONSOLE_SCREEN_BUFFER_INFO_EX csbe)
        {
            csbe.srWindow.Bottom++;
            csbe.srWindow.Right++;

            bool brc = ColorMapper.SetConsoleScreenBufferInfoEx(hConsoleOutput, ref csbe);

            if (!brc)
            {
                throw this.CreateException(Marshal.GetLastWin32Error());
            }
        }
Esempio n. 5
0
        private CONSOLE_SCREEN_BUFFER_INFO_EX GetBufferInfo(IntPtr hConsoleOutput)
        {
            CONSOLE_SCREEN_BUFFER_INFO_EX csbe = new CONSOLE_SCREEN_BUFFER_INFO_EX();

            csbe.cbSize = (int)Marshal.SizeOf(csbe); // 96 = 0x60

            if (hConsoleOutput == ColorMapper.INVALID_HANDLE_VALUE)
            {
                throw this.CreateException(Marshal.GetLastWin32Error());
            }

            bool brc = ColorMapper.GetConsoleScreenBufferInfoEx(hConsoleOutput, ref csbe);

            if (!brc)
            {
                throw this.CreateException(Marshal.GetLastWin32Error());
            }

            return(csbe);
        }
Esempio n. 6
0
        /// <summary>
        /// Sets all 16 colors in the console buffer using colors supplied in a dictionary.
        /// </summary>
        /// <param name="colors">A dictionary containing COLORREFs keyed by the COLORREF's alias in the buffer's
        /// ColorTable.</param>
        public void SetBatchBufferColors(Dictionary <string, COLORREF> colors)
        {
            IntPtr hConsoleOutput = ColorMapper.GetStdHandle(ColorMapper.STD_OUTPUT_HANDLE); // 7
            CONSOLE_SCREEN_BUFFER_INFO_EX csbe = this.GetBufferInfo(hConsoleOutput);

            csbe.black       = colors["black"];
            csbe.darkBlue    = colors["darkBlue"];
            csbe.darkGreen   = colors["darkGreen"];
            csbe.darkCyan    = colors["darkCyan"];
            csbe.darkRed     = colors["darkRed"];
            csbe.darkMagenta = colors["darkMagenta"];
            csbe.darkYellow  = colors["darkYellow"];
            csbe.gray        = colors["gray"];
            csbe.darkGray    = colors["darkGray"];
            csbe.blue        = colors["blue"];
            csbe.green       = colors["green"];
            csbe.cyan        = colors["cyan"];
            csbe.red         = colors["red"];
            csbe.magenta     = colors["magenta"];
            csbe.yellow      = colors["yellow"];
            csbe.white       = colors["white"];

            this.SetBufferInfo(hConsoleOutput, csbe);
        }
Esempio n. 7
0
        private void MapColor(ConsoleColor color, uint r, uint g, uint b)
        {
            IntPtr hConsoleOutput = ColorMapper.GetStdHandle(ColorMapper.STD_OUTPUT_HANDLE); // 7
            CONSOLE_SCREEN_BUFFER_INFO_EX csbe = this.GetBufferInfo(hConsoleOutput);

            switch (color)
            {
            case ConsoleColor.Black:
                csbe.black = new COLORREF(r, g, b);
                break;

            case ConsoleColor.DarkBlue:
                csbe.darkBlue = new COLORREF(r, g, b);
                break;

            case ConsoleColor.DarkGreen:
                csbe.darkGreen = new COLORREF(r, g, b);
                break;

            case ConsoleColor.DarkCyan:
                csbe.darkCyan = new COLORREF(r, g, b);
                break;

            case ConsoleColor.DarkRed:
                csbe.darkRed = new COLORREF(r, g, b);
                break;

            case ConsoleColor.DarkMagenta:
                csbe.darkMagenta = new COLORREF(r, g, b);
                break;

            case ConsoleColor.DarkYellow:
                csbe.darkYellow = new COLORREF(r, g, b);
                break;

            case ConsoleColor.Gray:
                csbe.gray = new COLORREF(r, g, b);
                break;

            case ConsoleColor.DarkGray:
                csbe.darkGray = new COLORREF(r, g, b);
                break;

            case ConsoleColor.Blue:
                csbe.blue = new COLORREF(r, g, b);
                break;

            case ConsoleColor.Green:
                csbe.green = new COLORREF(r, g, b);
                break;

            case ConsoleColor.Cyan:
                csbe.cyan = new COLORREF(r, g, b);
                break;

            case ConsoleColor.Red:
                csbe.red = new COLORREF(r, g, b);
                break;

            case ConsoleColor.Magenta:
                csbe.magenta = new COLORREF(r, g, b);
                break;

            case ConsoleColor.Yellow:
                csbe.yellow = new COLORREF(r, g, b);
                break;

            case ConsoleColor.White:
                csbe.white = new COLORREF(r, g, b);
                break;
            }

            this.SetBufferInfo(hConsoleOutput, csbe);
        }