示例#1
0
 public static ContainerSpan StyleSuccess(this string @string)
 {
     return(new ContainerSpan(
                ForegroundColorSpan.LightGreen(),
                new ContentSpan(@string),
                ForegroundColorSpan.Reset()));
 }
            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));
                }
            }
示例#3
0
            public override void Render(ConsoleRenderer renderer, Region region)
            {
                var p    = Math.Clamp(Progress, 0, 1.0);
                var done = (int)(p * 100);

                const int textWidth  = 6;
                var       text       = p.ToString("P");
                const int aHalf      = 47;
                var       firstFill  = Math.Clamp(done, 0, aHalf);
                var       secondFill = Math.Clamp(done - (aHalf + textWidth), 0, aHalf);

                var result = new ContainerSpan(
                    Title.StyleUnderline(),
                    ": ".AsTextSpan(),
                    new ContainerSpan(
                        new string('=', firstFill).StyleColor(ForegroundColorSpan.LightGreen()),
                        new string('-', aHalf - firstFill).StyleColor(ForegroundColorSpan.LightGray())
                        ),
                    done switch
                {
示例#4
0
 public static Span LightGreen(this string value) =>
 new ContainerSpan(ForegroundColorSpan.LightGreen(),
                   new ContentSpan(value),
                   ForegroundColorSpan.Reset());