Skip to content

Commit

Permalink
#11 adding setting to highlight multiple cells
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiCorbilla committed Apr 1, 2021
1 parent 7ee53bd commit c5b2fa7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 52 deletions.
74 changes: 40 additions & 34 deletions table.lib/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions table.lib/HighlightOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> StringValue { get; set; }
public List<decimal> DecimalValue { get; set; }
public ConsoleColor ForegroundColorIfEqual { get; set; } = ConsoleColor.White;
public ConsoleColor BackgroundColorIfEqual { get; set; } = ConsoleColor.DarkGreen;
public ConsoleColor ForegroundColorIfDifferent { get; set; } = ConsoleColor.White;
Expand Down
5 changes: 3 additions & 2 deletions table.lib/table.lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>table.lib</RootNamespace>
<Version>1.6.1</Version>
<Version>1.6.2</Version>
<Copyright>Jordi Corbilla</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/JordiCorbilla/table.lib</RepositoryUrl>
<PackageReleaseNotes>v1.6
- Allow multiple cell highlights for the same column
- Fix bug when dealing with empty records</PackageReleaseNotes>
- Fix bug when dealing with empty records
- Allow multiple cell selection</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Description>Simple c# (.NET 5) table library that renders any List&lt;T&gt; and Dictionary&lt;TV,T&gt; into a nicely formatted markdown, csv, html or console table, allowing for extra formats.</Description>
Expand Down
20 changes: 6 additions & 14 deletions table.runner/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static void SimpleConsoleOutputWithHighlighterForList()
{
Table<TestClass>.Add(GetSampleOutput())
.HighlightValue(new HighlightOperator
{Field = "Field3", Type = HighlightType.Decimal, DecimalValue = 2121.32m})
{Field = "Field3", Type = HighlightType.Decimal, DecimalValue = new List<decimal> { 2121.32m }})
.ToConsole();
}

Expand Down Expand Up @@ -311,22 +311,14 @@ public static void SimpleConsoleOutputWithHighlighterForDictionary()
TableDic<string, TestClass>.Add(GetSimpleDictionary())
.HighlightValue(new HighlightOperator
{
Field = "Field3", Type = HighlightType.Decimal, DecimalValue = 2121.32m,
Field = "Field3", Type = HighlightType.Decimal, DecimalValue = new List<decimal>{ 2121.32m },
Operation = HighlightOperation.Equality
})
.HighlightValue(new HighlightOperator
{
Field = "Field6", Type = HighlightType.Decimal, DecimalValue = 34.43m,
Field = "Field6", Type = HighlightType.Decimal, DecimalValue = new List<decimal>(){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();
}

Expand All @@ -338,9 +330,9 @@ public static void SimpleCsvOutputForDictionary()

public static void SimpleConsoleOutputForDictionary()
{
var dic = new Dictionary<string, string> {{"1", "1"}, {"2", "2"}};
TableDic<string, string>.Add(dic)
.ToConsole();
//var dic = new Dictionary<string, string> {{"1", "1"}, {"2", "2"}};
//TableDic<string, string>.Add(dic)
// .ToConsole();
}

public static void ComplexMarkDownOutputFilteringForDictionary()
Expand Down

0 comments on commit c5b2fa7

Please sign in to comment.