From 9d87078f4d19381f97db3e7b04ef0adba87ae994 Mon Sep 17 00:00:00 2001 From: Maikel Hofman Date: Mon, 22 Apr 2024 18:38:25 +0200 Subject: [PATCH] Add colors to console output --- .github/workflows/release.yaml | 2 +- FactorioLib/Types/Mod.cs | 4 +- FactorioModUpdater/FactorioModUpdater.csproj | 2 +- FactorioModUpdater/Program.cs | 49 ++++++++++++++++---- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 451e576..e9aa347 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: Main +name: Release permissions: contents: write on: diff --git a/FactorioLib/Types/Mod.cs b/FactorioLib/Types/Mod.cs index b558954..c952647 100644 --- a/FactorioLib/Types/Mod.cs +++ b/FactorioLib/Types/Mod.cs @@ -5,8 +5,8 @@ namespace FactorioLib.Types; public class Mod { public string Name { get; set; } - public SemVersion LatestVersion { get; set; } - public SemVersion LocalVersion { get; set; } + public SemVersion? LatestVersion { get; set; } + public SemVersion? LocalVersion { get; set; } public bool Enabled { get; set; } /// diff --git a/FactorioModUpdater/FactorioModUpdater.csproj b/FactorioModUpdater/FactorioModUpdater.csproj index 0006320..44b1cba 100644 --- a/FactorioModUpdater/FactorioModUpdater.csproj +++ b/FactorioModUpdater/FactorioModUpdater.csproj @@ -8,7 +8,7 @@ - + diff --git a/FactorioModUpdater/Program.cs b/FactorioModUpdater/Program.cs index 46caecc..fbc3fc2 100644 --- a/FactorioModUpdater/Program.cs +++ b/FactorioModUpdater/Program.cs @@ -1,6 +1,6 @@ using System.CommandLine; -using ConsoleTables; using FactorioLib; +using Spectre.Console; namespace FactorioModUpdater; @@ -38,19 +38,50 @@ private static async Task ListMods(string dir) FactorioMods mods = new FactorioMods(dir); var listModFiles = await mods.List(true); - var table = new ConsoleTable("Name", "Local Version", "Latest Version", "Enabled", "Present") + var table = new Table(); + table.AddColumn("Name"); + table.AddColumn("Local Version"); + table.AddColumn("Latest Version"); + table.AddColumn("Enabled"); + table.AddColumn("Present"); + + + foreach (var listModFile in listModFiles) { - Options = + string[] rowData = new string[5]; + + rowData[0] = listModFile.Name; + if (listModFile.LocalVersion == null) { - NumberAlignment = Alignment.Right + rowData[1] = "[maroon]N/A[/]"; } - }; - foreach (var listModFile in listModFiles) - { - table.AddRow(listModFile.Name, listModFile.LocalVersion, listModFile.LatestVersion, listModFile.Enabled, listModFile.Present); + else + { + rowData[1] = listModFile.LocalVersion.ToString(); + } + + + if (listModFile.LocalVersion != null && listModFile.LatestVersion != null) + { + if (listModFile.LocalVersion.ComparePrecedenceTo(listModFile.LatestVersion) < 0) + { + rowData[2] = $"[green]{listModFile.LatestVersion}[/]"; + } + else + { + rowData[2] = listModFile.LatestVersion?.ToString() ?? string.Empty; + } + } + else + { + rowData[2] = listModFile.LatestVersion?.ToString() ?? string.Empty; + } + rowData[3] = listModFile.Enabled.ToString(); + rowData[4] = listModFile.Present.ToString(); + table.AddRow(rowData); } - table.Write(Format.Minimal); + AnsiConsole.Write(table); } private static string GetFactorioModDir()