neofeels/main.go

76 lines
1.8 KiB
Go

package main
import (
"bufio"
_ "embed"
"fmt"
"os"
"os/user"
"path"
"strings"
"time"
"git.tilde.town/nbsp/neofeels/app"
"git.tilde.town/nbsp/neofeels/config"
"git.tilde.town/nbsp/neofeels/ttbp"
"git.tilde.town/nbsp/neofeels/ui"
)
//go:embed assets/header.html
var header string
//go:embed assets/footer.html
var footer []byte
//go:embed assets/style.css
var style []byte
func initializePrompt() {
fmt.Println(`i don't recognize you, stranger. let's make friends.
the feels engine is an internal blogging platform on tilde.town. it assists you
in recording your feels, giving you the option to publish to html or gopher, and
read the feels of other users on tilde.town.
press ↵ to set up an account, or Ctrl+c to quit. you can always come back later.`)
input := bufio.NewScanner(os.Stdin)
input.Scan()
println(ttbp.PathUserConfig, ttbp.PathUserFeels)
user, _ := user.Current()
header := strings.ReplaceAll(header, "%USER%", user.Username)
header = strings.ReplaceAll(header, "%DATETIME%", time.Now().Format(time.DateTime))
os.MkdirAll(ttbp.PathUserConfig, 0700)
os.MkdirAll(ttbp.PathUserEntries, 0700)
os.WriteFile(path.Join(ttbp.PathUserConfig, "header.txt"), []byte(header), 0644)
os.WriteFile(path.Join(ttbp.PathUserConfig, "footer.txt"), footer, 0644)
os.WriteFile(path.Join(ttbp.PathUserConfig, "style.css"), style, 0644)
config.Default.Write()
// TODO: edit users.txt
}
func main() {
if _, err := os.Stat(ttbp.PathUserRc); err != nil {
initializePrompt()
}
state, err := ui.New(app.NewMainMenu())
if err != nil {
panic(err)
}
defer state.Close()
loop:
for {
select {
case event := <-ui.Events:
state.HandleEvent(event)
case newState := <-ui.ViewChange:
state.HandleViewChange(newState)
case <-ui.Quit:
break loop
}
}
}