1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

First pass at creating a generic checklist component

The idea is that checklist-like modules would all share an underlying
checklist implementation (ie: Todo and Todoist) to avoid duplication.
This commit is contained in:
Chris Cummer
2018-07-12 11:14:52 -07:00
parent 236005ab48
commit 4ad25edc0e
8 changed files with 237 additions and 211 deletions

View File

@@ -8,6 +8,8 @@ import (
"github.com/senorprogrammer/wtf/wtf"
)
const checkWidth = 4
func (w *Widget) display() {
if len(w.list) == 0 {
return
@@ -17,11 +19,25 @@ func (w *Widget) display() {
w.View.SetTitle(fmt.Sprintf("%s- [green]%s[white] ", w.Name, list.Project.Name))
str := wtf.SigilStr(len(w.list), w.idx, w.View) + "\n"
maxLen := w.list[w.idx].LongestLine()
for index, item := range list.items {
foreColor, backColor := "white", wtf.Config.UString("wtf.colors.background", "black")
if index == list.index {
str = str + fmt.Sprintf("[%s]", wtf.Config.UString("wtf.colors.border.focused", "grey"))
foreColor = wtf.Config.UString("wtf.colors.highlight.fore", "black")
backColor = wtf.Config.UString("wtf.colors.highlight.back", "orange")
}
str = str + fmt.Sprintf("| | %s[white]\n", tview.Escape(item.Content))
row := fmt.Sprintf(
"[%s:%s]| | %s[white]",
foreColor,
backColor,
tview.Escape(item.Content),
)
row = row + wtf.PadRow((checkWidth+len(item.Content)), (checkWidth+maxLen+1)) + "\n"
str = str + row
}
w.View.Clear()

View File

@@ -62,6 +62,18 @@ func (l *List) loadItems() {
l.items = tasks
}
func (list *List) LongestLine() int {
maxLen := 0
for _, item := range list.items {
if len(item.Content) > maxLen {
maxLen = len(item.Content)
}
}
return maxLen
}
func (l *List) close() {
if err := l.items[l.index].Close(); err != nil {
panic(err)