From 8fc6b83d59a99563f15a11e26c332c3e2e58f849 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Wed, 18 Jul 2018 10:15:46 -0700 Subject: [PATCH] Move generic checklist code into its own package --- {wtf => checklist}/checklist.go | 2 +- {wtf => checklist}/checklist_item.go | 8 ++++++-- todo/display.go | 5 +++-- todo/widget.go | 7 ++++--- 4 files changed, 14 insertions(+), 8 deletions(-) rename {wtf => checklist}/checklist.go (99%) rename {wtf => checklist}/checklist_item.go (80%) diff --git a/wtf/checklist.go b/checklist/checklist.go similarity index 99% rename from wtf/checklist.go rename to checklist/checklist.go index 4aa60c75..af55b03c 100644 --- a/wtf/checklist.go +++ b/checklist/checklist.go @@ -1,4 +1,4 @@ -package wtf +package checklist // Checklist is a module for creating generic checklist implementations // See 'Todo' for an implementation example diff --git a/wtf/checklist_item.go b/checklist/checklist_item.go similarity index 80% rename from wtf/checklist_item.go rename to checklist/checklist_item.go index 514ef714..f1bb1547 100644 --- a/wtf/checklist_item.go +++ b/checklist/checklist_item.go @@ -1,4 +1,8 @@ -package wtf +package checklist + +import ( + "github.com/senorprogrammer/wtf/wtf" +) // ChecklistItem is a module for creating generic checklist implementations // 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 func (item *ChecklistItem) CheckMark() string { if item.Checked { - return Config.UString("wtf.mods.todo.checkedIcon", "x") + return wtf.Config.UString("wtf.mods.todo.checkedIcon", "x") } else { return " " } diff --git a/todo/display.go b/todo/display.go index 1a2027b5..057e94d5 100644 --- a/todo/display.go +++ b/todo/display.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/senorprogrammer/wtf/checklist" "github.com/senorprogrammer/wtf/wtf" ) @@ -11,7 +12,7 @@ const checkWidth = 4 func (widget *Widget) display() { str := "" - newList := wtf.NewChecklist() + newList := checklist.NewChecklist() for _, item := range widget.list.UncheckedItems() { str = str + widget.formattedItemLine(item, widget.list.SelectedItem(), widget.list.LongestLine()) @@ -30,7 +31,7 @@ func (widget *Widget) display() { 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") if item.Checked { diff --git a/todo/widget.go b/todo/widget.go index c0d9bef1..7ce923e5 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -7,6 +7,7 @@ import ( "github.com/gdamore/tcell" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/cfg" + "github.com/senorprogrammer/wtf/checklist" "github.com/senorprogrammer/wtf/wtf" "gopkg.in/yaml.v2" ) @@ -39,7 +40,7 @@ type Widget struct { app *tview.Application filePath string - list wtf.Checklist + list checklist.Checklist pages *tview.Pages } @@ -49,7 +50,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { app: app, filePath: wtf.Config.UString("wtf.mods.todo.filename"), - list: wtf.NewChecklist(), + list: checklist.NewChecklist(), pages: pages, } @@ -67,7 +68,7 @@ func (widget *Widget) Refresh() { widget.display() } -func (widget *Widget) SetList(newList wtf.Checklist) { +func (widget *Widget) SetList(newList checklist.Checklist) { widget.list = newList }