Skip to content

Commit

Permalink
Add colors to console output
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikelH committed Apr 22, 2024
1 parent e74ef7b commit 9d87078
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Main
name: Release
permissions:
contents: write
on:
Expand Down
4 changes: 2 additions & 2 deletions FactorioLib/Types/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion FactorioModUpdater/FactorioModUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ConsoleTables" Version="2.6.1" />
<PackageReference Include="Spectre.Console" Version="0.48.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

Expand Down
49 changes: 40 additions & 9 deletions FactorioModUpdater/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.CommandLine;
using ConsoleTables;
using FactorioLib;
using Spectre.Console;

namespace FactorioModUpdater;

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9d87078

Please sign in to comment.