public void DrawVerticalLineCapFull()
        {
            var buffer = new ConsoleBuffer(4);

            buffer.DrawVerticalLine(0, 0, 5, Red, LineWidth.Single, DrawLineFlags.CapFull);
            buffer.DrawVerticalLine(1, 1, 3, Green, LineWidth.Single, DrawLineFlags.CapFull);
            buffer.DrawVerticalLine(3, -1, 10, Blue, LineWidth.Double, DrawLineFlags.CapFull);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar {
                LineChar = LineCharVertical, ForegroundColor = Red
            };
            var cg = new ConsoleChar {
                LineChar = LineCharVertical, ForegroundColor = Green
            };
            var cb = new ConsoleChar {
                LineChar = LineCharVerticalDouble, ForegroundColor = Blue
            };

            buffer.GetLine(0).Should().Equal(cr, c0, c0, cb);
            buffer.GetLine(1).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(2).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(3).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(4).Should().Equal(cr, c0, c0, cb);
        }
Beispiel #2
0
        public void DrawVerticalLine()
        {
            var buffer = new ConsoleBuffer(4);

            buffer.DrawVerticalLine(0, 0, 5, Red);
            buffer.DrawVerticalLine(1, 1, 3, Green);
            buffer.DrawVerticalLine(3, -1, 10, Blue, LineWidth.Wide);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar {
                LineChar = LineChar.Vertical, ForegroundColor = Red
            };
            var cg = new ConsoleChar {
                LineChar = LineChar.Vertical, ForegroundColor = Green
            };
            var cb = new ConsoleChar {
                LineChar = LineChar.Vertical | LineChar.VerticalWide, ForegroundColor = Blue
            };

            buffer.GetLine(0).Should().Equal(cr, c0, c0, cb);
            buffer.GetLine(1).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(2).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(3).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(4).Should().Equal(cr, c0, c0, cb);
        }
Beispiel #3
0
 public override void Render (ConsoleBuffer buffer)
 {
     base.Render(buffer);
     if (Orientation == Orientation.Vertical)
         buffer.DrawVerticalLine(0, 0, RenderSize.Height, EffectiveColor, Stroke);
     else
         buffer.DrawHorizontalLine(0, 0, RenderSize.Width, EffectiveColor, Stroke);
 }
        public void DrawVerticalLineCapCenter()
        {
            var buffer = new ConsoleBuffer(4);

            buffer.DrawVerticalLine(0, 0, 5, Red, LineWidth.Single, DrawLineFlags.CapCenter);
            buffer.DrawVerticalLine(1, 1, 3, Green, LineWidth.Single, DrawLineFlags.CapStartCenter);
            buffer.DrawVerticalLine(2, 2, 2, Blue, LineWidth.Double, DrawLineFlags.CapEndCenter);
            buffer.DrawVerticalLine(3, -1, 10, Blue, LineWidth.Double, DrawLineFlags.CapCenter);

            var c0m = new ConsoleChar();
            var crs = new ConsoleChar {
                LineChar = LineCharBottom(LineWidth.Single), ForegroundColor = Red
            };
            var crm = new ConsoleChar {
                LineChar = LineCharVertical, ForegroundColor = Red
            };
            var cre = new ConsoleChar {
                LineChar = LineCharTop(LineWidth.Single), ForegroundColor = Red
            };
            var cgs = new ConsoleChar {
                LineChar = LineCharBottom(LineWidth.Single), ForegroundColor = Green
            };
            var cgm = new ConsoleChar {
                LineChar = LineCharVertical, ForegroundColor = Green
            };
            var cge = new ConsoleChar {
                LineChar = LineChar.None, ForegroundColor = Green
            };
            var cbs = new ConsoleChar {
                LineChar = LineChar.None, ForegroundColor = Blue
            };
            var cbm = new ConsoleChar {
                LineChar = LineCharVerticalDouble, ForegroundColor = Blue
            };
            var cbe = new ConsoleChar {
                LineChar = LineCharTop(LineWidth.Double), ForegroundColor = Blue
            };

            buffer.GetLine(0).Should().Equal(crs, c0m, c0m, cbm);
            buffer.GetLine(1).Should().Equal(crm, cgs, c0m, cbm);
            buffer.GetLine(2).Should().Equal(crm, cgm, cbs, cbm);
            buffer.GetLine(3).Should().Equal(crm, cge, cbe, cbm);
            buffer.GetLine(4).Should().Equal(cre, c0m, c0m, cbm);
        }
Beispiel #5
0
        public void BoxLineCharRendererSimple()
        {
            var buffer = new ConsoleBuffer(6)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 1, 6, null, LineWidth.Double);
            buffer.DrawHorizontalLine(1, 3, 4);
            buffer.DrawVerticalLine(2, 0, 5);
            buffer.DrawVerticalLine(4, 1, 3, null, LineWidth.Double);

            GetRenderedText(buffer).Should().BeLines(
                "  │   ",
                "══╪═╦═",
                "  │ ║ ",
                " ─┼─╜ ",
                "  │   ");
        }
