public static void WriteLine(string text, ForegroundColors foreColor, BackgroundColors backColor) { var stdout = GetStdHandle(Constants.STD_OUTPUT_HANDLE); if (stdout == Constants.INVALID_HANDLE_VALUE) { throw new System.Exception("Unable to get standard output handle"); } if (!GetConsoleScreenBufferInfo(stdout, out csbi)) { throw new System.Exception("Unable to get existing console settings"); } if (!SetConsoleTextAttribute(stdout, (ushort)((ushort)foreColor | (ushort)backColor))) { throw new System.Exception("Unable to set console colors"); } System.Console.WriteLine(text); if (!SetConsoleTextAttribute(stdout, csbi.wAttributes)) { throw new System.Exception("Unable to restore normal console colors"); } }
private static void WriteCharacter(short Top, short Left, ForegroundColors Color, int Block) { SafeFileHandle ConsoleHandle = CreateFile("CONOUT$", 0x40000000, 2, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero); FillConsoleOutputAttribute(ConsoleHandle, Color, 1, new Coord(Top, Left), ref RefHandle); WriteConsoleOutputCharacter(ConsoleHandle, new string((char)Block, 1), 1, new Coord(Top, Left), ref RefHandle); }
public ConsoleColor GetColorOrDefault(char key) { // TODO: Potentially abstract the default values to a static instance // Check null if (ForegroundColors == null) { return(ConsoleColor.White); } // Check if entry exists return(ForegroundColors.TryGetValue(key, out var output) ? output : ConsoleColor.White); }
public ColorRulesViewModel(MainViewModel mainViewModel) { MainViewModel = mainViewModel; _ForegroundColors = new ObservableCollection <SwatchViewModel>(); _BackgroundColors = new ObservableCollection <SwatchViewModel>(); ForegroundColors.Add(new SwatchViewModel(MainViewModel, new Swatch(Colors.Red))); ForegroundColors.Add(new SwatchViewModel(MainViewModel, new Swatch(Colors.Green))); ForegroundColors.Add(new SwatchViewModel(MainViewModel, new Swatch(Colors.Blue))); BackgroundColors.Add(new SwatchViewModel(MainViewModel, new Swatch(Colors.Yellow))); BackgroundColors.Add(new SwatchViewModel(MainViewModel, new Swatch(Colors.Purple))); BackgroundColors.Add(new SwatchViewModel(MainViewModel, new Swatch(Colors.Silver))); Interval = 1; }
public static void WriteLine(string text, ForegroundColors foreColor) { System.IntPtr stdout = GetStdHandle(Constants.STD_OUTPUT_HANDLE); if (stdout == Constants.INVALID_HANDLE_VALUE) { throw new System.Exception("Unable to get standard output handle."); } if (!GetConsoleScreenBufferInfo(stdout, out csbi)) { throw new System.Exception("Unable to get existing console settings"); } BackgroundColors defaultBackground = (BackgroundColors)(csbi.wAttributes & 0xF0); System.Console.WriteLine(text, foreColor, defaultBackground); }
/// <inheritdoc /> public override void Write(LogInfo logInfo, string messageTemplate, params object[] logParameters) { if (!BackgroundColors.TryGetValue(logInfo.LogLevel, out var backgroundColor)) { backgroundColor = ConsoleColor.Black; } if (!ForegroundColors.TryGetValue(logInfo.LogLevel, out var foregroundColor)) { foregroundColor = ConsoleColor.White; } // Make sure the colors don't mix, as the write is not atomic. lock (_lock) { Console.BackgroundColor = backgroundColor; Console.ForegroundColor = foregroundColor; Console.Write(Format(logInfo, messageTemplate, logParameters)); Console.ResetColor(); } }
private static void PutBlock(short Top, short Left, ForegroundColors Color) => WriteCharacter(Top, Left, Color, FULL_BLOCK);
public static void DrawBoundary(ForegroundColors Color) => TravelBoundary((i, j) => PutBlock(i, j, Color));
public static extern bool FillConsoleOutputAttribute( SafeFileHandle hConsoleOutput, ForegroundColors lpCharacter, int nLength, Coord dwWriteCoord, ref int lpumberOfCharsWritten);
public static void WriteLine(string text, ForegroundColors foreColor) { System.IntPtr stdout = GetStdHandle(Constants.STD_OUTPUT_HANDLE); if (stdout == Constants.INVALID_HANDLE_VALUE) { throw new System.Exception("Unable to get standard output handle."); } if (!GetConsoleScreenBufferInfo(stdout, out csbi)) { throw new System.Exception("Unable to get existing console settings"); } BackgroundColors defaultBackground = (BackgroundColors) (csbi.wAttributes & 0xF0); System.Console.WriteLine(text, foreColor, defaultBackground); }
public static void WriteLine(string text, ForegroundColors foreColor, BackgroundColors backColor) { var stdout = GetStdHandle(Constants.STD_OUTPUT_HANDLE); if (stdout == Constants.INVALID_HANDLE_VALUE) { throw new System.Exception("Unable to get standard output handle"); } if (!GetConsoleScreenBufferInfo(stdout, out csbi)) { throw new System.Exception("Unable to get existing console settings"); } if (!SetConsoleTextAttribute(stdout, (ushort) ((ushort) foreColor | (ushort) backColor))) { throw new System.Exception("Unable to set console colors"); } System.Console.WriteLine(text); if (!SetConsoleTextAttribute(stdout, csbi.wAttributes)) { throw new System.Exception("Unable to restore normal console colors"); } }