public void Render (IConsoleBufferSource buffer)
        {
            if (buffer == null)
                throw new ArgumentNullException(nameof(buffer));
            ConsoleColor currentForeColor = Console.ForegroundColor, oldForeColor = currentForeColor;
            ConsoleColor currentBackColor = Console.BackgroundColor, oldBackColor = currentBackColor;
            bool isManualWrap = buffer.Width < Console.BufferWidth;
            try {
                for (int iy = 0; iy < buffer.Height; iy++) {
                    ConsoleChar[] charsLine = buffer.GetLine(iy);

                    for (int ix = 0; ix < buffer.Width; ix++) {
                        ConsoleChar chr = charsLine[ix];
                        ConsoleColor foreColor = ColorOverride ?? chr.ForegroundColor;
                        if (foreColor != currentForeColor)
                            Console.ForegroundColor = currentForeColor = foreColor;
                        ConsoleColor backColor = BackgroundOverride ?? chr.BackgroundColor;
                        if (backColor != currentBackColor)
                            Console.BackgroundColor = currentBackColor = backColor;
                        Console.Write(chr.HasChar || chr.LineChar.IsEmpty() ? chr.PrintableChar : buffer.GetLineChar(ix, iy));
                    }
                    if (isManualWrap)
                        Console.WriteLine();
                }
            }
            finally {
                Console.ForegroundColor = oldForeColor;
                Console.BackgroundColor = oldBackColor;
            }
        }