Beispiel #6
0
        public void BoxLineCharRendererLines()
        {
            var buffer = new ConsoleBuffer(3)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 3);
            buffer.DrawHorizontalLine(0, 2, 3, null, LineWidth.Double);
            buffer.DrawVerticalLine(0, 0, 1);
            buffer.DrawVerticalLine(2, 0, 1, null, LineWidth.Double);
            buffer.DrawVerticalLine(0, 2, 1);
            buffer.DrawVerticalLine(2, 2, 1, null, LineWidth.Double);

            GetRenderedText(buffer).Should().BeLines(
                "├─╢",
                "   ",
                "╞═╣");
        }
Beispiel #7
0
        public void CharLineCharRendererSimple()
        {
            var buffer = new ConsoleBuffer(6)
            {
                LineCharRenderer = LineCharRenderer.Char('*')
            };

            buffer.DrawHorizontalLine(0, 1, 6, null, LineWidth.Double);
            buffer.DrawHorizontalLine(1, 3, 4);
            buffer.DrawVerticalLine(2, 0, 5);
            buffer.DrawVerticalLine(4, 1, 3, null, LineWidth.Double);

            GetRenderedText(buffer).Should().BeLines(
                "  *   ",
                "******",
                "  * * ",
                " **** ",
                "  *   ");
        }
        public void DrawVerticalLine ()
        {
            var buffer = new ConsoleBuffer(4);

            buffer.DrawVerticalLine(0, 0, 5, Red);
            buffer.DrawVerticalLine(1, 1, 3, Green);
            buffer.DrawVerticalLine(3, -1, 10, Blue, LineWidth.Wide);

            var c0 = new ConsoleChar();
            var cr = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Red };
            var cg = new ConsoleChar { LineChar = LineChar.Vertical, ForegroundColor = Green };
            var cb = new ConsoleChar { LineChar = LineChar.Vertical | LineChar.VerticalWide, ForegroundColor = Blue };

            buffer.GetLine(0).Should().Equal(cr, c0, c0, cb);
            buffer.GetLine(1).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(2).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(3).Should().Equal(cr, cg, c0, cb);
            buffer.GetLine(4).Should().Equal(cr, c0, c0, cb);
        }
Beispiel #9
0
        public void SimpleLineCharRendererSimple()
        {
            var buffer = new ConsoleBuffer(6)
            {
                LineCharRenderer = LineCharRenderer.Simple
            };

            buffer.DrawHorizontalLine(0, 1, 6, null, LineWidth.Double);
            buffer.DrawHorizontalLine(1, 3, 4);
            buffer.DrawVerticalLine(2, 0, 5);
            buffer.DrawVerticalLine(4, 1, 3, null, LineWidth.Double);

            GetRenderedText(buffer).Should().BeLines(
                "  |   ",
                "==+=+=",
                "  | | ",
                " -+-+ ",
                "  |   ");
        }
Beispiel #10
0
 protected override void RenderOverride(ConsoleBuffer buffer)
 {
     base.RenderOverride(buffer);
     if (Orientation == Orientation.Vertical)
     {
         buffer.DrawVerticalLine(0, 0, RenderSize.Height, EffectiveColor, Stroke);
     }
     else
     {
         buffer.DrawHorizontalLine(0, 0, RenderSize.Width, EffectiveColor, Stroke);
     }
 }
Beispiel #11
0
        public void BoxLineCharRendererBox2x2Single()
        {
            var buffer = new ConsoleBuffer(5)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 5);
            buffer.DrawHorizontalLine(0, 2, 5);
            buffer.DrawHorizontalLine(0, 4, 5);
            buffer.DrawVerticalLine(0, 0, 5);
            buffer.DrawVerticalLine(2, 0, 5);
            buffer.DrawVerticalLine(4, 0, 5);

            GetRenderedText(buffer).Should().BeLines(
                "┌─┬─┐",
                "│ │ │",
                "├─┼─┤",
                "│ │ │",
                "└─┴─┘");
        }
Beispiel #12
0
        public void BoxLineCharRendererBox2x2MixedAlt()
        {
            var buffer = new ConsoleBuffer(5)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 5);
            buffer.DrawHorizontalLine(0, 2, 5, null, LineWidth.Double);
            buffer.DrawHorizontalLine(0, 4, 5);
            buffer.DrawVerticalLine(0, 0, 5, null, LineWidth.Double);
            buffer.DrawVerticalLine(2, 0, 5);
            buffer.DrawVerticalLine(4, 0, 5, null, LineWidth.Double);

            GetRenderedText(buffer).Should().BeLines(
                "╓─┬─╖",
                "║ │ ║",
                "╠═╪═╣",
                "║ │ ║",
                "╙─┴─╜");
        }
Beispiel #13
0
        public void BoxLineCharRendererBox2x2Mixed()
        {
            var buffer = new ConsoleBuffer(5)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 5, null, LineWidth.Double);
            buffer.DrawHorizontalLine(0, 2, 5);
            buffer.DrawHorizontalLine(0, 4, 5, null, LineWidth.Double);
            buffer.DrawVerticalLine(0, 0, 5);
            buffer.DrawVerticalLine(2, 0, 5, null, LineWidth.Double);
            buffer.DrawVerticalLine(4, 0, 5);

            GetRenderedText(buffer).Should().BeLines(
                "╒═╦═╕",
                "│ ║ │",
                "├─╫─┤",
                "│ ║ │",
                "╘═╩═╛");
        }
