Exemple #1
0
        public static void WriteANSIString(ANSIString String, Point?p = null, ConsoleColor?background = null, ConsoleColor?foreground = null)
        {
            CursorChanger cursor = null;

            if (p.HasValue)
            {
                cursor = new CursorChanger(p);
            }

            using (var color = new ColorChanger(background, foreground))
            {
                var oldBack = Console.BackgroundColor;
                var oldFore = Console.ForegroundColor;

                ConsoleColor?lastBack = null, lastFore = null;

                foreach (var ansichar in String as IEnumerable <ANSIString.ANSIChar> )
                {
                    if (lastBack != ansichar.BackgroundColor)
                    {
                        lastBack = ansichar.BackgroundColor;
                        if (lastBack.HasValue)
                        {
                            Console.BackgroundColor = lastBack.Value;
                        }
                        else
                        {
                            Console.BackgroundColor = oldBack;
                        }
                    }
                    if (lastFore != ansichar.ForegroundColor)
                    {
                        lastFore = ansichar.ForegroundColor;
                        if (lastFore.HasValue)
                        {
                            Console.ForegroundColor = lastFore.Value;
                        }
                        else
                        {
                            Console.ForegroundColor = oldFore;
                        }
                    }

                    Console.Write(ansichar.UnicodeChar);
                }
            }

            if (cursor != null)
            {
                cursor.Dispose();
            }
        }
Exemple #2
0
        public void Render()
        {
            lock (Application.DrawLock)
            {
                NeedsRender = false;
                Graphics.DrawLine(new Point(0, ConsoleHelper.Size.Height - 1), new Size(ConsoleHelper.Size.Width - 1, 0), ' ');

                Console.SetCursorPosition(Cursor, ConsoleHelper.Size.Height - 1);
                using (var cur = new CursorChanger(new Point(0, ConsoleHelper.Size.Height - 1)))
                    using (var col = new ColorChanger(foreground: ConsoleColor.White))
                    {
                        Graphics.WriteANSIString(new ANSIString(_Content.ToString()));
                    }
                Console.ForegroundColor = ConsoleColor.Gray;
            }
        }