mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
insert highlight regions for scrolling
This commit is contained in:
parent
c705297805
commit
77e5ca087e
@ -2,6 +2,7 @@ package todo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/senorprogrammer/wtf/checklist"
|
"github.com/senorprogrammer/wtf/checklist"
|
||||||
@ -14,14 +15,18 @@ func (widget *Widget) display() {
|
|||||||
str := ""
|
str := ""
|
||||||
newList := checklist.NewChecklist()
|
newList := checklist.NewChecklist()
|
||||||
|
|
||||||
for _, item := range widget.list.UncheckedItems() {
|
offset := 0
|
||||||
str = str + widget.formattedItemLine(item, widget.list.SelectedItem(), widget.list.LongestLine())
|
|
||||||
|
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)
|
newList.Items = append(newList.Items, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range widget.list.CheckedItems() {
|
for idx, item := range widget.list.CheckedItems() {
|
||||||
str = str + widget.formattedItemLine(item, widget.list.SelectedItem(), widget.list.LongestLine())
|
str = str + widget.formattedItemLine(idx + offset, item, widget.list.SelectedItem(), widget.list.LongestLine())
|
||||||
newList.Items = append(newList.Items, item)
|
newList.Items = append(newList.Items, item)
|
||||||
|
|
||||||
|
offset++
|
||||||
}
|
}
|
||||||
|
|
||||||
newList.SetSelectedByItem(widget.list.SelectedItem())
|
newList.SetSelectedByItem(widget.list.SelectedItem())
|
||||||
@ -29,9 +34,10 @@ func (widget *Widget) display() {
|
|||||||
|
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
widget.View.SetText(str)
|
widget.View.SetText(str)
|
||||||
|
widget.View.Highlight(strconv.Itoa(widget.list.Selected)).ScrollToHighlight()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) formattedItemLine(item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {
|
func (widget *Widget) formattedItemLine(idx int, item *checklist.ChecklistItem, selectedItem *checklist.ChecklistItem, maxLen int) string {
|
||||||
foreColor, backColor := "white", wtf.Config.UString("wtf.colors.background", "black")
|
foreColor, backColor := "white", wtf.Config.UString("wtf.colors.background", "black")
|
||||||
|
|
||||||
if item.Checked {
|
if item.Checked {
|
||||||
@ -44,7 +50,8 @@ func (widget *Widget) formattedItemLine(item *checklist.ChecklistItem, selectedI
|
|||||||
}
|
}
|
||||||
|
|
||||||
str := fmt.Sprintf(
|
str := fmt.Sprintf(
|
||||||
"[%s:%s]|%s| %s[white]",
|
`["%d"][%s:%s]|%s| %s[-][""]`,
|
||||||
|
idx,
|
||||||
foreColor,
|
foreColor,
|
||||||
backColor,
|
backColor,
|
||||||
item.CheckMark(),
|
item.CheckMark(),
|
||||||
|
@ -55,6 +55,8 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
widget.init()
|
widget.init()
|
||||||
|
widget.View.SetScrollable(true)
|
||||||
|
widget.View.SetRegions(true)
|
||||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
|
Loading…
x
Reference in New Issue
Block a user