Beispiel #14
0
        public void BoxLineCharRendererBox2x2Double()
        {
            var buffer = new ConsoleBuffer(5)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 5, null, LineWidth.Double);
            buffer.DrawHorizontalLine(0, 2, 5, null, LineWidth.Double);
            buffer.DrawHorizontalLine(0, 4, 5, null, LineWidth.Double);
            buffer.DrawVerticalLine(0, 0, 5, null, LineWidth.Double);
            buffer.DrawVerticalLine(2, 0, 5, null, LineWidth.Double);
            buffer.DrawVerticalLine(4, 0, 5, null, LineWidth.Double);

            GetRenderedText(buffer).Should().BeLines(
                "╔═╦═╗",
                "║ ║ ║",
                "╠═╬═╣",
                "║ ║ ║",
                "╚═╩═╝");
        }
        public void BoxLineCharRendererPixels()
        {
            var buffer = new ConsoleBuffer(3)
            {
                LineCharRenderer = LineCharRenderer.Box
            };

            buffer.DrawHorizontalLine(0, 0, 1);
            buffer.DrawHorizontalLine(2, 0, 1);
            buffer.DrawHorizontalLine(0, 2, 1, null, LineWidth.Wide);
            buffer.DrawHorizontalLine(2, 2, 1, null, LineWidth.Wide);
            buffer.DrawVerticalLine(0, 0, 1);
            buffer.DrawVerticalLine(2, 0, 1, null, LineWidth.Wide);
            buffer.DrawVerticalLine(0, 2, 1);
            buffer.DrawVerticalLine(2, 2, 1, null, LineWidth.Wide);

            GetRenderedText(buffer).Should().BeLines(
                "┼ ╫",
                "   ",
                "╪ ╬");
        }
