1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/todo/display.go
Sean Smith a5f98c138a Move closing region tag to the end of the line
Highlight works by highlighting the entire region that exists
Since current region starts and immediately ends, there is no highlighting
2019-05-09 11:00:19 -04:00

70 lines
1.8 KiB
Go

package todo
import (
"fmt"
"strconv"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/checklist"
"github.com/wtfutil/wtf/wtf"
)
const checkWidth = 4
func (widget *Widget) display() {
str := ""
newList := checklist.NewChecklist(
widget.settings.common.Sigils.Checkbox.Checked,
widget.settings.common.Sigils.Checkbox.Unchecked,
)
offset := 0
for idx, item := range widget.list.UncheckedItems() {
str = str + widget.formattedItemLine(idx, item, widget.list.SelectedItem(), widget.list.LongestLine())
newList.Items = append(newList.Items, item)
offset++
}
for idx, item := range widget.list.CheckedItems() {
str = str + widget.formattedItemLine(idx+offset, 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)
widget.View.Highlight(strconv.Itoa(widget.list.Selected())).ScrollToHighlight()
}
func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {
foreColor, backColor := widget.settings.common.Colors.Text, widget.settings.common.Colors.Background
if item.Checked {
foreColor = widget.settings.common.Colors.Checked
}
if widget.View.HasFocus() && (item == selectedItem) {
foreColor = widget.settings.common.Colors.HighlightFore
backColor = widget.settings.common.Colors.HighlightBack
}
str := fmt.Sprintf(
`["%d"][%s:%s]|%s| %s[white][""]`,
idx,
foreColor,
backColor,
item.CheckMark(),
tview.Escape(item.Text),
)
_, _, w, _ := widget.View.GetInnerRect()
if w > maxLen {
maxLen = w
}
return str + wtf.PadRow((checkWidth+len(item.Text)), (checkWidth+maxLen+1)) + "\n"
}