Add day selector
This commit is contained in:
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
bin/
|
||||
obj/
|
||||
/packages/
|
||||
riderModule.iml
|
||||
/_ReSharper.Caches/
|
||||
.idea/.idea.AdventOfCode/.idea
|
||||
14
AdventOfCode.csproj
Normal file
14
AdventOfCode.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Spectre.Console" Version="0.45.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
16
AdventOfCode.sln
Normal file
16
AdventOfCode.sln
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode", "AdventOfCode.csproj", "{566CA1D9-1EDC-491C-8196-CA163F9D6FE1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{566CA1D9-1EDC-491C-8196-CA163F9D6FE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{566CA1D9-1EDC-491C-8196-CA163F9D6FE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{566CA1D9-1EDC-491C-8196-CA163F9D6FE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{566CA1D9-1EDC-491C-8196-CA163F9D6FE1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
14
Days/Day.cs
Normal file
14
Days/Day.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace AdventOfCode.Days;
|
||||
|
||||
public abstract class Day
|
||||
{
|
||||
public abstract int Number { get; }
|
||||
public abstract string Name { get; }
|
||||
|
||||
public abstract void Run();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Day {Number}: {Name}";
|
||||
}
|
||||
}
|
||||
14
Days/Day1.cs
Normal file
14
Days/Day1.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace AdventOfCode.Days;
|
||||
|
||||
public class Day1 : Day
|
||||
{
|
||||
public override int Number => 1;
|
||||
public override string Name => "First day";
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
AnsiConsole.WriteLine("Day 1 result");
|
||||
}
|
||||
}
|
||||
14
Days/Day2.cs
Normal file
14
Days/Day2.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Spectre.Console;
|
||||
|
||||
namespace AdventOfCode.Days;
|
||||
|
||||
public class Day2 : Day
|
||||
{
|
||||
public override int Number { get; } = 2;
|
||||
public override string Name { get; } = "Second day";
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
AnsiConsole.WriteLine("Day 2 result");
|
||||
}
|
||||
}
|
||||
18
Program.cs
Normal file
18
Program.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
using System.Reflection;
|
||||
using AdventOfCode.Days;
|
||||
using Spectre.Console;
|
||||
|
||||
var days = Assembly.GetAssembly(typeof(Day))!.GetTypes()
|
||||
.Where(t => t.IsAssignableTo(typeof(Day)) && t.GetConstructor(Type.EmptyTypes) != null && !t.IsAbstract)
|
||||
.Select(t => (Day)Activator.CreateInstance(t)!);
|
||||
|
||||
var select = new SelectionPrompt<Day>()
|
||||
.Title("[cyan]Select a [yellow]day[/] to run:[/]")
|
||||
.AddChoices(days);
|
||||
|
||||
var selectedDay = AnsiConsole.Prompt(select);
|
||||
|
||||
AnsiConsole.MarkupLine($"[cyan]Running [yellow]{selectedDay}[/]...[/]\n");
|
||||
|
||||
selectedDay.Run();
|
||||
Reference in New Issue
Block a user