示例#2
0
        protected override void RenderOverride (IConsoleBufferSource buffer)
        {
            ThrowIfDisposed();
            if (buffer == null)
                throw new ArgumentNullException(nameof(buffer));

            ConsoleColor currentForeColor = (ConsoleColor)int.MaxValue;
            ConsoleColor currentBackColor = (ConsoleColor)int.MaxValue;

            Writer.Write("\x1B[0m");

            for (int iy = 0; iy < buffer.Height; iy++) {
                ConsoleChar[] charsLine = buffer.GetLine(iy);

                for (int ix = 0; ix < buffer.Width; ix++) {
                    ConsoleChar chr = charsLine[ix];
                    ConsoleColor foreColor = ColorOverride ?? chr.ForegroundColor;
                    ConsoleColor backColor = BackgroundOverride ?? chr.BackgroundColor;
                    if (foreColor != currentForeColor || backColor != currentBackColor) {
                        Writer.Write("\x1B[");
                        Writer.Write(ColorMap[(int)foreColor]);
                        Writer.Write(";");
                        Writer.Write(BackgroundColorMap[(int)backColor]);
                        Writer.Write("m");
                        currentForeColor = foreColor;
                        currentBackColor = backColor;
                    }
                    Writer.Write(chr.HasChar || chr.LineChar.IsEmpty() ? chr.PrintableChar : buffer.GetLineChar(ix, iy));
                }
                Writer.WriteLine();
            }
        }
        protected override void RenderOverride(IConsoleBufferSource buffer)
        {
            ThrowIfDisposed();
            Debug.Assert(Writer != null);
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            ConsoleColor currentForeColor = (ConsoleColor)int.MaxValue;
            ConsoleColor currentBackColor = (ConsoleColor)int.MaxValue;

            if (!BodyOnly)
            {
                Writer.Write($@"<!DOCTYPE html>
                    <html>
                    <head>
                      <meta charset=""{Writer.Encoding.WebName}"">
                      <title>{WebUtility.HtmlEncode(PageTitle)}</title>
                      <style>
                        pre {{ font: {Font} }}
                      </style>
                    </head>
                    <body>
                    ".Replace("\n                    ", "\n"));
            }

            Writer.Write("<pre><span>");

            for (int iy = 0; iy < buffer.Height; iy++)
            {
                ConsoleChar[] charsLine = buffer.GetLine(iy);

                for (int ix = 0; ix < buffer.Width; ix++)
                {
                    ConsoleChar  chr       = charsLine[ix];
                    ConsoleColor foreColor = ColorOverride ?? chr.ForegroundColor;
                    ConsoleColor backColor = BackgroundOverride ?? chr.BackgroundColor;
                    if (foreColor != currentForeColor || backColor != currentBackColor)
                    {
                        Writer.Write($"</span><span style=\"color:#{ColorMap[(int)foreColor]};background:#{ColorMap[(int)backColor]}\">");
                        currentForeColor = foreColor;
                        currentBackColor = backColor;
                    }
                    char c = chr.HasChar || chr.LineChar.IsEmpty ? chr.PrintableChar : buffer.GetLineChar(ix, iy);
                    Writer.Write(WebUtility.HtmlEncode(c.ToString()));
                }

                Writer.Write("<br/>");
            }

            Writer.Write("</pre>");
            if (!BodyOnly)
            {
                Writer.Write("\n</body>\n</html>");
            }
        }
示例#4
0
        protected override void RenderOverride (IConsoleBufferSource buffer)
        {
            ThrowIfDisposed();
            if (buffer == null)
                throw new ArgumentNullException(nameof(buffer));

            for (int iy = 0; iy < buffer.Height; iy++) {
                ConsoleChar[] charsLine = buffer.GetLine(iy);
                for (int ix = 0; ix < buffer.Width; ix++) {
                    ConsoleChar chr = charsLine[ix];
                    Writer.Write(chr.HasChar || chr.LineChar.IsEmpty() ? chr.PrintableChar : buffer.GetLineChar(ix, iy));
                }
                Writer.WriteLine();
            }
        }
示例#5
0
        protected static void RenderToCanvas([NotNull] IConsoleBufferSource buffer, WpfCanvas linesPanel, WpfSize charSize)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            ConsoleColor currentForeColor = (ConsoleColor)int.MaxValue;
            ConsoleColor currentBackColor = (ConsoleColor)int.MaxValue;
            TextBlock    text             = null;

            for (int iy = 0; iy < buffer.Height; iy++)
            {
                ConsoleChar[] charsLine = buffer.GetLine(iy);
                for (int ix = 0; ix < buffer.Width; ix++)
                {
                    ConsoleChar  chr       = charsLine[ix];
                    ConsoleColor foreColor = chr.ForegroundColor;
                    ConsoleColor backColor = chr.BackgroundColor;
                    if (text == null || foreColor != currentForeColor || backColor != currentBackColor)
                    {
                        currentForeColor = foreColor;
                        currentBackColor = backColor;
                        AppendTextBlockIfNeeded();
                        text = new TextBlock {
                            Foreground = ConsoleBrushes[foreColor],
                            Background = ConsoleBrushes[backColor],
                            Height     = charSize.Height,
                        };
                        WpfCanvas.SetLeft(text, ix * charSize.Width);
                        WpfCanvas.SetTop(text, iy * charSize.Height);
                    }
                    text.Text += chr.HasChar || chr.LineChar.IsEmpty() ? chr.PrintableChar : buffer.GetLineChar(ix, iy);
                }
                AppendTextBlockIfNeeded();
            }
            AppendTextBlockIfNeeded();

            void AppendTextBlockIfNeeded()
            {
                if (text == null)
                {
                    return;
                }
                text.Width = text.Text.Length * charSize.Width;
                linesPanel.Children.Add(text);
                text = null;
            }
        }
        public void Render(IConsoleBufferSource buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            ConsoleColor currentForeColor = Console.ForegroundColor, oldForeColor = currentForeColor;
            ConsoleColor currentBackColor = Console.BackgroundColor, oldBackColor = currentBackColor;
            bool         isManualWrap;

            try {
                isManualWrap = buffer.Width < Console.BufferWidth;
            }
            catch (IOException) {
                isManualWrap = true;
            }
            try {
                for (int iy = 0; iy < buffer.Height; iy++)
                {
                    ConsoleChar[] charsLine = buffer.GetLine(iy);

                    for (int ix = 0; ix < buffer.Width; ix++)
                    {
                        ConsoleChar  chr       = charsLine[ix];
                        ConsoleColor foreColor = ColorOverride ?? chr.ForegroundColor;
                        if (foreColor != currentForeColor)
                        {
                            Console.ForegroundColor = currentForeColor = foreColor;
                        }
                        ConsoleColor backColor = BackgroundOverride ?? chr.BackgroundColor;
                        if (backColor != currentBackColor)
                        {
                            Console.BackgroundColor = currentBackColor = backColor;
                        }
                        Console.Write(chr.HasChar || chr.LineChar.IsEmpty() ? chr.PrintableChar : buffer.GetLineChar(ix, iy));
                    }
                    if (isManualWrap)
                    {
                        Console.WriteLine();
                    }
                }
            }
            finally {
                Console.ForegroundColor = oldForeColor;
                Console.BackgroundColor = oldBackColor;
            }
        }
