public void  When_formatting_null_values_then_empty_span_is_returned()
        {
            var formatter = new SpanFormatter();

            var span = formatter.Format(null);

            span.Should().Be(Span.Empty());
        }
Exemplo n.º 2
0
 internal static ContentView Create(object content, SpanFormatter formatter)
 {
     if (content == null)
     {
         return(new ContentView(Span.Empty()));
     }
     return(CreateView((dynamic)content, formatter));
 }
Exemplo n.º 3
0
 public void WriteJsonUtf16()
 {
     var buffer = new byte[1024];
     var formatter = new SpanFormatter(buffer.Slice(), FormattingData.InvariantUtf16);            
     var json = new JsonWriter<SpanFormatter>(formatter, prettyPrint: false);
     Write(ref json);
     var str = Encoding.Unicode.GetString(buffer, 0, formatter.CommitedByteCount);
     Assert.Equal(expected, str.Replace(" ", ""));
 }
Exemplo n.º 4
0
        public void InlineImgWithoutTitleWithSpecialAttributes()
        {
            var m = GetSetupMarkdown();

            m.ExtraMode = true;
            var s = new SpanFormatter(m);

            Assert.AreEqual("pre <img src=\"url.com/image.png\" alt=\"alt text\" id=\"foo\" class=\"a b cl\" lang=\"nl\" /> post",
                            s.Format("pre ![alt text](url.com/image.png){#foo .a .b .cl lang=nl} post"));
        }
Exemplo n.º 5
0
        public void InlineLinkWithoutTitleWithSpecialAttributes()
        {
            var m = GetSetupMarkdown();

            m.ExtraMode = true;
            var s = new SpanFormatter(m);

            Assert.AreEqual("pre <a href=\"url.com\" id=\"foo\" class=\"a b cl\" lang=\"nl\">link text</a> post",
                            s.Format("pre [link text](url.com){#foo .a .b .cl lang=nl} post"));
        }
Exemplo n.º 6
0
        public void SetUp()
        {
            m = new Markdown();
            m.AddLinkDefinition(new LinkDefinition("link1", "url.com", "title"));
            m.AddLinkDefinition(new LinkDefinition("link2", "url.com"));
            m.AddLinkDefinition(new LinkDefinition("img1", "url.com/image.png", "title"));
            m.AddLinkDefinition(new LinkDefinition("img2", "url.com/image.png"));

            s = new SpanFormatter(m);
        }
Exemplo n.º 7
0
        public void combined_18()
        {
            var fExtra = new SpanFormatter(new Markdown()
            {
                ExtraMode = true
            });

            Assert.AreEqual("<em>Emphasis</em>, trailing",
                            fExtra.Format("_Emphasis_, trailing"));
        }
Exemplo n.º 8
0
        public void combined_17()
        {
            var fExtra = new SpanFormatter(new Markdown()
            {
                ExtraMode = true
            });

            Assert.AreEqual("<strong>Bold</strong> <em>Italic</em>",
                            fExtra.Format("__Bold__ _Italic_"));
        }
        public void A_simple_formattable_string_can_be_converted_to_a_ContentSpan()
        {
            var span = new SpanFormatter().ParseToSpan($"some text");

            span.Should()
            .BeOfType <ContentSpan>()
            .Which
            .Content
            .Should()
            .Be("some text");
        }
Exemplo n.º 10
0
        public void WriteJsonUtf16()
        {
            var buffer    = new byte[1024];
            var formatter = new SpanFormatter(buffer.Slice(), EncodingData.InvariantUtf16);
            var json      = new JsonWriter <SpanFormatter>(formatter, prettyPrint: false);

            Write(ref json);
            var str = Encoding.Unicode.GetString(buffer, 0, formatter.CommitedByteCount);

            Assert.Equal(expected, str.Replace(" ", ""));
        }
            public DirectoryView(DirectoryInfo directory)
            {
                if (directory == null)
                {
                    throw new ArgumentNullException(nameof(directory));
                }

                var formatter = new SpanFormatter();

                formatter.AddFormatter <DateTime>(d => $"{d:d} {ForegroundColorSpan.DarkGray()}{d:t}");

                Add(new ContentView(""));
                Add(new ContentView(""));

                Add(new ContentView($"Directory: {directory.FullName}"));

                Add(new ContentView(""));
                Add(new ContentView(""));

                var directoryContents = directory.EnumerateFileSystemInfos()
                                        .OrderBy(f => f is DirectoryInfo
                                                                   ? 0
                                                                   : 1).ToList();

                var tableView = new TableView <FileSystemInfo>();

                tableView.Items = directoryContents;
                tableView.AddColumn(f => f is DirectoryInfo
                                     ? Span($"{ForegroundColorSpan.LightGreen()}{f.Name} ")
                                     : Span($"{ForegroundColorSpan.White()}{f.Name} "),
                                    new ContentView(formatter.ParseToSpan($"{Ansi.Text.UnderlinedOn}Name{Ansi.Text.UnderlinedOff}")));

                tableView.AddColumn(f => formatter.Format(f.CreationTime),
                                    new ContentView(formatter.ParseToSpan($"{Ansi.Text.UnderlinedOn}Created{Ansi.Text.UnderlinedOff}")));
                tableView.AddColumn(f => formatter.Format(f.LastWriteTime),
                                    new ContentView(formatter.ParseToSpan($"{Ansi.Text.UnderlinedOn}Modified{Ansi.Text.UnderlinedOff}")));

                Add(tableView);

                Span Span(FormattableString formattableString)
                {
                    return(formatter.ParseToSpan(formattableString));
                }
            }
