Exemplo n.º 1
0
 public static ContainerSpan StyleBold(this string @string)
 {
     return(new ContainerSpan(
                StyleSpan.BoldOn(),
                new ContentSpan(@string),
                StyleSpan.BoldOff()));
 }
Exemplo n.º 2
0
        public void StyleSpans_with_equivalent_content_have_the_same_hash_code()
        {
            var one = new StyleSpan("green", Ansi.Color.Foreground.Green);
            var two = new StyleSpan("green", Ansi.Color.Foreground.Green);

            one.GetHashCode().Should().Be(two.GetHashCode());
        }
Exemplo n.º 3
0
 public static ContainerSpan StyleUnderline(this string @string)
 {
     return(new ContainerSpan(
                StyleSpan.UnderlinedOn(),
                new ContentSpan(@string),
                StyleSpan.UnderlinedOff()));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sets the text style to Bold and White.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns>TextSpan.</returns>
 public static TextSpan BoldWhite(this string value) =>
 new ContainerSpan(
     ForegroundColorSpan.White(),
     StyleSpan.BoldOn(),
     new ContentSpan(value),
     StyleSpan.BoldOff(),
     ForegroundColorSpan.Reset());
Exemplo n.º 5
0
        public void Same_input_with_or_without_ansi_codes_produce_the_same_wrap(
            int left,
            int top,
            int width,
            int height
            )
        {
            var terminalWithoutAnsiCodes = new TestTerminal();
            var rendererWithoutAnsiCodes = new ConsoleRenderer(
                terminalWithoutAnsiCodes,
                OutputMode.NonAnsi
                );

            var terminalWithAnsiCodes = new TestTerminal();
            var rendererWithAnsiCodes = new ConsoleRenderer(
                terminalWithAnsiCodes,
                OutputMode.NonAnsi
                );

            FormattableString formattableString =
                $"Call me {StyleSpan.BoldOn()}{StyleSpan.UnderlinedOn()}Ishmael{StyleSpan.UnderlinedOff()}{StyleSpan.BoldOff()}. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and {ForegroundColorSpan.Rgb(60, 0, 0)}methodically{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(90, 0, 0)}knocking{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(120, 0, 0)}people's{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(160, 0, 0)}hats{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(220, 0, 0)}off{ForegroundColorSpan.Reset()} then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.";

            var stringWithoutCodes = formattableString.ToString();

            var region = new Region(left, top, width, height);

            rendererWithAnsiCodes.RenderToRegion(formattableString, region);

            rendererWithoutAnsiCodes.RenderToRegion(stringWithoutCodes, region);

            var outputFromInputWithoutAnsiCodes = terminalWithoutAnsiCodes.Out.ToString();
            var outputFromInputWithAnsiCodes    = terminalWithAnsiCodes.Out.ToString();

            outputFromInputWithAnsiCodes.Should().Be(outputFromInputWithoutAnsiCodes);
        }
Exemplo n.º 6
0
        public void StyleSpans_with_different_names_are_not_equal()
        {
            var one = new StyleSpan("red", Ansi.Color.Foreground.Green);
            var two = new StyleSpan("green", Ansi.Color.Foreground.Green);

            one.Equals(two).Should().BeFalse();
        }
Exemplo n.º 7
0
 private static View Underline(string text)
 {
     return(new ContentView(new ContainerSpan(
                                StyleSpan.UnderlinedOn(),
                                new ContentSpan(text),
                                StyleSpan.UnderlinedOff())));
 }
Exemplo n.º 8
0
 public void WriteEmphasize(string content)
 {
     Terminal.Render(StyleSpan.BoldOn());
     Terminal.Render(StyleSpan.UnderlinedOn());
     Write(content);
     Terminal.Render(StyleSpan.BoldOff());
     Terminal.Render(StyleSpan.UnderlinedOff());
 }
Exemplo n.º 9
0
 public static void OutputEmphasize(this ITerminal terminal, string content)
 {
     terminal.Render(StyleSpan.BoldOn());
     terminal.Render(StyleSpan.UnderlinedOn());
     terminal.Output(content);
     terminal.Render(StyleSpan.BoldOff());
     terminal.Render(StyleSpan.UnderlinedOff());
 }
Exemplo n.º 10
0
        public void StyleSpans_with_the_same_name_are_equal()
        {
            var one = new StyleSpan("green", Ansi.Color.Foreground.Green);
            var two = new StyleSpan("green", Ansi.Color.Foreground.Green);

            one.Equals(two).Should().BeTrue();

            one.Invoking(code => code.Equals(null)).Should().NotThrow <NullReferenceException>();
        }
Exemplo n.º 11
0
        public void StyleSpans_with_different_names_are_not_equal()
        {
            var one = new StyleSpan("red");
            var two = new StyleSpan("green");

            one.Equals(two)
            .Should()
            .BeFalse();
        }
Exemplo n.º 12
0
        void SetSpan(int start, int end, TypefaceStyle typeface)
        {
            CharacterStyle span = new StyleSpan(typeface);

            if (start == end)
            {
                EditText.EditableText.SetSpan(span, start, end, SpanTypes.InclusiveInclusive);
            }
            else
            {
                EditText.EditableText.SetSpan(span, start, end, SpanTypes.ExclusiveInclusive);
            }
        }
Exemplo n.º 13
0
        public static StyleSpan [] StyleSpans(Path path, StrokeStyle [] styles, NSNumber [] lengths, LengthKind lengthKind, double lengthOffset)
        {
            var stylesArray  = NSArray.FromNSObjects(styles);
            var lengthsArray = NSArray.FromNSObjects(lengths);
            var result       = _StyleSpans(path, stylesArray.Handle, lengthsArray.Handle, lengthKind, lengthOffset);
            var nsObjects    = NSArray.ArrayFromHandle <NSObject> (result);
            var resultArray  = new StyleSpan [nsObjects.Length];

            for (int i = 0; i < nsObjects.Length; i++)
            {
                resultArray [i] = (StyleSpan)nsObjects [i];
            }

            return(resultArray);
        }
        public void A_formattable_string_containing_ansi_codes_can_be_converted_to_a_ContainerSpan()
        {
            var span = new TextSpanFormatter().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.º 15
0
 static PromoVideosPageFragment()
 {
     PrefixStyle      = new StyleSpan(TypefaceStyle.Bold);
     PrefixColorStyle = new ForegroundColorSpan(new Color(ResourceExtension.AccentColour));
 }
Exemplo n.º 16
0
 public static TextSpan Bold(this string value) =>
 new ContainerSpan(StyleSpan.BoldOn(),
                   new ContentSpan(value),
                   StyleSpan.BoldOff());
Exemplo n.º 17
0
 public virtual void VisitStyleSpan(StyleSpan span)
 {
 }
Exemplo n.º 18
0
 public override void VisitStyleSpan(StyleSpan span) => VisitedSpans.Add(span);
Exemplo n.º 19
0
 public static TextSpan UnderlineRed(this string value) =>
 new ContainerSpan(StyleSpan.UnderlinedOn(),
                   ForegroundColorSpan.Rgb(237, 90, 90),
                   new ContentSpan(value),
                   ForegroundColorSpan.Reset(),
                   StyleSpan.UnderlinedOff());
Exemplo n.º 20
0
 public static TextSpan UnderlineRgb(this string value, byte r, byte g, byte b) =>
 new ContainerSpan(StyleSpan.UnderlinedOn(),
                   ForegroundColorSpan.Rgb(r, g, b),
                   new ContentSpan(value),
                   ForegroundColorSpan.Reset(),
                   StyleSpan.UnderlinedOff());
Exemplo n.º 21
0
        private static void HandleFormatRun(ISpannable spannableString, IAttributedTextRun run)
        {
            var attributes = run.Attributes;
            var start      = run.Start;
            var end        = start + run.Length;

            var fontName = attributes.GetFontName();

            if (fontName != null)
            {
                var typefaceSpan = new TypefaceSpan(fontName);
                spannableString.SetSpan(typefaceSpan, start, end, SpanTypes.ExclusiveExclusive);
            }

            if (attributes.GetBold() && attributes.GetItalic())
            {
                var span = new StyleSpan(TypefaceStyle.BoldItalic);
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }
            else if (attributes.GetBold())
            {
                var span = new StyleSpan(TypefaceStyle.Bold);
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }
            else if (attributes.GetItalic())
            {
                var span = new StyleSpan(TypefaceStyle.Italic);
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }

            if (attributes.GetUnderline())
            {
                var span = new UnderlineSpan();
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }

            var foregroundColor = attributes.GetForegroundColor()?.ParseAsInts()?.ToColor();

            if (foregroundColor != null)
            {
                var span = new ForegroundColorSpan((global::Android.Graphics.Color)foregroundColor);
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }

            var backgroundColor = attributes.GetBackgroundColor()?.ParseAsInts()?.ToColor();

            if (backgroundColor != null)
            {
                var span = new BackgroundColorSpan((global::Android.Graphics.Color)backgroundColor);
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }

            if (attributes.GetSubscript())
            {
                var span = new SubscriptSpan();
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }

            if (attributes.GetSuperscript())
            {
                var span = new SuperscriptSpan();
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }

            if (attributes.GetStrikethrough())
            {
                var span = new StrikethroughSpan();
                spannableString.SetSpan(span, start, end, SpanTypes.ExclusiveExclusive);
            }

            if (attributes.GetUnorderedList())
            {
                var bulletSpan = new BulletSpan();
                spannableString.SetSpan(bulletSpan, start, end, SpanTypes.ExclusiveExclusive);
            }
        }
Exemplo n.º 22
0
 public static Span Underline(this string value) =>
 new ContainerSpan(StyleSpan.UnderlinedOn(),
                   new ContentSpan(value),
                   StyleSpan.UnderlinedOff());
Exemplo n.º 23
0
 public void WriteBlink(string content)
 {
     Terminal.Render(StyleSpan.BlinkOn());
     Write(content);
     Terminal.Render(StyleSpan.BlinkOff());
 }
Exemplo n.º 24
0
 public void WriteBold(string content)
 {
     Terminal.Render(StyleSpan.BoldOn());
     Write(content);
     Terminal.Render(StyleSpan.BoldOff());
 }
Exemplo n.º 25
0
 public void WriteStandout(string content)
 {
     Terminal.Render(StyleSpan.StandoutOn());
     Write(content);
     Terminal.Render(StyleSpan.StandoutOff());
 }
Exemplo n.º 26
0
 public void FormatSpans_do_not_have_default_string_representations()
 {
     $"{ForegroundColorSpan.DarkGray()}The {BackgroundColorSpan.Cyan()}quick{StyleSpan.BlinkOn()} brown fox jumped over the lazy dog.{StyleSpan.BoldOff()}{ForegroundColorSpan.Reset()}{BackgroundColorSpan.Reset()}"
     .Should()
     .Be("The quick brown fox jumped over the lazy dog.");
 }
Exemplo n.º 27
0
 public static void OutputStandout(this ITerminal terminal, string content)
 {
     terminal.Render(StyleSpan.StandoutOn());
     terminal.Output(content);
     terminal.Render(StyleSpan.StandoutOff());
 }
Exemplo n.º 28
0
        /// <summary>
        /// Demonstrates various rendering capabilities.
        /// </summary>
        /// <param name="invocationContext"></param>
        /// <param name="sample">Renders a specified sample</param>
        /// <param name="height">The height of the rendering area</param>
        /// <param name="width">The width of the rendering area</param>
        /// <param name="top">The top position of the render area</param>
        /// <param name="left">The left position of the render area</param>
        /// <param name="text">The text to render</param>
        /// <param name="overwrite">Overwrite the specified region. (If not, scroll.)</param>
        public static void Main(
#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
            InvocationContext invocationContext,
            SampleName sample = SampleName.Dir,
            int?height        = null,
            int?width         = null,
            int top           = 0,
            int left          = 0,
            string text       = null,
            bool overwrite    = true)
#pragma warning restore CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
        {
            var region = new Region(left,
                                    top,
                                    width ?? Console.WindowWidth,
                                    height ?? Console.WindowHeight,
                                    overwrite);

            if (overwrite &&
                invocationContext.Console is ITerminal terminal)
            {
                terminal.Clear();
            }

            var consoleRenderer = new ConsoleRenderer(
                invocationContext.Console,
                mode: invocationContext.BindingContext.OutputMode(),
                resetAfterRender: true);

            switch (sample)
            {
            case SampleName.Colors:
            {
                var screen = new ScreenView(renderer: consoleRenderer, invocationContext.Console);
                screen.Child = new ColorsView(text ?? "*");

                screen.Render(region);
            }
            break;

            case SampleName.Dir:
                var directoryTableView = new DirectoryTableView(new DirectoryInfo(Directory.GetCurrentDirectory()));
                directoryTableView.Render(consoleRenderer, region);

                break;

            case SampleName.Moby:
                consoleRenderer.RenderToRegion(
                    $"Call me {StyleSpan.BoldOn()}{StyleSpan.UnderlinedOn()}Ishmael{StyleSpan.UnderlinedOff()}{StyleSpan.BoldOff()}. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and {ForegroundColorSpan.Rgb(60, 0, 0)}methodically{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(90, 0, 0)}knocking{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(120, 0, 0)}people's{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(160, 0, 0)}hats{ForegroundColorSpan.Reset()} {ForegroundColorSpan.Rgb(220, 0, 0)}off{ForegroundColorSpan.Reset()} then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.",
                    region);
                break;

            case SampleName.Processes:
            {
                var view = new ProcessesView(Process.GetProcesses());
                view.Render(consoleRenderer, region);
            }

            break;

            case SampleName.TableView:
            {
                var table = new TableView <Process>
                {
                    Items = Process.GetProcesses().Where(x => !string.IsNullOrEmpty(x.MainWindowTitle)).OrderBy(p => p.ProcessName).ToList()
                };
                table.AddColumn(process => $"{process.ProcessName} ", "Name");
                table.AddColumn(process => ContentView.FromObservable(process.TrackCpuUsage(), x => $"{x.UsageTotal:P}"), "CPU", ColumnDefinition.Star(1));

                var screen = new ScreenView(renderer: consoleRenderer, invocationContext.Console)
                {
                    Child = table
                };
                screen.Render();
            }
            break;

            case SampleName.Clock:
            {
                var screen          = new ScreenView(renderer: consoleRenderer, invocationContext.Console);
                var lastTime        = DateTime.Now;
                var clockObservable = new BehaviorSubject <DateTime>(lastTime);
                var clockView       = ContentView.FromObservable(clockObservable, x => $"{x:T}");
                screen.Child = clockView;
                screen.Render();

                while (!Console.KeyAvailable)
                {
                    if (DateTime.Now - lastTime > TimeSpan.FromSeconds(1))
                    {
                        lastTime = DateTime.Now;
                        clockObservable.OnNext(lastTime);
                    }
                }
            }
            break;

            case SampleName.GridLayout:
            {
                var screen  = new ScreenView(renderer: consoleRenderer, invocationContext.Console);
                var content = new ContentView(
                    "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum for Kevin.");
                var smallContent = new ContentView("Kevin Bost");
                var longContent  = new ContentView("Hacking on System.CommandLine");

                var gridView = new GridView();
                gridView.SetColumns(
                    ColumnDefinition.SizeToContent(),
                    ColumnDefinition.Star(1),
                    ColumnDefinition.Star(0.5)
                    );
                gridView.SetRows(
                    RowDefinition.Star(0.5),
                    RowDefinition.Star(0.5)
                    );

                gridView.SetChild(smallContent, 0, 0);
                gridView.SetChild(longContent, 0, 1);
                //gridView.SetChild(content, 0, 0);
                gridView.SetChild(content, 1, 1);
                gridView.SetChild(content, 2, 0);

                screen.Child = gridView;

                screen.Render();
            }
            break;

            default:
                if (!string.IsNullOrWhiteSpace(text))
                {
                    consoleRenderer.RenderToRegion(
                        text,
                        region);
                }
                else
                {
                    var screen      = new ScreenView(renderer: consoleRenderer, invocationContext.Console);
                    var stackLayout = new StackLayoutView();
                    var content1    = new ContentView("Hello World!");
                    var content2    = new ContentView(
                        "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum for Kevin.");
                    stackLayout.Add(content2);
                    stackLayout.Add(content1);
                    stackLayout.Add(content2);
                    screen.Child = stackLayout;
                    screen.Render(new Region(0, 0, 50, Size.MaxValue));
                    //screen.Render(writer);
                }

                break;
            }

            if (!Console.IsOutputRedirected)
            {
                Console.ReadKey();
            }
        }
Exemplo n.º 29
0
 public static void OutputBold(this ITerminal terminal, string content)
 {
     terminal.Render(StyleSpan.BoldOn());
     terminal.Output(content);
     terminal.Render(StyleSpan.BoldOff());
 }