diff --git a/Sharp7.Monitor/CustomStyles.cs b/Sharp7.Monitor/CustomStyles.cs index eddd410..ba0a184 100644 --- a/Sharp7.Monitor/CustomStyles.cs +++ b/Sharp7.Monitor/CustomStyles.cs @@ -4,7 +4,10 @@ namespace Sharp7.Monitor; public static class CustomStyles { - public static Style Error { get; } = new Style(foreground: Color.Red); - public static Style Note { get; } = new(foreground: Color.DarkSlateGray1); - public static Style? Hex { get; } = new(foreground: Color.Blue); -} \ No newline at end of file + public static Style Default { get; } = new(background:Color.Black); + + public static Style Error { get; } = Default.Foreground(Color.Red); + public static Style Hex { get; } = Default.Foreground(Color.Blue); + public static Style Note { get; } = Default.Foreground(Color.DarkSlateGray1); + public static Style TableBorder { get; } = Default.Foreground(Color.DarkGreen); +} diff --git a/Sharp7.Monitor/Program.cs b/Sharp7.Monitor/Program.cs index 1c8c834..85bff90 100644 --- a/Sharp7.Monitor/Program.cs +++ b/Sharp7.Monitor/Program.cs @@ -1,5 +1,5 @@ -using System.Text; -using Spectre.Console; +using System.Diagnostics.CodeAnalysis; +using System.Text; using Spectre.Console.Cli; namespace Sharp7.Monitor; @@ -8,11 +8,15 @@ internal class Program { private static readonly CancellationTokenSource cts = new(); + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ReadPlcCommand))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ReadPlcCommand.Settings))] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, "Spectre.Console.Cli.ExplainCommand", "Spectre.Console.Cli")] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, "Spectre.Console.Cli.VersionCommand", "Spectre.Console.Cli")] + [DynamicDependency(DynamicallyAccessedMemberTypes.All, "Spectre.Console.Cli.XmlDocCommand", "Spectre.Console.Cli")] public static async Task Main(string[] args) { Console.InputEncoding = Console.OutputEncoding = Encoding.UTF8; - Console.CancelKeyPress += OnCancelKeyPress; AppDomain.CurrentDomain.ProcessExit += OnProcessExit; @@ -25,22 +29,17 @@ internal class Program app.Configure(config => { config.SetApplicationName("s7mon.exe"); }); - await app.RunAsync(args); + return await app.RunAsync(args); } catch (OperationCanceledException) { + return 0; } finally { AppDomain.CurrentDomain.ProcessExit -= OnProcessExit; Console.CancelKeyPress -= OnCancelKeyPress; } - - AnsiConsole.WriteLine(); - AnsiConsole.MarkupLine("[lightgoldenrod2_1]THANK YOU FOR PARTICIPATING IN THIS ENRICHMENT CENTER ACTIVITY![/]"); - AnsiConsole.WriteLine(); - - return 0; } private static void OnCancelKeyPress(object? sender, ConsoleCancelEventArgs e) @@ -62,4 +61,4 @@ internal class Program cts.Cancel(); } -} \ No newline at end of file +} diff --git a/Sharp7.Monitor/ReadPlcCommand.cs b/Sharp7.Monitor/ReadPlcCommand.cs index 5f87aaa..85a3c34 100644 --- a/Sharp7.Monitor/ReadPlcCommand.cs +++ b/Sharp7.Monitor/ReadPlcCommand.cs @@ -24,6 +24,10 @@ internal sealed class ReadPlcCommand : AsyncCommand { } + AnsiConsole.WriteLine(); + AnsiConsole.MarkupLine("[lightgoldenrod2_1]THANK YOU FOR PARTICIPATING IN THIS ENRICHMENT CENTER ACTIVITY![/]"); + AnsiConsole.WriteLine(); + return 0; } @@ -42,10 +46,10 @@ internal sealed class ReadPlcCommand : AsyncCommand long => FormatNo(), ulong => FormatNo(), - _ => new Text(value.ToString() ?? "") + _ => new Text(value.ToString() ?? "", CustomStyles.Default) }; - Markup FormatNo() => new($"[blue]0x{value:X2}[/] {value}"); + Markup FormatNo() => new($"[blue]0x{value:X2}[/] {value}", CustomStyles.Default); } private static async Task RunProgram(Settings settings, CancellationToken token) @@ -84,14 +88,14 @@ internal sealed class ReadPlcCommand : AsyncCommand var table = new Table { Border = TableBorder.Rounded, - BorderStyle = new Style(foreground: Color.DarkGreen) + BorderStyle = CustomStyles.TableBorder, }; - table.AddColumn("Variable"); - table.AddColumn("Value"); + table.AddColumn(new TableColumn(new Text("Variable", CustomStyles.Default))); + table.AddColumn(new TableColumn(new Text( "Value", CustomStyles.Default))); foreach (var record in variableContainer.VariableRecords) - table.AddRow(record.Address, "[gray]init[/]"); + table.AddRow(new Text( record.Address, CustomStyles.Default), new Text("init", CustomStyles.Note)); await AnsiConsole.Live(table) .StartAsync(async ctx => @@ -144,4 +148,4 @@ internal sealed class ReadPlcCommand : AsyncCommand return ValidationResult.Success(); } } -} \ No newline at end of file +} diff --git a/Sharp7.Monitor/Sharp7.Monitor.csproj b/Sharp7.Monitor/Sharp7.Monitor.csproj index b563862..7ab385e 100644 --- a/Sharp7.Monitor/Sharp7.Monitor.csproj +++ b/Sharp7.Monitor/Sharp7.Monitor.csproj @@ -2,10 +2,15 @@ Exe + s7mon + + true + net8.0 enable enable - s7mon + + true diff --git a/publish.ps1 b/publish.ps1 new file mode 100644 index 0000000..2d4a63f --- /dev/null +++ b/publish.ps1 @@ -0,0 +1,4 @@ + +dotnet publish .\Sharp7.Monitor\Sharp7.Monitor.csproj -c Release --output publish\non-sc --no-self-contained + +dotnet publish .\Sharp7.Monitor\Sharp7.Monitor.csproj -c Release --output publish\sc -p:PublishTrimmed=true -p:EnableCompressionInSingleFile=true --self-contained