Exemplo n.º 12
0
        public ProcessesView(Process[] processes)
        {
            var formatter = new SpanFormatter();

            formatter.AddFormatter <TimeSpan>(t => new ContentSpan(t.ToString(@"hh\:mm\:ss")));

            Add(new ContentView(""));
            Add(new ContentView("Processes"));
            Add(new ContentView(""));

            var table = new TableView <Process>
            {
                Items = processes
            };

            table.AddColumn(p => p.Id, new ContentView("PID".Underline()));
            table.AddColumn(p => Name(p), new ContentView("COMMAND".Underline()));
            table.AddColumn(p => p.PrivilegedProcessorTime, new ContentView("TIME".Underline()));
            table.AddColumn(p => p.Threads.Count, new ContentView("#TH".Underline()));
            table.AddColumn(p => p.PrivateMemorySize64.Abbreviate(), new ContentView("MEM".Underline()));
            table.AddColumn(p =>
            {
#pragma warning disable CS0618 // Type or member is obsolete
                var usage = p.TrackCpuUsage().First();
#pragma warning restore CS0618 // Type or member is obsolete
                return($"{usage.UsageTotal:P}");
            }, new ContentView("CPU".Underline()));


            Add(table);

            FormattableString Name(Process p)
            {
                if (!p.Responding)
                {
                    return($"{ForegroundColorSpan.Rgb(180, 0, 0)}{p.ProcessName}{ForegroundColorSpan.Reset()}");
                }
                return($"{p.ProcessName}");
            }
        }
Exemplo n.º 13
0
        public void A_formattable_string_containing_ansi_codes_can_be_converted_to_a_ContainerSpan()
        {
            var span = new SpanFormatter().ParseToSpan($"some {StyleSpan.BlinkOn()}blinking{StyleSpan.BlinkOff()} text");

            var containerSpan = span.Should()
                                .BeOfType <ContainerSpan>()
                                .Subject;

            containerSpan
            .Should()
            .BeEquivalentTo(
                new ContainerSpan(
                    new ContentSpan("some "),
                    StyleSpan.BlinkOn(),
                    new ContentSpan("blinking"),
                    StyleSpan.BlinkOff(),
                    new ContentSpan(" text")
                    ),
                options => options.WithStrictOrdering()
                .Excluding(s => s.Parent)
                .Excluding(s => s.Root)
                );
        }
Exemplo n.º 14
0
        public void FormattableString_parsing_handles_escapes(
            FormattableString fs,
            int expectedCount)
        {
            var formatter = new SpanFormatter();

            var span = formatter.ParseToSpan(fs);

            if (expectedCount > 1)
            {
                var containerSpan = span.Should()
                                    .BeOfType <ContainerSpan>()
                                    .Subject;

                output.WriteLine(containerSpan.ToString());

                containerSpan.Count.Should().Be(expectedCount);
            }
            else
            {
                span.Should().BeOfType <ContentSpan>();
            }
        }
Exemplo n.º 15
0
        public void Empty_strings_are_returned_as_empty_spans()
        {
            var formatter = new SpanFormatter();

            var span = formatter
                       .ParseToSpan($"{Ansi.Color.Foreground.Red}normal{Ansi.Color.Foreground.Default:a}");

            var containerSpan = span.Should()
                                .BeOfType <ContainerSpan>()
                                .Subject;

            containerSpan
            .Should()
            .BeEquivalentTo(
                new ContainerSpan(
                    Span.Empty(),
                    new ContentSpan("normal"),
                    Span.Empty()
                    ),
                options => options.WithStrictOrdering()
                .Excluding(s => s.Parent)
                .Excluding(s => s.Root)
                );
        }
Exemplo n.º 16
0
 private static ContentView CreateView(string stringContent, SpanFormatter _)
 => new ContentView(stringContent);
Exemplo n.º 17
0
 public void SetUp()
 {
     f = new SpanFormatter(new Markdown());
 }
Exemplo n.º 18
0
 public void SetUp()
 {
     m = new Markdown();
     s = new SpanFormatter(m);
 }
Exemplo n.º 19
0
 public void SetUp()
 {
     _formatter = new SpanFormatter(GetSetupMarkdown());
 }
Exemplo n.º 20
0
 private static ContentView CreateView(object value, SpanFormatter formatter)
 => new ContentView(formatter.Format(value));
Exemplo n.º 21
0
 private static ContentView CreateView <T>(IObservable <T> observable, SpanFormatter _)
 => FromObservable(observable);
Exemplo n.º 22
0
 private static ContentView CreateView(Span span, SpanFormatter _)
 => new ContentView(span);