From ab764c2b4060e447cbf207b7e1068b9c7f63daea Mon Sep 17 00:00:00 2001 From: Rob Prouse Date: Mon, 30 Sep 2024 10:53:16 -0400 Subject: [PATCH] Do not display Id or Updated metatags --- src/todo.domain/Entities/TaskItem.cs | 27 ++++++++++++++----- src/todo/todo.csproj | 2 +- .../Domain/Entities/TaskItemTests.cs | 17 ++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/todo.domain/Entities/TaskItem.cs b/src/todo.domain/Entities/TaskItem.cs index 390657c..4a6fb2f 100644 --- a/src/todo.domain/Entities/TaskItem.cs +++ b/src/todo.domain/Entities/TaskItem.cs @@ -226,26 +226,41 @@ public ColoredString[] ToColorString(bool includeLineNumber, ITaskConfiguration string[] words = Description.Split(' ', '\t'); foreach (string word in words) { - if(word.StartsWith("+")) - tokens.Add(new ColoredString($"{word} ", + if (word.StartsWith('+')) + { + tokens.Add(new ColoredString($"{word} ", config.ProjectColor?.Color ?? priorityColor?.Color, config.ProjectColor?.BackgroundColor ?? priorityColor?.BackgroundColor)); - else if (word.StartsWith("@")) + } + else if (word.StartsWith('@')) + { tokens.Add(new ColoredString($"{word} ", config.ContextColor?.Color ?? priorityColor?.Color, config.ContextColor?.BackgroundColor ?? priorityColor?.BackgroundColor)); + } else if (word.Contains(":")) - tokens.Add(new ColoredString($"{word} ", - config.MetaColor?.Color ?? priorityColor?.Color, - config.MetaColor?.BackgroundColor ?? priorityColor?.BackgroundColor)); + { + if (DisplayMeta(word)) + { + tokens.Add(new ColoredString($"{word} ", + config.MetaColor?.Color ?? priorityColor?.Color, + config.MetaColor?.BackgroundColor ?? priorityColor?.BackgroundColor)); + } + } else + { tokens.Add(new ColoredString($"{word} ", priorityColor?.Color, priorityColor?.BackgroundColor)); + } } return tokens.ToArray(); } + // Do not display ID or Updated metadata + private static bool DisplayMeta(string meta) => + !meta.ToLowerInvariant().StartsWith("id:") && !meta.ToLowerInvariant().StartsWith("updated:"); + public override bool Equals(object obj) { if(obj is TaskItem task) diff --git a/src/todo/todo.csproj b/src/todo/todo.csproj index 3118062..ae50a63 100644 --- a/src/todo/todo.csproj +++ b/src/todo/todo.csproj @@ -13,7 +13,7 @@ https://github.com/rprouse/dotnet-todo https://github.com/rprouse/dotnet-todo dotnet-todo - 0.6.0 + 0.6.1 true todo ./nupkg diff --git a/tests/todo.tests/Domain/Entities/TaskItemTests.cs b/tests/todo.tests/Domain/Entities/TaskItemTests.cs index af982e3..fb863af 100644 --- a/tests/todo.tests/Domain/Entities/TaskItemTests.cs +++ b/tests/todo.tests/Domain/Entities/TaskItemTests.cs @@ -199,5 +199,22 @@ public void TokenizesMeta(string line, int pos) result[pos].Color.Should().Be(ConsoleColor.DarkCyan); result[pos].BackgroundColor.Should().BeNull(); } + + [TestCase("id:1234 one two")] + [TestCase("one id:1234 two")] + [TestCase("one two id:1234")] + [TestCase("updated:1234 one two")] + [TestCase("one updated:1234 two")] + [TestCase("one two updated:1234")] + [TestCase("one two id:1234 updated:1234")] + [TestCase("one two Id:1234 Updated:1234")] + [TestCase("one two ID:1234 UPDATED:1234")] + public void DoesNotIncludeIdOrUpdatedMeta(string line) + { + var config = new TaskConfiguration(); + var task = new TaskItem(line); + var result = task.ToColorString(false, config); + result.Should().HaveCount(2); + } } }