From 53d2fdacda930d384cf11902431cf80e654bead5 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 3 May 2018 11:26:53 -0700 Subject: [PATCH] A crap version that uses tview's Modal --- todo/widget.go | 28 ++++++++++++++------------ wtf/billboard_modal.go | 45 ------------------------------------------ 2 files changed, 15 insertions(+), 58 deletions(-) delete mode 100644 wtf/billboard_modal.go diff --git a/todo/widget.go b/todo/widget.go index 301fe461..caff21ed 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -16,12 +16,8 @@ import ( var Config *config.Config const helpText = ` - Todo - - h - Displays the help text - o - Opens the todo file in the operating system - - space - checks an item on or off + h: Displays the help text. o: Opens the todo file in the operating system. + space: Checks an item on or off ` type Widget struct { @@ -86,16 +82,19 @@ func (widget *Widget) editItem() { } func (widget *Widget) help() { - cancelFn := func() { - widget.pages.RemovePage("billboard") + cancelFn := func(idx int, label string) { + widget.pages.RemovePage("help") widget.app.SetFocus(widget.View) widget.display() } - billboard := wtf.NewBillboardModal(helpText, cancelFn) + helpModal := tview.NewModal() + helpModal.SetText(helpText) + helpModal.AddButtons([]string{"Close"}) + helpModal.SetDoneFunc(cancelFn) - widget.pages.AddPage("billboard", billboard, false, true) - widget.app.SetFocus(billboard) + widget.pages.AddPage("help", helpModal, false, true) + widget.app.SetFocus(helpModal) } func (widget *Widget) init() { @@ -228,11 +227,14 @@ func (widget *Widget) addButtons(form *tview.Form, saveFctn func()) { } func (widget *Widget) addCancelButton(form *tview.Form) { - form.AddButton("Cancel", func() { + cancelFn := func() { widget.pages.RemovePage("modal") widget.app.SetFocus(widget.View) widget.display() - }) + } + + form.AddButton("Cancel", cancelFn) + form.SetCancelFunc(cancelFn) } func (widget *Widget) addSaveButton(form *tview.Form, fctn func()) { diff --git a/wtf/billboard_modal.go b/wtf/billboard_modal.go deleted file mode 100644 index f217e675..00000000 --- a/wtf/billboard_modal.go +++ /dev/null @@ -1,45 +0,0 @@ -package wtf - -import ( - "github.com/gdamore/tcell" - "github.com/rivo/tview" -) - -type BillboardModal struct{} - -func NewBillboardModal(text string, cancelFn func()) *tview.Frame { - modal := BillboardModal{} - - frame := modal.build(cancelFn) - frame.AddText(text, false, tview.AlignLeft, tcell.ColorWhite) - - return frame -} - -/* -------------------- Unexported Functions -------------------- */ - -func (modal *BillboardModal) build(cancelFn func()) *tview.Frame { - form := modal.buildForm(cancelFn) - frame := modal.buildFrame(form) - - return frame -} - -func (modal *BillboardModal) buildForm(cancelFn func()) *tview.Form { - form := tview.NewForm(). - SetButtonsAlign(tview.AlignCenter). - SetButtonTextColor(tview.Styles.PrimaryTextColor) - - form.AddButton("Cancel", cancelFn) - - return form -} - -func (modal *BillboardModal) buildFrame(form *tview.Form) *tview.Frame { - - frame := tview.NewFrame(form).SetBorders(0, 0, 0, 0, 0, 0) - frame.SetBorder(true) - frame.SetRect(20, 20, 80, 20) - - return frame -}