1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/todo/display.go
Chris Cummer 4ad25edc0e 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.
2018-07-12 11:29:41 -07:00

55 lines
1.4 KiB
Go

package todo
import (
"fmt"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
)
const checkWidth = 4
func (widget *Widget) display() {
str := ""
newList := wtf.NewChecklist()
for _, item := range widget.list.UncheckedItems() {
str = str + widget.formattedItemLine(item, widget.list.SelectedItem(), widget.list.LongestLine())
newList.Items = append(newList.Items, item)
}
for _, item := range widget.list.CheckedItems() {
str = str + widget.formattedItemLine(item, widget.list.SelectedItem(), widget.list.LongestLine())
newList.Items = append(newList.Items, item)
}
newList.SetSelectedByItem(widget.list.SelectedItem())
widget.SetList(newList)
widget.View.Clear()
widget.View.SetText(str)
}
func (widget *Widget) formattedItemLine(item *wtf.ChecklistItem, selectedItem *wtf.ChecklistItem, maxLen int) string {
foreColor, backColor := "white", wtf.Config.UString("wtf.colors.background", "black")
if item.Checked {
foreColor = wtf.Config.UString("wtf.colors.checked", "white")
}
if widget.View.HasFocus() && (item == selectedItem) {
foreColor = wtf.Config.UString("wtf.colors.highlight.fore", "black")
backColor = wtf.Config.UString("wtf.colors.highlight.back", "orange")
}
str := fmt.Sprintf(
"[%s:%s]|%s| %s[white]",
foreColor,
backColor,
item.CheckMark(),
tview.Escape(item.Text),
)
return str + wtf.PadRow((checkWidth+len(item.Text)), (checkWidth+maxLen+1)) + "\n"
}