/// <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); }
/// <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); }
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); }