Skip to content

Commit

Permalink
Merge pull request #77 from rprouse/issue/76
Browse files Browse the repository at this point in the history
Do not display Id or Updated metatags
  • Loading branch information
rprouse authored Sep 30, 2024
2 parents 66c8351 + ab764c2 commit da44fb9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/todo.domain/Entities/TaskItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/todo/todo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://github.com/rprouse/dotnet-todo</PackageProjectUrl>
<RepositoryUrl>https://github.com/rprouse/dotnet-todo</RepositoryUrl>
<PackageId>dotnet-todo</PackageId>
<Version>0.6.0</Version>
<Version>0.6.1</Version>
<PackAsTool>true</PackAsTool>
<ToolCommandName>todo</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
Expand Down
17 changes: 17 additions & 0 deletions tests/todo.tests/Domain/Entities/TaskItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit da44fb9

Please sign in to comment.