mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	A crap version that uses tview's Modal
This commit is contained in:
		
							parent
							
								
									6ccdbabec9
								
							
						
					
					
						commit
						53d2fdacda
					
				@ -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()) {
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user