public static ConsolePalette GetDefaultPalette() { if (_readDefPalette) { return(_defPalette); } //For whatever reason, System.Console stores the default console colors privately. I would rather use reflection //instead of Win32Native, so we're going with this //Calling GetBufferInfo makes sure the private values we need in Console are set. This method handles lazy evaluation used to populate some //private variables, so it's perfectly safe for us to call. We could also check _haveReadDefaultColors to see if we actually need to do this, //but we would end up using this anyway if that's false, so we're saving on reflection. //We're looking for the method with no parameters typeof(Console).GetMethod("GetBufferInfo", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { }, null).Invoke(null, null); //The private field we need is now set, so we can check the value safely byte dwColors = (byte)typeof(Console).GetField("_defaultColors", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); //Convert the value into 4 bit colors, then cache the value so we never have to do this again... _defPalette = new ConsolePalette((ConsoleColor)(dwColors & 15), (ConsoleColor)((dwColors & 240) >> 4)); _readDefPalette = true; return(_defPalette); }
public static void WithColorScheme(ConsolePalette scheme, Action task) { var temp = ConsolePalette.GetCurrent(); scheme.Apply(); task(); temp.Apply(); }
public ConsoleLayoutComponent(Rectangle bounds, ConsolePalette colors) { _colors = colors; _bounds = bounds; Refresh(); }
public SelectableLabel(string text, Rectangle bounds, ConsolePalette normal, ConsolePalette selected) : base(bounds, normal) { _text = text; _selectedColor = selected; Refresh(); }