Beispiel #16
0
        private void Run()
        {
            /*Size consoleSize = Size.Min(ConsoleRenderer.ConsoleLargestWindowSize, new Size((25 + 1) * 7 + 1, 60));
             * try {
             *  ConsoleRenderer.ConsoleWindowRect = new Rect(consoleSize);
             *  Console.BufferWidth = consoleSize.Width;
             * }
             * catch (Exception e) {
             *  var consoleRect = new Rect(Console.WindowLeft, Console.WindowTop, Console.WindowWidth, Console.WindowHeight);
             *  Console.WriteLine(consoleRect);
             *  var bufferRect = new Size(Console.BufferWidth, Console.BufferHeight);
             *  Console.WriteLine(bufferRect);
             *  Console.WriteLine(e.Message);
             * }*/
            Console.WindowWidth    = 80;
            Console.BufferWidth    = 80;
            Console.OutputEncoding = Encoding.UTF8;
            Console.Title          = Path.GetFileNameWithoutExtension(Console.Title);

            var data = new Data {
                Title           = "Header Title",
                SubTitle        = "Header SubTitle",
                Formatted       = "Aaaa\nBbbb\nCccc",
                LoremIpsum      = "Lo|rem ip|sum do|lor sit amet, con|sec|te|tur adi|pis|cing elit, sed do eius|mod tem|por in|ci|di|dunt ut la|bo|re et do|lo|re mag|na ali|qua. Ut enim ad mi|nim ve|ni|am, qu|is nos|trud exer|ci|ta|tion ul|lam|co la|bo|ris ni|si ut ali|quip ex ea com|mo|do con|se|quat. Du|is au|te iru|re do|lor in rep|re|hen|de|rit in vo|lup|ta|te ve|lit es|se cil|lum do|lo|re eu fu|gi|at nul|la pa|ri|a|tur. Ex|cep|te|ur sint oc|ca|e|cat cu|pi|da|tat non pro|i|dent, sunt in cul|pa qui of|fi|cia de|se|runt mol|lit anim id est la|bo|rum.",
                LoremIpsumShort = "Lo|rem ip|sum do|lor sit amet, con|sec|te|tur adi|pis|cing elit, sed do eius|mod tem|por in|ci|di|dunt ut la|bo|re et do|lo|re mag|na ali|qua. Ut enim ad mi|nim ve|ni|am, qu|is nos|trud exer|ci|ta|tion ul|lam|co la|bo|ris ni|si ut ali|quip ex ea com|mo|do con|se|quat.",
                Unicode         = "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽž",
                Guid            = Guid.NewGuid(),
                Date            = DateTime.Now,
                Items           = new List <DataItem> {
                    new DataItem {
                        Id       = 1, Name = "Name 1", Value = "Value 1",
                        SubItems = new List <DataItem> {
                            new DataItem {
                                Id = 11, Name = "Name 1.1", Value = "Value 1.1"
                            },
                            new DataItem {
                                Id = 12, Name = "Name 1.2", Value = "Value 1.2"
                            },
                        }
                    },
                    new DataItem {
                        Id       = 2, Name = "Name 2", Value = "Value 2",
                        SubItems = new List <DataItem> {
                            new DataItem {
                                Id = 21, Name = "Name 2.1", Value = "Value 2.1"
                            },
                            new DataItem {
                                Id = 22, Name = "Name 2.2", Value = "Value 2.2"
                            },
                        }
                    },
                },
                Roman = FigletFont.Load(GetType().Assembly.GetManifestResourceStream(GetType(), "Resources.Roman.flf")),
            };

            /*if (MemoryProfiler.IsActive) {
             *  MemoryProfiler.EnableAllocations();
             *  MemoryProfiler.Dump();
             * }
             * new ConsoleRenderer().RenderDocument(ReadXaml<Document>(data));
             * if (MemoryProfiler.IsActive)
             *  MemoryProfiler.Dump();*/
            /*for (int i = 0; i < 100; i++)
             *  new ConsoleRenderer().RenderDocument(ReadXaml<Document>(data));*/
            /*if (MemoryProfiler.IsActive)
             *  MemoryProfiler.Dump();*/

            Document xamlDoc = ConsoleRenderer.ReadDocumentFromResource(GetType(), "Markup.xaml", data, new XamlElementReaderSettings {
                ReferenceAssemblies = { typeof(FigletDiv).Assembly }
            });

            //Document xamlDoc = ConsoleRenderer.ReadDocumentFromResource(GetType().Assembly, "Alba.CsConsoleFormat.ConsoleTest.Markup.xaml", data);
            Console.WriteLine("\nXAML\n");
            ConsoleRenderer.RenderDocument(xamlDoc);
            ConsoleRenderer.RenderDocument(xamlDoc, new HtmlRenderTarget(File.Create("../Tmp/0.html"), new UTF8Encoding(false)));

            Document builtDoc = new ViewBuilder().CreateDocument(data);

            Console.WriteLine("\nBUILDER\n");
            ConsoleRenderer.RenderDocument(builtDoc);
            ConsoleRenderer.RenderDocument(builtDoc, new HtmlRenderTarget(File.Create("../Tmp/0a.html"), new UTF8Encoding(false)));

            Console.WriteLine("\nBUILDER FLUENT\n");
            ConsoleRenderer.RenderDocument(new ViewBuilder().CreateDocumentFluent(data));

            var buffer = new ConsoleBuffer(80)
            {
                LineCharRenderer = LineCharRenderer.BoxExtended,
                //Clip = new Rect(1, 1, 78, 30),
            };
            var rainbow = new[] {
                Black,
                DarkRed, DarkYellow, DarkGreen, DarkCyan, DarkBlue, DarkMagenta, DarkRed,
                Black,
                Red, Yellow, Green, Cyan, Blue, Magenta, Red,
            };

            /*for (int i = 0; i < 16; i++)
             *  buffer.FillRectangle((ConsoleColor)i, i, i, 80 - i * 2, 31 - i * 2);*/
            const LineWidth Thick = LineWidth.Heavy;

            for (int i = 0; i < rainbow.Length; i++)
            {
                buffer.FillBackgroundRectangle(i, i, 80 - i * 2, (rainbow.Length - i) * 2, rainbow[i]);
            }
            buffer.DrawHorizontalLine(1, 0, 78, White);
            buffer.DrawHorizontalLine(1, 1, 78, White, Thick);
            buffer.DrawHorizontalLine(3, 3, 7, White);
            buffer.DrawVerticalLine(1, 1, 9, White);
            buffer.DrawVerticalLine(2, 2, 4, White);
            buffer.DrawVerticalLine(5, 0, 6, White, Thick);
            buffer.DrawVerticalLine(5, 0, 6, White);
            buffer.DrawVerticalLine(6, 0, 6, White);
            buffer.DrawVerticalLine(3, 0, 12, White, Thick);
            buffer.DrawRectangle(0, 0, 80, 32, White, Thick);
            buffer.FillBackgroundVerticalLine(40, 0, 32, Yellow);
            buffer.FillForegroundVerticalLine(41, 0, 32, White, FullBlock);
            buffer.FillForegroundVerticalLine(42, 0, 32, White, DarkShade);
            buffer.FillForegroundVerticalLine(43, 0, 32, White, MediumShade);
            buffer.FillForegroundVerticalLine(44, 0, 32, White, LightShade);
            buffer.DrawString(15, 15, Black, "Hello world!");
            buffer.DrawString(15, 16, White, "Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!");
            //buffer.ApplyBackgroundColorMap(0, 0, buffer.Width, buffer.Height, ColorMaps.Invert);
            //buffer.ApplyForegroundColorMap(0, 0, buffer.Width, buffer.Height, ColorMaps.Invert);
            new ConsoleRenderTarget().Render(buffer);
            //new ConsoleRenderTarget { ColorOverride = White, BackgroundOverride = Black }.Render(buffer);

            Colors.WriteLine("Console without colors is boring...");
            Colors.WriteLine("Colors".Red(), " are".Green(), " fun!".Blue());
            Colors.WriteLine(
                "Background".Red().OnDarkRed(), "colors".Green().OnDarkGreen(), "are".Blue().OnDarkBlue(),
                "even".DarkRed().OnRed(), "more".DarkGreen().OnGreen(), "fun!".DarkBlue().OnBlue());
            Colors.WriteLine(new Border {
                Shadow   = new Thickness(-1, -1, 1, 1), ShadowColor = DarkGray,
                Align    = Align.Left,
                Children = { "Borders yay!".Yellow().OnGray() }
            });

            using (var file = File.Create("../Tmp/1.html"))
                new HtmlRenderTarget(file, new UTF8Encoding(false)).Render(buffer);
            using (var file = new StreamWriter(File.Create("../Tmp/1.ans"), Encoding.GetEncoding("ibm437"))
            {
                NewLine = ""
            })
                new AnsiRenderTarget(file).Render(buffer);
            using (var file = File.Create("../Tmp/1.txt"))
                new TextRenderTarget(file).Render(buffer);
            using (var file = File.Create("../Tmp/1.asc"))
                new TextRenderTarget(file, Encoding.GetEncoding("ibm437")).Render(buffer);

            /*var text = new TextRenderTarget();
             * text.Render(buffer);
             * Console.Write(text.OutputText);*/

            /*Console.WriteLine(Console.OutputEncoding);
             * Console.OutputEncoding = Encoding.UTF8;
             * Console.WriteLine("■▬▲►▼◄");
             * Console.WriteLine("▀▄█▌▐");
             * Console.WriteLine("♠♣♥♦");
             * Console.WriteLine("☺☻☼♀♂♫");
             * Console.WriteLine("«»‘’‚‛“”„‟‹›");*/
            /*const string TestString1 = "«»‘’‚‛“”„‟‹›", TestString2 = "─═│║┼╪╫╬";
             * foreach (EncodingInfo encodingInfo in Encoding.GetEncodings()) {
             *  try {
             *      Encoding encoding = encodingInfo.GetEncoding();
             *      bool matched1 = encoding.GetString(encoding.GetBytes(TestString1)) == TestString1;
             *      bool matched2 = encoding.GetString(encoding.GetBytes(TestString2)) == TestString2;
             *      Console.OutputEncoding = encoding;
             *      Console.WriteLine("{0,-10}{1,-20}{2}{3} {4} {5}",
             *          encodingInfo.CodePage, encodingInfo.Name, matched1 ? "+" : "-", matched2 ? "+" : "-", TestString1, TestString2);
             *  }
             *  catch {
             *      Console.WriteLine("{0,-10}{1,-20}xx FAILED",
             *          encodingInfo.CodePage, encodingInfo.Name);
             *  }
             * }*/
            /*for (int i = 1; i < 10000; i += 10) {
             *  var sb = new StringBuilder();
             *  for (int j = 0; j < 10; j++)
             *      sb.AppendFormat("{0,-6}{1} ", (i + j), (char)(i + j));
             *  Console.Write(sb);
             * }*/
        }
