mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00

committed by
Patrik Svensson

parent
0a0380ae0a
commit
3f2ca49071
15
examples/Calendars/Calendars.csproj
Normal file
15
examples/Calendars/Calendars.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<Title>Calendars</Title>
|
||||
<Description>Demonstrates how to render calendars.</Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
68
examples/Calendars/Program.cs
Normal file
68
examples/Calendars/Program.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System.Collections.Generic;
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Calendars
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
AnsiConsole.Render(
|
||||
new Columns(GetCalendars())
|
||||
.Collapse());
|
||||
}
|
||||
|
||||
private static IEnumerable<IRenderable> GetCalendars()
|
||||
{
|
||||
yield return EmbedInPanel(
|
||||
"Invariant calendar",
|
||||
new Calendar(2020, 10)
|
||||
.SimpleHeavyBorder()
|
||||
.SetHighlightStyle(Style.Parse("red"))
|
||||
.AddCalendarEvent("An event", 2020, 9, 22)
|
||||
.AddCalendarEvent("Another event", 2020, 10, 2)
|
||||
.AddCalendarEvent("A third event", 2020, 10, 13));
|
||||
|
||||
yield return EmbedInPanel(
|
||||
"Swedish calendar (sv-SE)",
|
||||
new Calendar(2020, 10)
|
||||
.RoundedBorder()
|
||||
.SetHighlightStyle(Style.Parse("blue"))
|
||||
.SetCulture("sv-SE")
|
||||
.AddCalendarEvent("An event", 2020, 9, 22)
|
||||
.AddCalendarEvent("Another event", 2020, 10, 2)
|
||||
.AddCalendarEvent("A third event", 2020, 10, 13));
|
||||
|
||||
yield return EmbedInPanel(
|
||||
"German calendar (de-DE)",
|
||||
new Calendar(2020, 10)
|
||||
.MarkdownBorder()
|
||||
.SetHighlightStyle(Style.Parse("yellow"))
|
||||
.SetCulture("de-DE")
|
||||
.AddCalendarEvent("An event", 2020, 9, 22)
|
||||
.AddCalendarEvent("Another event", 2020, 10, 2)
|
||||
.AddCalendarEvent("A third event", 2020, 10, 13));
|
||||
|
||||
yield return EmbedInPanel(
|
||||
"Italian calendar (de-DE)",
|
||||
new Calendar(2020, 10)
|
||||
.DoubleBorder()
|
||||
.SetHighlightStyle(Style.Parse("green"))
|
||||
.SetCulture("it-IT")
|
||||
.AddCalendarEvent("An event", 2020, 9, 22)
|
||||
.AddCalendarEvent("Another event", 2020, 10, 2)
|
||||
.AddCalendarEvent("A third event", 2020, 10, 13));
|
||||
}
|
||||
|
||||
private static IRenderable EmbedInPanel(string title, Calendar calendar)
|
||||
{
|
||||
return new Panel(calendar)
|
||||
.Expand()
|
||||
.RoundedBorder()
|
||||
.SetBorderStyle(Style.Parse("grey"))
|
||||
.SetHeader($" {title} ", Style.Parse("yellow"));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user