neofeels/main.go

76 lines
1.8 KiB
Go
Raw Normal View History

2025-01-05 16:40:26 +00:00
package main
import (
2025-01-08 00:45:01 +00:00
"bufio"
_ "embed"
"fmt"
"os"
"os/user"
"path"
"strings"
"time"
2025-01-05 16:40:26 +00:00
"git.tilde.town/nbsp/neofeels/app"
2025-01-08 00:45:01 +00:00
"git.tilde.town/nbsp/neofeels/config"
"git.tilde.town/nbsp/neofeels/ttbp"
2025-01-05 16:40:26 +00:00
"git.tilde.town/nbsp/neofeels/ui"
)
2025-01-08 00:45:01 +00:00
//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()
2025-01-08 01:14:15 +00:00
// TODO: edit users.txt
2025-01-08 00:45:01 +00:00
}
2025-01-05 16:40:26 +00:00
func main() {
2025-01-08 00:45:01 +00:00
if _, err := os.Stat(ttbp.PathUserRc); err != nil {
initializePrompt()
}
2025-01-05 16:40:26 +00:00
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
}
}
}