Exemplo n.º 1
0
        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");
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        /// <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();
            }
        }
Exemplo n.º 7
0
 private static void PutBlock(short Top, short Left, ForegroundColors Color) => WriteCharacter(Top, Left, Color, FULL_BLOCK);
Exemplo n.º 8
0
 public static void DrawBoundary(ForegroundColors Color) => TravelBoundary((i, j) => PutBlock(i, j, Color));
Exemplo n.º 9
0
 public static extern bool FillConsoleOutputAttribute(
     SafeFileHandle hConsoleOutput,
     ForegroundColors lpCharacter,
     int nLength,
     Coord dwWriteCoord,
     ref int lpumberOfCharsWritten);
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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");
            }
        }