Beispiel #17
0
        private void Run ()
        {
            /*Size consoleSize = Size.Min(ConsoleRenderer.ConsoleLargestWindowSize, new Size((25 + 1) * 7 + 1, 60));
            try {
                ConsoleRenderer.ConsoleWindowRect = new Rect(consoleSize);
                Console.BufferWidth = consoleSize.Width;
            }
            catch (Exception e) {
                var consoleRect = new Rect(Console.WindowLeft, Console.WindowTop, Console.WindowWidth, Console.WindowHeight);
                Console.WriteLine(consoleRect);
                var bufferRect = new Size(Console.BufferWidth, Console.BufferHeight);
                Console.WriteLine(bufferRect);
                Console.WriteLine(e.Message);
            }*/
            Console.OutputEncoding = Encoding.UTF8;
            Console.Title = Path.GetFileNameWithoutExtension(Console.Title);

            var data = new Data {
                Title = "Header Title",
                SubTitle = "Header SubTitle",
                Formatted = "Aaaa\nBbbb\nCccc",
                LoremIpsum = "Lo|rem ip|sum do|lor sit amet, con|sec|te|tur adi|pis|cing elit, sed do eius|mod tem|por in|ci|di|dunt ut la|bo|re et do|lo|re mag|na ali|qua. Ut enim ad mi|nim ve|ni|am, qu|is nos|trud exer|ci|ta|tion ul|lam|co la|bo|ris ni|si ut ali|quip ex ea com|mo|do con|se|quat. Du|is au|te iru|re do|lor in rep|re|hen|de|rit in vo|lup|ta|te ve|lit es|se cil|lum do|lo|re eu fu|gi|at nul|la pa|ri|a|tur. Ex|cep|te|ur sint oc|ca|e|cat cu|pi|da|tat non pro|i|dent, sunt in cul|pa qui of|fi|cia de|se|runt mol|lit anim id est la|bo|rum.",
                LoremIpsumShort = "Lo|rem ip|sum do|lor sit amet, con|sec|te|tur adi|pis|cing elit, sed do eius|mod tem|por in|ci|di|dunt ut la|bo|re et do|lo|re mag|na ali|qua. Ut enim ad mi|nim ve|ni|am, qu|is nos|trud exer|ci|ta|tion ul|lam|co la|bo|ris ni|si ut ali|quip ex ea com|mo|do con|se|quat.",
                Guid = Guid.NewGuid(),
                Date = DateTime.Now,
                Items = new List<DataItem> {
                    new DataItem {
                        Id = 1, Name = "Name 1", Value = "Value 1",
                        SubItems = new List<DataItem> {
                            new DataItem { Id = 11, Name = "Name 1.1", Value = "Value 1.1" },
                            new DataItem { Id = 12, Name = "Name 1.2", Value = "Value 1.2" },
                        }
                    },
                    new DataItem { Id = 2, Name = "Name 2", Value = "Value 2" },
                }
            };

            /*if (MemoryProfiler.IsActive) {
                MemoryProfiler.EnableAllocations();
                MemoryProfiler.Dump();
            }
            new ConsoleRenderer().RenderDocument(ReadXaml<Document>(data));
            if (MemoryProfiler.IsActive)
                MemoryProfiler.Dump();*/
            /*for (int i = 0; i < 100; i++)
                new ConsoleRenderer().RenderDocument(ReadXaml<Document>(data));*/
            /*if (MemoryProfiler.IsActive)
                MemoryProfiler.Dump();*/

            Document xamlDoc = ConsoleRenderer.ReadDocumentFromResource(GetType(), "Markup.xaml", data);
            //Document xamlDoc = ConsoleRenderer.ReadDocumentFromResource(GetType().Assembly, "Alba.CsConsoleFormat.ConsoleTest.Markup.xaml", data);
            Console.WriteLine("XAML");
            ConsoleRenderer.RenderDocument(xamlDoc);
            ConsoleRenderer.RenderDocument(xamlDoc, new HtmlRenderTarget(File.Create(@"../../Tmp/0.html"), new UTF8Encoding(false)));

            Document builtDoc = new ViewBuilder().CreateDocument(data);
            Console.WriteLine("Builder");
            ConsoleRenderer.RenderDocument(builtDoc);
            ConsoleRenderer.RenderDocument(builtDoc, new HtmlRenderTarget(File.Create(@"../../Tmp/0a.html"), new UTF8Encoding(false)));

            var buffer = new ConsoleBuffer(80) {
                LineCharRenderer = LineCharRenderer.Box,
                //Clip = new Rect(1, 1, 78, 30),
            };
            var rainbow = new[] {
                Black,
                DarkRed, DarkYellow, DarkGreen, DarkCyan, DarkBlue, DarkMagenta, DarkRed,
                Black,
                Red, Yellow, Green, Cyan, Blue, Magenta, Red,
            };
            /*for (int i = 0; i < 16; i++)
                buffer.FillRectangle((ConsoleColor)i, i, i, 80 - i * 2, 31 - i * 2);*/
            for (int i = 0; i < rainbow.Length; i++)
                buffer.FillBackgroundRectangle(i, i, 80 - i * 2, (rainbow.Length - i) * 2, rainbow[i]);
            buffer.DrawHorizontalLine(1, 0, 78, White);
            buffer.DrawHorizontalLine(1, 1, 78, White, LineWidth.Wide);
            buffer.DrawHorizontalLine(3, 3, 7, White);
            buffer.DrawVerticalLine(1, 1, 9, White);
            buffer.DrawVerticalLine(2, 2, 4, White);
            buffer.DrawVerticalLine(5, 0, 6, White, LineWidth.Wide);
            buffer.DrawVerticalLine(5, 0, 6, White);
            buffer.DrawVerticalLine(6, 0, 6, White);
            buffer.DrawVerticalLine(3, 0, 12, White, LineWidth.Wide);
            buffer.DrawRectangle(0, 0, 80, 32, White, LineWidth.Wide);
            buffer.FillBackgroundVerticalLine(40, 0, 32, Yellow);
            buffer.FillForegroundVerticalLine(41, 0, 32, White, FullBlock);
            buffer.FillForegroundVerticalLine(42, 0, 32, White, DarkShade);
            buffer.FillForegroundVerticalLine(43, 0, 32, White, MediumShade);
            buffer.FillForegroundVerticalLine(44, 0, 32, White, LightShade);
            buffer.DrawString(15, 15, Black, "Hello world!");
            buffer.DrawString(15, 16, White, "Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!");
            //buffer.ApplyBackgroundColorMap(0, 0, buffer.Width, buffer.Height, ColorMaps.Invert);
            //buffer.ApplyForegroundColorMap(0, 0, buffer.Width, buffer.Height, ColorMaps.Invert);

            //new ConsoleRenderTarget().Render(buffer);
            //new ConsoleRenderTarget { ColorOverride = ConsoleColor.White, BackgroundOverride = ConsoleColor.Black }.Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.html"))
                new HtmlRenderTarget(file, new UTF8Encoding(false)).Render(buffer);
            using (var file = new StreamWriter(File.Create(@"../../Tmp/1.ans"), Encoding.GetEncoding("ibm437")) { NewLine = "" })
                new AnsiRenderTarget(file).Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.txt"))
                new TextRenderTarget(file).Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.asc"))
                new TextRenderTarget(file, Encoding.GetEncoding("ibm437")).Render(buffer);

            /*var text = new TextRenderTarget();
            text.Render(buffer);
            Console.Write(text.OutputText);*/

            /*Console.WriteLine(Console.OutputEncoding);
            Console.OutputEncoding = Encoding.UTF8;
            Console.WriteLine("■▬▲►▼◄");
            Console.WriteLine("▀▄█▌▐");
            Console.WriteLine("♠♣♥♦");
            Console.WriteLine("☺☻☼♀♂♫");
            Console.WriteLine("«»‘’‚‛“”„‟‹›");*/
            /*const string TestString1 = "«»‘’‚‛“”„‟‹›", TestString2 = "─═│║┼╪╫╬";
            foreach (EncodingInfo encodingInfo in Encoding.GetEncodings()) {
                try {
                    Encoding encoding = encodingInfo.GetEncoding();
                    bool matched1 = encoding.GetString(encoding.GetBytes(TestString1)) == TestString1;
                    bool matched2 = encoding.GetString(encoding.GetBytes(TestString2)) == TestString2;
                    Console.OutputEncoding = encoding;
                    Console.WriteLine("{0,-10}{1,-20}{2}{3} {4} {5}",
                        encodingInfo.CodePage, encodingInfo.Name, matched1 ? "+" : "-", matched2 ? "+" : "-", TestString1, TestString2);
                }
                catch {
                    Console.WriteLine("{0,-10}{1,-20}xx FAILED",
                        encodingInfo.CodePage, encodingInfo.Name);
                }
            }*/
            /*for (int i = 1; i < 10000; i += 10) {
                var sb = new StringBuilder();
                for (int j = 0; j < 10; j++)
                    sb.AppendFormat("{0,-6}{1} ", (i + j), (char)(i + j));
                Console.Write(sb);
            }*/
        }
