mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add Spectre.Cli to Spectre.Console
* Renames Spectre.Cli to Spectre.Console.Cli. * Now uses Verify with Spectre.Console.Cli tests. * Removes some duplicate definitions. Closes #168
This commit is contained in:

committed by
Patrik Svensson

parent
0bbf9b81a9
commit
0ae419326d
19
examples/Console/Columns/Columns.csproj
Normal file
19
examples/Console/Columns/Columns.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<ExampleTitle>Columns</ExampleTitle>
|
||||
<ExampleDescription>Demonstrates how to render data into columns.</ExampleDescription>
|
||||
<ExampleGroup>Widgets</ExampleGroup>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
31
examples/Console/Columns/Program.cs
Normal file
31
examples/Console/Columns/Program.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace ColumnsExample
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var cards = new List<Panel>();
|
||||
foreach(var user in User.LoadUsers())
|
||||
{
|
||||
cards.Add(
|
||||
new Panel(GetCardContent(user))
|
||||
.Header($"{user.Country}")
|
||||
.RoundedBorder().Expand());
|
||||
}
|
||||
|
||||
// Render all cards in columns
|
||||
AnsiConsole.Render(new Columns(cards));
|
||||
}
|
||||
|
||||
private static string GetCardContent(User user)
|
||||
{
|
||||
var name = $"{user.FirstName} {user.LastName}";
|
||||
var city = $"{user.City}";
|
||||
|
||||
return $"[b]{name}[/]\n[yellow]{city}[/]";
|
||||
}
|
||||
}
|
||||
}
|
89
examples/Console/Columns/User.cs
Normal file
89
examples/Console/Columns/User.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ColumnsExample
|
||||
{
|
||||
public sealed class User
|
||||
{
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string City { get; set; }
|
||||
public string Country { get; set; }
|
||||
|
||||
public static List<User> LoadUsers()
|
||||
{
|
||||
return new List<User>
|
||||
{
|
||||
new User
|
||||
{
|
||||
FirstName = "Andrea",
|
||||
LastName = "Johansen",
|
||||
City = "Hornbæk",
|
||||
Country = "Denmark",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Brandon",
|
||||
LastName = "Cole",
|
||||
City = "Washington",
|
||||
Country = "United States",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Patrik",
|
||||
LastName = "Svensson",
|
||||
City = "Stockholm",
|
||||
Country = "Sweden",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Freya",
|
||||
LastName = "Thompson",
|
||||
City = "Rotorua",
|
||||
Country = "New Zealand",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "طاها",
|
||||
LastName = "رضایی",
|
||||
City = "اهواز",
|
||||
Country = "Iran",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Yara",
|
||||
LastName = "Simon",
|
||||
City = "Develier",
|
||||
Country = "Switzerland",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Giray",
|
||||
LastName = "Erbay",
|
||||
City = "Karabük",
|
||||
Country = "Turkey",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Miodrag",
|
||||
LastName = "Schaffer",
|
||||
City = "Möckern",
|
||||
Country = "Germany",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Carmela",
|
||||
LastName = "Lo Castro",
|
||||
City = "Firenze",
|
||||
Country = "Italy",
|
||||
},
|
||||
new User
|
||||
{
|
||||
FirstName = "Roberto",
|
||||
LastName = "Sims",
|
||||
City = "Mallow",
|
||||
Country = "Ireland",
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user