mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-01 01:25:27 +08:00 
			
		
		
		
	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:
		| @@ -9,7 +9,7 @@ namespace Generator.Commands.Samples | ||||
|     { | ||||
|         public abstract void Run(IAnsiConsole console); | ||||
|         public virtual string Name() => PascalToKebab(GetType().Name.Replace("Sample","")); | ||||
|         public virtual (int Cols, int Rows) ConsoleSize => (120, 24); | ||||
|         public virtual (int Cols, int Rows) ConsoleSize => (82, 24); | ||||
|         public virtual IEnumerable<(string Name, Action<Capabilities> CapabilitiesAction)> GetCapabilities() | ||||
|         { | ||||
|             return new (string Name, Action<Capabilities> CapabilitiesAction)[] | ||||
|   | ||||
| @@ -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(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Nils Andresen
					Nils Andresen