Skip to content

Commit

Permalink
add checklist counter
Browse files Browse the repository at this point in the history
  • Loading branch information
mebitek committed Jul 10, 2023
1 parent 1cadd1a commit 6489538
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion deck_card/deck_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@ func BuildStacks() {

for _, card := range s.Cards {
var labels = utils.BuildLabels(card)
secondLine := fmt.Sprintf("%s", labels)
checked, total, err := deck_markdown.CountCheckList(card.Description)
if err == nil {
secondLine = fmt.Sprintf("[white]%s | [-:-:-]%s", fmt.Sprintf("%d/%d", checked, total), labels)
}

CardsMap[card.Id] = card

dueDate := ""
Expand All @@ -744,7 +750,7 @@ func BuildStacks() {
assignersFormatter = fmt.Sprintf("- [red:gray:-]%s[-:-:-] ", utils.CommaString(assigners))
}

todoList.AddItem(fmt.Sprintf("[%s]#%d[white] %s- %s %s", configuration.Color, card.Id, assignersFormatter, card.Title, dueDate), labels, rune(0), nil)
todoList.AddItem(fmt.Sprintf("[%s]#%d[white] %s- %s %s", configuration.Color, card.Id, assignersFormatter, card.Title, dueDate), secondLine, rune(0), nil)
}

todoList.SetSelectedFunc(func(index int, name string, secondName string, shortcut rune) {
Expand Down
14 changes: 14 additions & 0 deletions deck_markdown/deck_markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,17 @@ func checkLink(str string) (result [][]string) {
return
}
}

func CountCheckList(description string) (int, int, error) {
re := regexp.MustCompile("- \\[ \\]")
matchUncheckd := re.FindAllStringSubmatch(description, -1)

re = regexp.MustCompile("- \\[x\\]")
matchChecked := re.FindAllStringSubmatch(description, -1)

if len(matchChecked) > 0 || len(matchUncheckd) > 0 {
return len(matchChecked), len(matchUncheckd) + len(matchChecked), nil
}
return 0, 0, fmt.Errorf("no check list found")

}
2 changes: 1 addition & 1 deletion deck_ui/deck_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"tui-deck/utils"
)

const VERSION = "v0.5.14"
const VERSION = "v0.5.15"

var FullFlex = tview.NewFlex()
var MainFlex = tview.NewFlex()
Expand Down

0 comments on commit 6489538

Please sign in to comment.