Update ColumnsSample to showcase nicer data (#1295)

Also, I switched the base width of the AsciiCast back
to 82 (from 120) so newly created casts are no longer
overflowing the display with on the pages.

Re-created the Panel and BreakdownChart casts, as
they were currently overflowing due to the 120 chars
width of the cast.
This commit is contained in:
Nils Andresen
2023-09-12 12:58:18 +02:00
committed by GitHub
parent 1002c6fe27
commit a3dcb31729
8 changed files with 173 additions and 41 deletions

View File

@ -1,22 +1,94 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Spectre.Console;
namespace Generator.Commands.Samples
// ReSharper disable once CheckNamespace
namespace Generator.Commands.Samples;
// ReSharper disable once UnusedType.Global
public class ColumnsSample : BaseSample
{
public class ColumnsSample : BaseSample
public override void Run(IAnsiConsole console)
{
public override void Run(IAnsiConsole console)
{
for (var i = 0; i <= 10; i++)
var cards = Fruit
.LoadFriuts()
.Select(GetContent)
.ToList();
// Animate
console.Live(new Text(""))
.AutoClear(true)
.Overflow(VerticalOverflow.Ellipsis)
.Cropping(VerticalOverflowCropping.Top)
.Start(ctx =>
{
var n = 3 * i + 1;
console.Write(new Columns(
new Text($"Item {n}", new Style(Color.Red, Color.Black)),
new Text($"Item {n+1}", new Style(Color.Green, Color.Black)),
new Text($"Item {n+2}", new Style(Color.Blue, Color.Black))
));
Thread.Sleep(200);
for (var i = 1; i < cards.Count; i++)
{
var toShow = cards.Take(i);
ctx.UpdateTarget(new Columns(toShow));
//ctx.Refresh();
Thread.Sleep(200);
}
});
// Render all cards in columns
AnsiConsole.Write(new Spectre.Console.Columns(cards));
}
private static string GetContent(Fruit fruit)
{
return $"[b][yellow]{fruit.Name}[/][/]";
}
private sealed class Fruit
{
public string Name { get; init; }
public static List<Fruit> LoadFriuts()
{
return new []
{
"Apple",
"Apricot",
"Avocado",
"Banana",
"Blackberry",
"Blueberry",
"Boysenberry",
"Breadfruit",
"Cacao",
"Cherry",
"Cloudberry",
"Coconut",
"Dragonfruit",
"Elderberry",
"Grape",
"Grapefruit",
"Jackfruit",
"Kiwifruit",
"Lemon",
"Lime",
"Mango",
"Melon",
"Orange",
"Blood orange",
"Clementine",
"Mandarine",
"Tangerine",
"Papaya",
"Passionfruit",
"Plum",
"Pineapple",
"Pomelo",
"Raspberry",
"Salmonberry",
"Strawberry",
"Ximenia",
"Yuzu",
}
.Select(x => new Fruit{Name = x})
.ToList();
}
}
}