1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Move generic checklist code into its own package

This commit is contained in:
Chris Cummer 2018-07-18 10:15:46 -07:00
parent 0cdfe8d785
commit 8fc6b83d59
4 changed files with 14 additions and 8 deletions

View File

@ -1,4 +1,4 @@
package wtf package checklist
// Checklist is a module for creating generic checklist implementations // Checklist is a module for creating generic checklist implementations
// See 'Todo' for an implementation example // See 'Todo' for an implementation example

View File

@ -1,4 +1,8 @@
package wtf package checklist
import (
"github.com/senorprogrammer/wtf/wtf"
)
// ChecklistItem is a module for creating generic checklist implementations // ChecklistItem is a module for creating generic checklist implementations
// See 'Todo' for an implementation example // See 'Todo' for an implementation example
@ -10,7 +14,7 @@ type ChecklistItem struct {
// CheckMark returns the string used to indicate a ChecklistItem is checked or unchecked // CheckMark returns the string used to indicate a ChecklistItem is checked or unchecked
func (item *ChecklistItem) CheckMark() string { func (item *ChecklistItem) CheckMark() string {
if item.Checked { if item.Checked {
return Config.UString("wtf.mods.todo.checkedIcon", "x") return wtf.Config.UString("wtf.mods.todo.checkedIcon", "x")
} else { } else {
return " " return " "
} }

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/senorprogrammer/wtf/checklist"
"github.com/senorprogrammer/wtf/wtf" "github.com/senorprogrammer/wtf/wtf"
) )
@ -11,7 +12,7 @@ const checkWidth = 4
func (widget *Widget) display() { func (widget *Widget) display() {
str := "" str := ""
newList := wtf.NewChecklist() newList := checklist.NewChecklist()
for _, item := range widget.list.UncheckedItems() { for _, item := range widget.list.UncheckedItems() {
str = str + widget.formattedItemLine(item, widget.list.SelectedItem(), widget.list.LongestLine()) str = str + widget.formattedItemLine(item, widget.list.SelectedItem(), widget.list.LongestLine())
@ -30,7 +31,7 @@ func (widget *Widget) display() {
widget.View.SetText(str) widget.View.SetText(str)
} }
func (widget *Widget) formattedItemLine(item *wtf.ChecklistItem, selectedItem *wtf.ChecklistItem, maxLen int) string { func (widget *Widget) formattedItemLine(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 {

View File

@ -7,6 +7,7 @@ import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/senorprogrammer/wtf/cfg" "github.com/senorprogrammer/wtf/cfg"
"github.com/senorprogrammer/wtf/checklist"
"github.com/senorprogrammer/wtf/wtf" "github.com/senorprogrammer/wtf/wtf"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -39,7 +40,7 @@ type Widget struct {
app *tview.Application app *tview.Application
filePath string filePath string
list wtf.Checklist list checklist.Checklist
pages *tview.Pages pages *tview.Pages
} }
@ -49,7 +50,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
app: app, app: app,
filePath: wtf.Config.UString("wtf.mods.todo.filename"), filePath: wtf.Config.UString("wtf.mods.todo.filename"),
list: wtf.NewChecklist(), list: checklist.NewChecklist(),
pages: pages, pages: pages,
} }
@ -67,7 +68,7 @@ func (widget *Widget) Refresh() {
widget.display() widget.display()
} }
func (widget *Widget) SetList(newList wtf.Checklist) { func (widget *Widget) SetList(newList checklist.Checklist) {
widget.list = newList widget.list = newList
} }