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:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user