Beispiel #18
0
        private void Run()
        {
            /*Size consoleSize = Size.Min(ConsoleRenderer.ConsoleLargestWindowSize, new Size((25 + 1) * 7 + 1, 60));
             * try {
             *  ConsoleRenderer.ConsoleWindowRect = new Rect(consoleSize);
             *  Console.BufferWidth = consoleSize.Width;
             * }
             * catch (Exception e) {
             *  var consoleRect = new Rect(Console.WindowLeft, Console.WindowTop, Console.WindowWidth, Console.WindowHeight);
             *  Console.WriteLine(consoleRect);
             *  var bufferRect = new Size(Console.BufferWidth, Console.BufferHeight);
             *  Console.WriteLine(bufferRect);
             *  Console.WriteLine(e.Message);
             * }*/
            Console.WindowWidth    = 80;
            Console.BufferWidth    = 80;
            Console.OutputEncoding = Encoding.UTF8;
            Console.Title          = Path.GetFileNameWithoutExtension(Console.Title);

            var data = new Data {
                Title           = "Header Title",
                SubTitle        = "Header SubTitle",
                Formatted       = "Aaaa\nBbbb\nCccc",
                LoremIpsum      = "Lo|rem ip|sum do|lor sit amet, con|sec|te|tur adi|pis|cing elit, sed do eius|mod tem|por in|ci|di|dunt ut la|bo|re et do|lo|re mag|na ali|qua. Ut enim ad mi|nim ve|ni|am, qu|is nos|trud exer|ci|ta|tion ul|lam|co la|bo|ris ni|si ut ali|quip ex ea com|mo|do con|se|quat. Du|is au|te iru|re do|lor in rep|re|hen|de|rit in vo|lup|ta|te ve|lit es|se cil|lum do|lo|re eu fu|gi|at nul|la pa|ri|a|tur. Ex|cep|te|ur sint oc|ca|e|cat cu|pi|da|tat non pro|i|dent, sunt in cul|pa qui of|fi|cia de|se|runt mol|lit anim id est la|bo|rum.",
                LoremIpsumShort = "Lo|rem ip|sum do|lor sit amet, con|sec|te|tur adi|pis|cing elit, sed do eius|mod tem|por in|ci|di|dunt ut la|bo|re et do|lo|re mag|na ali|qua. Ut enim ad mi|nim ve|ni|am, qu|is nos|trud exer|ci|ta|tion ul|lam|co la|bo|ris ni|si ut ali|quip ex ea com|mo|do con|se|quat.",
                Guid            = Guid.NewGuid(),
                Date            = DateTime.Now,
                Items           = new List <DataItem> {
                    new DataItem {
                        Id       = 1, Name = "Name 1", Value = "Value 1",
                        SubItems = new List <DataItem> {
                            new DataItem {
                                Id = 11, Name = "Name 1.1", Value = "Value 1.1"
                            },
                            new DataItem {
                                Id = 12, Name = "Name 1.2", Value = "Value 1.2"
                            },
                        }
                    },
                    new DataItem {
                        Id       = 2, Name = "Name 2", Value = "Value 2",
                        SubItems = new List <DataItem> {
                            new DataItem {
                                Id = 21, Name = "Name 2.1", Value = "Value 2.1"
                            },
                            new DataItem {
                                Id = 22, Name = "Name 2.2", Value = "Value 2.2"
                            },
                        }
                    },
                }
            };

            /*if (MemoryProfiler.IsActive) {
             *  MemoryProfiler.EnableAllocations();
             *  MemoryProfiler.Dump();
             * }
             * new ConsoleRenderer().RenderDocument(ReadXaml<Document>(data));
             * if (MemoryProfiler.IsActive)
             *  MemoryProfiler.Dump();*/
            /*for (int i = 0; i < 100; i++)
             *  new ConsoleRenderer().RenderDocument(ReadXaml<Document>(data));*/
            /*if (MemoryProfiler.IsActive)
             *  MemoryProfiler.Dump();*/

            Document xamlDoc = ConsoleRenderer.ReadDocumentFromResource(GetType(), "Markup.xaml", data);

            //Document xamlDoc = ConsoleRenderer.ReadDocumentFromResource(GetType().Assembly, "Alba.CsConsoleFormat.ConsoleTest.Markup.xaml", data);
            Console.WriteLine("XAML");
            ConsoleRenderer.RenderDocument(xamlDoc);
            ConsoleRenderer.RenderDocument(xamlDoc, new HtmlRenderTarget(File.Create(@"../../Tmp/0.html"), new UTF8Encoding(false)));

            Document builtDoc = new ViewBuilder().CreateDocument(data);

            Console.WriteLine("Builder");
            ConsoleRenderer.RenderDocument(builtDoc);
            ConsoleRenderer.RenderDocument(builtDoc, new HtmlRenderTarget(File.Create(@"../../Tmp/0a.html"), new UTF8Encoding(false)));

            var buffer = new ConsoleBuffer(80)
            {
                LineCharRenderer = LineCharRenderer.Box,
                //Clip = new Rect(1, 1, 78, 30),
            };
            var rainbow = new[] {
                Black,
                DarkRed, DarkYellow, DarkGreen, DarkCyan, DarkBlue, DarkMagenta, DarkRed,
                Black,
                Red, Yellow, Green, Cyan, Blue, Magenta, Red,
            };

            /*for (int i = 0; i < 16; i++)
             *  buffer.FillRectangle((ConsoleColor)i, i, i, 80 - i * 2, 31 - i * 2);*/
            for (int i = 0; i < rainbow.Length; i++)
            {
                buffer.FillBackgroundRectangle(i, i, 80 - i * 2, (rainbow.Length - i) * 2, rainbow[i]);
            }
            buffer.DrawHorizontalLine(1, 0, 78, White);
            buffer.DrawHorizontalLine(1, 1, 78, White, LineWidth.Wide);
            buffer.DrawHorizontalLine(3, 3, 7, White);
            buffer.DrawVerticalLine(1, 1, 9, White);
            buffer.DrawVerticalLine(2, 2, 4, White);
            buffer.DrawVerticalLine(5, 0, 6, White, LineWidth.Wide);
            buffer.DrawVerticalLine(5, 0, 6, White);
            buffer.DrawVerticalLine(6, 0, 6, White);
            buffer.DrawVerticalLine(3, 0, 12, White, LineWidth.Wide);
            buffer.DrawRectangle(0, 0, 80, 32, White, LineWidth.Wide);
            buffer.FillBackgroundVerticalLine(40, 0, 32, Yellow);
            buffer.FillForegroundVerticalLine(41, 0, 32, White, FullBlock);
            buffer.FillForegroundVerticalLine(42, 0, 32, White, DarkShade);
            buffer.FillForegroundVerticalLine(43, 0, 32, White, MediumShade);
            buffer.FillForegroundVerticalLine(44, 0, 32, White, LightShade);
            buffer.DrawString(15, 15, Black, "Hello world!");
            buffer.DrawString(15, 16, White, "Hello world! Hello world! Hello world! Hello world! Hello world! Hello world!");
            //buffer.ApplyBackgroundColorMap(0, 0, buffer.Width, buffer.Height, ColorMaps.Invert);
            //buffer.ApplyForegroundColorMap(0, 0, buffer.Width, buffer.Height, ColorMaps.Invert);

            //new ConsoleRenderTarget().Render(buffer);
            //new ConsoleRenderTarget { ColorOverride = ConsoleColor.White, BackgroundOverride = ConsoleColor.Black }.Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.html"))
                new HtmlRenderTarget(file, new UTF8Encoding(false)).Render(buffer);
            using (var file = new StreamWriter(File.Create(@"../../Tmp/1.ans"), Encoding.GetEncoding("ibm437"))
            {
                NewLine = ""
            })
                new AnsiRenderTarget(file).Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.txt"))
                new TextRenderTarget(file).Render(buffer);
            using (var file = File.Create(@"../../Tmp/1.asc"))
                new TextRenderTarget(file, Encoding.GetEncoding("ibm437")).Render(buffer);

            /*var text = new TextRenderTarget();
             * text.Render(buffer);
             * Console.Write(text.OutputText);*/

            /*Console.WriteLine(Console.OutputEncoding);
             * Console.OutputEncoding = Encoding.UTF8;
             * Console.WriteLine("■▬▲►▼◄");
             * Console.WriteLine("▀▄█▌▐");
             * Console.WriteLine("♠♣♥♦");
             * Console.WriteLine("☺☻☼♀♂♫");
             * Console.WriteLine("«»‘’‚‛“”„‟‹›");*/
            /*const string TestString1 = "«»‘’‚‛“”„‟‹›", TestString2 = "─═│║┼╪╫╬";
             * foreach (EncodingInfo encodingInfo in Encoding.GetEncodings()) {
             *  try {
             *      Encoding encoding = encodingInfo.GetEncoding();
             *      bool matched1 = encoding.GetString(encoding.GetBytes(TestString1)) == TestString1;
             *      bool matched2 = encoding.GetString(encoding.GetBytes(TestString2)) == TestString2;
             *      Console.OutputEncoding = encoding;
             *      Console.WriteLine("{0,-10}{1,-20}{2}{3} {4} {5}",
             *          encodingInfo.CodePage, encodingInfo.Name, matched1 ? "+" : "-", matched2 ? "+" : "-", TestString1, TestString2);
             *  }
             *  catch {
             *      Console.WriteLine("{0,-10}{1,-20}xx FAILED",
             *          encodingInfo.CodePage, encodingInfo.Name);
             *  }
             * }*/
            /*for (int i = 1; i < 10000; i += 10) {
             *  var sb = new StringBuilder();
             *  for (int j = 0; j < 10; j++)
             *      sb.AppendFormat("{0,-6}{1} ", (i + j), (char)(i + j));
             *  Console.Write(sb);
             * }*/
        }