use pttodo.Todos.Like...()

This commit is contained in:
Bel LaPointe
2023-11-06 13:06:11 -07:00
parent 39345e5e2a
commit bfdeebb7a2
3 changed files with 55 additions and 26 deletions

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"io"
"os"
"strings"
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
"gopkg.in/yaml.v2"
@@ -31,31 +30,8 @@ func _dump(writer io.Writer, filepaths []string, tags []string, search, rootDisp
v = root.Done
}
if todos, ok := v.([]pttodo.Todo); ok {
if len(tags) > 0 {
result := make([]pttodo.Todo, 0, len(todos))
for _, todo := range todos {
skip := false
for _, tag := range tags {
positiveTag := strings.TrimLeft(tag, "-")
hasTag := strings.Contains(todo.Tags, positiveTag)
wantToHaveTag := !strings.HasPrefix(tag, "-")
skip = skip || !(hasTag == wantToHaveTag)
}
if !skip {
result = append(result, todo)
}
}
todos = result
}
if len(search) > 0 {
result := make([]pttodo.Todo, 0, len(todos))
for _, todo := range todos {
if strings.Contains(strings.ToLower(fmt.Sprint(todo)), strings.ToLower(search)) {
result = append(result, todo)
}
}
todos = result
}
todos = pttodo.Todos(todos).LikeTags(tags)
todos = pttodo.Todos(todos).LikeSearch(search)
v = todos
}