neofeels/app/posted.go

53 lines
1.3 KiB
Go
Raw Permalink Normal View History

2025-01-05 19:42:53 +00:00
package app
import (
"os"
"path"
2025-01-08 00:08:50 +00:00
"strings"
2025-01-05 19:42:53 +00:00
"time"
"git.sr.ht/~rockorager/vaxis"
2025-01-08 00:08:50 +00:00
"git.tilde.town/nbsp/neofeels/ttbp"
2025-01-05 19:42:53 +00:00
"git.tilde.town/nbsp/neofeels/ui"
)
type Posted struct {
title string
content string
help string
}
func NewPosted() *Posted {
var content string
2025-01-08 00:08:50 +00:00
info, err := os.ReadFile(path.Join(ttbp.PathUserEntries, time.Now().Format("20060102")+".txt"))
if os.IsNotExist(err) || strings.Trim(string(info), " \r\n\t") == "" {
2025-01-05 19:42:53 +00:00
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)
2025-01-05 20:58:43 +00:00
case "Enter", "q", "h", "l", "Left", "Right":
2025-01-09 02:54:03 +00:00
ui.ViewChange <- NewMainMenu(0)
2025-01-05 19:42:53 +00:00
}
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
}