diff --git a/table.lib/Base.cs b/table.lib/Base.cs index 58a9ed4..3f5a056 100644 --- a/table.lib/Base.cs +++ b/table.lib/Base.cs @@ -119,29 +119,32 @@ public void ConsoleRender(string value, string column) try { var parsed = decimal.Parse(value.Trim()); - switch (item.Operation) + foreach (var num in item.DecimalValue) { - case HighlightOperation.Differences - when parsed != item.DecimalValue: - Console.BackgroundColor = item.BackgroundColorIfDifferent; - Console.ForegroundColor = item.ForegroundColorIfDifferent; - break; - case HighlightOperation.Differences: - Console.BackgroundColor = item.BackgroundColorIfEqual; - Console.ForegroundColor = item.ForegroundColorIfEqual; - break; - case HighlightOperation.Equality: + switch (item.Operation) { - if (parsed == item.DecimalValue) - { + case HighlightOperation.Differences + when parsed != num: + Console.BackgroundColor = item.BackgroundColorIfDifferent; + Console.ForegroundColor = item.ForegroundColorIfDifferent; + break; + case HighlightOperation.Differences: Console.BackgroundColor = item.BackgroundColorIfEqual; Console.ForegroundColor = item.ForegroundColorIfEqual; - } + break; + case HighlightOperation.Equality: + { + if (parsed == num) + { + Console.BackgroundColor = item.BackgroundColorIfEqual; + Console.ForegroundColor = item.ForegroundColorIfEqual; + } - break; + break; + } + default: + throw new ArgumentOutOfRangeException(); } - default: - throw new ArgumentOutOfRangeException(); } } catch @@ -153,29 +156,32 @@ public void ConsoleRender(string value, string column) case HighlightType.String: try { - switch (item.Operation) + foreach (var str in item.StringValue) { - case HighlightOperation.Differences - when value.Trim() != item.StringValue: - Console.BackgroundColor = item.BackgroundColorIfDifferent; - Console.ForegroundColor = item.ForegroundColorIfDifferent; - break; - case HighlightOperation.Differences: - Console.BackgroundColor = item.BackgroundColorIfEqual; - Console.ForegroundColor = item.ForegroundColorIfEqual; - break; - case HighlightOperation.Equality: + switch (item.Operation) { - if (value.Trim() == item.StringValue) - { + case HighlightOperation.Differences + when value.Trim() != str: + Console.BackgroundColor = item.BackgroundColorIfDifferent; + Console.ForegroundColor = item.ForegroundColorIfDifferent; + break; + case HighlightOperation.Differences: Console.BackgroundColor = item.BackgroundColorIfEqual; Console.ForegroundColor = item.ForegroundColorIfEqual; - } + break; + case HighlightOperation.Equality: + { + if (value.Trim() == str) + { + Console.BackgroundColor = item.BackgroundColorIfEqual; + Console.ForegroundColor = item.ForegroundColorIfEqual; + } - break; + break; + } + default: + throw new ArgumentOutOfRangeException(); } - default: - throw new ArgumentOutOfRangeException(); } } catch diff --git a/table.lib/HighlightOperator.cs b/table.lib/HighlightOperator.cs index d07366a..d853a58 100644 --- a/table.lib/HighlightOperator.cs +++ b/table.lib/HighlightOperator.cs @@ -43,14 +43,15 @@ //SOFTWARE. using System; +using System.Collections.Generic; namespace table.lib { public class HighlightOperator { public string Field { get; set; } - public string StringValue { get; set; } - public decimal DecimalValue { get; set; } + public List StringValue { get; set; } + public List DecimalValue { get; set; } public ConsoleColor ForegroundColorIfEqual { get; set; } = ConsoleColor.White; public ConsoleColor BackgroundColorIfEqual { get; set; } = ConsoleColor.DarkGreen; public ConsoleColor ForegroundColorIfDifferent { get; set; } = ConsoleColor.White; diff --git a/table.lib/table.lib.csproj b/table.lib/table.lib.csproj index 0a2f7d6..2dd8a1a 100644 --- a/table.lib/table.lib.csproj +++ b/table.lib/table.lib.csproj @@ -3,13 +3,14 @@ net5.0 table.lib - 1.6.1 + 1.6.2 Jordi Corbilla LICENSE https://github.com/JordiCorbilla/table.lib v1.6 - Allow multiple cell highlights for the same column -- Fix bug when dealing with empty records +- Fix bug when dealing with empty records +- Allow multiple cell selection true true Simple c# (.NET 5) table library that renders any List<T> and Dictionary<TV,T> into a nicely formatted markdown, csv, html or console table, allowing for extra formats. diff --git a/table.runner/Samples.cs b/table.runner/Samples.cs index 571e617..11b0099 100644 --- a/table.runner/Samples.cs +++ b/table.runner/Samples.cs @@ -192,7 +192,7 @@ public static void SimpleConsoleOutputWithHighlighterForList() { Table.Add(GetSampleOutput()) .HighlightValue(new HighlightOperator - {Field = "Field3", Type = HighlightType.Decimal, DecimalValue = 2121.32m}) + {Field = "Field3", Type = HighlightType.Decimal, DecimalValue = new List { 2121.32m }}) .ToConsole(); } @@ -311,22 +311,14 @@ public static void SimpleConsoleOutputWithHighlighterForDictionary() TableDic.Add(GetSimpleDictionary()) .HighlightValue(new HighlightOperator { - Field = "Field3", Type = HighlightType.Decimal, DecimalValue = 2121.32m, + Field = "Field3", Type = HighlightType.Decimal, DecimalValue = new List{ 2121.32m }, Operation = HighlightOperation.Equality }) .HighlightValue(new HighlightOperator { - Field = "Field6", Type = HighlightType.Decimal, DecimalValue = 34.43m, + Field = "Field6", Type = HighlightType.Decimal, DecimalValue = new List(){34.43m, 134.43m}, Operation = HighlightOperation.Equality }) - .HighlightValue(new HighlightOperator - { - Field = "Field6", - Type = HighlightType.Decimal, - DecimalValue = 134.43m, - Operation = HighlightOperation.Equality, - BackgroundColorIfEqual = ConsoleColor.DarkBlue - }) .ToConsole(); } @@ -338,9 +330,9 @@ public static void SimpleCsvOutputForDictionary() public static void SimpleConsoleOutputForDictionary() { - var dic = new Dictionary {{"1", "1"}, {"2", "2"}}; - TableDic.Add(dic) - .ToConsole(); + //var dic = new Dictionary {{"1", "1"}, {"2", "2"}}; + //TableDic.Add(dic) + // .ToConsole(); } public static void ComplexMarkDownOutputFilteringForDictionary()