town/cmd/welcome/main.go

87 lines
1.9 KiB
Go

package main
import (
"fmt"
"os"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
_ "embed"
)
//go:embed welcome.txt
var welcomeArt string
// TODO remove ConnectDB abstraction in favor of just connecting directly to sqliteh
// TODO move magic key machine to static page
type newUserData struct {
Username string
DisplayName string
Email string
PubKey string
}
func _main() error {
app := tview.NewApplication()
//data := &newUserData{}
help := tview.NewTextView()
help.SetText("tab+enter or mouse to submit. ctrl+c to quit.")
help.SetTextColor(tcell.ColorGray)
artView := tview.NewTextView()
artView.SetText(welcomeArt)
artView.SetDynamicColors(true)
artView.SetBackgroundColor(tcell.ColorBlack)
artView.SetTextColor(tcell.ColorPurple)
// TODO colors wacky
tokenInput := tview.NewInputField()
tokenInput.SetLabel("invite code:")
tokenInput.SetFieldWidth(40)
tokenForm := tview.NewForm()
tokenForm.SetButtonBackgroundColor(tcell.ColorPurple)
tokenForm.SetButtonTextColor(tcell.ColorBlack)
tokenForm.SetButtonActivatedStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite).Background(tcell.ColorPurple))
tokenForm.SetLabelColor(tcell.ColorPurple)
tokenForm.SetFieldBackgroundColor(tcell.ColorPurple)
tokenForm.AddFormItem(tokenInput)
tokenForm.AddButton("submit", func() {
app.Stop()
// TODO
})
tokenPage := tview.NewFlex()
tokenPage.SetDirection(tview.FlexRow)
tokenPage.AddItem(artView, 17, -1, false)
tokenPage.AddItem(tokenForm, 5, -1, true)
tokenPage.AddItem(help, 1, -1, false)
pages := tview.NewPages()
pages.AddPage("start", tokenPage, true, true)
app.SetRoot(pages, true)
/*
TODO multi-page flow:
- page 1: accept invite token
- page 2: username, display name, email
- page 3: public key
- page 4: next steps
*/
return app.EnableMouse(true).Run()
}
func main() {
err := _main()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}