1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/todo/display.go
Chris Cummer 200dbcc03c
WTF-730 Fix missing color key config error (#738)
* WTF-730 Fix missing color key config error

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Add Subheading color formatting to modules

Users can now set a `subheading` color in their config to change the
color of subheadings in widget display.

Defaults to `red`.

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix oustanding color issues

Clean up missing color config changes not addressed in earlier commits.

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Remove unused dependency

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Base cleanup

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix a few bugs related to color config changes

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix issues with PagerDuty subheading display

Signed-off-by: Chris Cummer <chriscummer@me.com>

* WTF-730 Fix bug with Todo list colour rendering

Signed-off-by: Chris Cummer <chriscummer@me.com>
2019-11-09 11:21:45 -08:00

64 lines
1.5 KiB
Go

package todo
import (
"fmt"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/checklist"
"github.com/wtfutil/wtf/utils"
)
func (widget *Widget) display() {
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
str := ""
newList := checklist.NewChecklist(
widget.settings.common.Sigils.Checkbox.Checked,
widget.settings.common.Sigils.Checkbox.Unchecked,
)
offset := 0
selectedItem := widget.SelectedItem()
for idx, item := range widget.list.UncheckedItems() {
str += widget.formattedItemLine(idx, item, selectedItem, widget.list.LongestLine())
newList.Items = append(newList.Items, item)
offset++
}
for idx, item := range widget.list.CheckedItems() {
str += widget.formattedItemLine(idx+offset, item, selectedItem, widget.list.LongestLine())
newList.Items = append(newList.Items, item)
}
if idx, ok := newList.IndexByItem(selectedItem); ok {
widget.Selected = idx
}
widget.SetList(newList)
return widget.CommonSettings().Title, str, false
}
func (widget *Widget) formattedItemLine(idx int, currItem *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {
rowColor := widget.RowColor(idx)
if currItem.Checked {
rowColor = widget.settings.common.Colors.CheckboxTheme.Checked
}
if widget.View.HasFocus() && (currItem == selectedItem) {
rowColor = widget.RowColor(idx)
}
row := fmt.Sprintf(
` [%s]|%s| %s[white]`,
rowColor,
currItem.CheckMark(),
tview.Escape(currItem.Text),
)
return utils.HighlightableHelper(widget.View, row, idx, len(currItem.Text))
}