Skip to content

Commit 6489538

Browse files
committed
add checklist counter
1 parent 1cadd1a commit 6489538

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

deck_card/deck_card.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,12 @@ func BuildStacks() {
725725

726726
for _, card := range s.Cards {
727727
var labels = utils.BuildLabels(card)
728+
secondLine := fmt.Sprintf("%s", labels)
729+
checked, total, err := deck_markdown.CountCheckList(card.Description)
730+
if err == nil {
731+
secondLine = fmt.Sprintf("[white]%s | [-:-:-]%s", fmt.Sprintf("%d/%d", checked, total), labels)
732+
}
733+
728734
CardsMap[card.Id] = card
729735

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

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

750756
todoList.SetSelectedFunc(func(index int, name string, secondName string, shortcut rune) {

deck_markdown/deck_markdown.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,17 @@ func checkLink(str string) (result [][]string) {
105105
return
106106
}
107107
}
108+
109+
func CountCheckList(description string) (int, int, error) {
110+
re := regexp.MustCompile("- \\[ \\]")
111+
matchUncheckd := re.FindAllStringSubmatch(description, -1)
112+
113+
re = regexp.MustCompile("- \\[x\\]")
114+
matchChecked := re.FindAllStringSubmatch(description, -1)
115+
116+
if len(matchChecked) > 0 || len(matchUncheckd) > 0 {
117+
return len(matchChecked), len(matchUncheckd) + len(matchChecked), nil
118+
}
119+
return 0, 0, fmt.Errorf("no check list found")
120+
121+
}

deck_ui/deck_ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"tui-deck/utils"
88
)
99

10-
const VERSION = "v0.5.14"
10+
const VERSION = "v0.5.15"
1111

1212
var FullFlex = tview.NewFlex()
1313
var MainFlex = tview.NewFlex()

0 commit comments

Comments
 (0)