package app import ( "os" "path" "strings" "time" "git.sr.ht/~rockorager/vaxis" "git.tilde.town/nbsp/neofeels/ttbp" "git.tilde.town/nbsp/neofeels/ui" ) type Posted struct { title string content string help string } func NewPosted() *Posted { var content string info, err := os.ReadFile(path.Join(ttbp.PathUserEntries, time.Now().Format("20060102")+".txt")) if os.IsNotExist(err) || strings.Trim(string(info), " \r\n\t") == "" { content = `your post is empty and was not published. see you next time!` } else { content = `your post has been successfully published. thanks for sharing your feels!` } return &Posted{ title, content, "q return", } } func (posted *Posted) Event(state *ui.State, event vaxis.Event) (processed bool) { if key, ok := event.(vaxis.Key); ok && key.EventType == vaxis.EventPress { switch key.String() { case "Ctrl+c", "Ctrl+d": close(ui.Quit) case "Enter", "q", "h", "l", "Left", "Right": ui.ViewChange <- NewMainMenu() } processed = true } win := state.Window() win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: posted.title}) win.New(win.Width/2-21, win.Height/2-2, 43, 2).Print(vaxis.Segment{Text: posted.content}) win.New(win.Width/2-4, win.Height/2+1, 8, 1).Print(vaxis.Segment{Text: posted.help}) return }