示例#7
0
        protected override void RenderOverride (IConsoleBufferSource buffer)
        {
            ThrowIfDisposed();
            if (buffer == null)
                throw new ArgumentNullException(nameof(buffer));

            ConsoleColor currentForeColor = (ConsoleColor)int.MaxValue;
            ConsoleColor currentBackColor = (ConsoleColor)int.MaxValue;

            if (!BodyOnly) {
                Writer.Write("<!DOCTYPE html>\n<html>\n<head>\n  <meta charset=\"");
                Writer.Write(Writer.Encoding.WebName);
                Writer.Write("\">\n  <title>");
                Writer.Write(WebUtility.HtmlEncode(PageTitle));
                Writer.Write("</title>\n  <style>\n    pre { font: ");
                Writer.Write(Font);
                Writer.Write(" }\n  </style>\n</head>\n<body>\n");
            }

            Writer.Write("<pre><span>");

            for (int iy = 0; iy < buffer.Height; iy++) {
                ConsoleChar[] charsLine = buffer.GetLine(iy);

                for (int ix = 0; ix < buffer.Width; ix++) {
                    ConsoleChar chr = charsLine[ix];
                    ConsoleColor foreColor = ColorOverride ?? chr.ForegroundColor;
                    ConsoleColor backColor = BackgroundOverride ?? chr.BackgroundColor;
                    if (foreColor != currentForeColor || backColor != currentBackColor) {
                        Writer.Write($"</span><span style=\"color:#{ColorMap[(int)foreColor]};background:#{ColorMap[(int)backColor]}\">");
                        currentForeColor = foreColor;
                        currentBackColor = backColor;
                    }
                    char c = chr.HasChar || chr.LineChar.IsEmpty() ? chr.PrintableChar : buffer.GetLineChar(ix, iy);
                    Writer.Write(WebUtility.HtmlEncode(c.ToString()));
                }

                Writer.Write("<br/>");
            }

            Writer.Write("</pre>");
            if (!BodyOnly)
                Writer.Write("\n</body>\n</html>");
        }
        protected override void RenderOverride(IConsoleBufferSource buffer)
        {
            ThrowIfDisposed();
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            for (int iy = 0; iy < buffer.Height; iy++)
            {
                ConsoleChar[] charsLine = buffer.GetLine(iy);
                for (int ix = 0; ix < buffer.Width; ix++)
                {
                    ConsoleChar chr = charsLine[ix];
                    Writer.Write(chr.HasChar || chr.LineChar.IsEmpty() ? chr.PrintableChar : buffer.GetLineChar(ix, iy));
                }
                Writer.WriteLine();
            }
        }
示例#9
0
        protected override void RenderOverride(IConsoleBufferSource buffer)
        {
            ThrowIfDisposed();
            Debug.Assert(Writer != null);
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            ConsoleColor currentForeColor = (ConsoleColor)int.MaxValue;
            ConsoleColor currentBackColor = (ConsoleColor)int.MaxValue;

            Writer.Write("\x1B[0m");

            for (int iy = 0; iy < buffer.Height; iy++)
            {
                ConsoleChar[] charsLine = buffer.GetLine(iy);

                for (int ix = 0; ix < buffer.Width; ix++)
                {
                    ConsoleChar  chr       = charsLine[ix];
                    ConsoleColor foreColor = ColorOverride ?? chr.ForegroundColor;
                    ConsoleColor backColor = BackgroundOverride ?? chr.BackgroundColor;
                    if (foreColor != currentForeColor || backColor != currentBackColor)
                    {
                        Writer.Write("\x1B[");
                        Writer.Write(ColorMap[(int)foreColor]);
                        Writer.Write(";");
                        Writer.Write(BackgroundColorMap[(int)backColor]);
                        Writer.Write("m");
                        currentForeColor = foreColor;
                        currentBackColor = backColor;
                    }
                    Writer.Write(chr.HasChar || chr.LineChar.IsEmpty ? chr.PrintableChar : buffer.GetLineChar(ix, iy));
                }
                Writer.WriteLine();
            }
        }
示例#10
0
        protected void RenderToFlowDocument(IConsoleBufferSource buffer, [NotNull] FlowDocument document)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            var par = new Paragraph {
                Background    = Background,
                FontFamily    = FontFamily,
                FontSize      = FontSize,
                FontStretch   = FontStretch,
                FontStyle     = FontStyle,
                FontWeight    = FontWeight,
                TextAlignment = System.Windows.TextAlignment.Left,
            };

            document.Blocks.Add(par);

            ConsoleColor currentForeColor = (ConsoleColor)int.MaxValue;
            ConsoleColor currentBackColor = (ConsoleColor)int.MaxValue;
            Run          text             = null;

            for (int iy = 0; iy < buffer.Height; iy++)
            {
                ConsoleChar[] charsLine = buffer.GetLine(iy);
                for (int ix = 0; ix < buffer.Width; ix++)
                {
                    ConsoleChar  chr       = charsLine[ix];
                    ConsoleColor foreColor = chr.ForegroundColor;
                    ConsoleColor backColor = chr.BackgroundColor;
                    if (text == null || foreColor != currentForeColor || backColor != currentBackColor)
                    {
                        currentForeColor = foreColor;
                        currentBackColor = backColor;
                        AppendRunIfNeeded();
                        text = new Run {
                            Foreground = ConsoleBrushes[foreColor],
                            Background = ConsoleBrushes[backColor],
                        };
                    }
                    text.Text += chr.HasChar || chr.LineChar.IsEmpty() ? chr.PrintableChar : buffer.GetLineChar(ix, iy);
                }
                AppendRunIfNeeded();
                if (iy + 1 < buffer.Height)
                {
                    par.Inlines.Add(new LineBreak());
                }
            }
            AppendRunIfNeeded();

            void AppendRunIfNeeded()
            {
                if (text == null)
                {
                    return;
                }
                par.Inlines.Add(text);
                text = null;
            }
        }