51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
"time"
|
|
|
|
"git.sr.ht/~rockorager/vaxis"
|
|
"git.tilde.town/nbsp/neofeels/ui"
|
|
)
|
|
|
|
type Posted struct {
|
|
title string
|
|
content string
|
|
help string
|
|
}
|
|
|
|
func NewPosted() *Posted {
|
|
var content string
|
|
info, err := os.Stat(path.Join(os.Getenv("HOME"), ".ttbp/entries", time.Now().Format("20060102")+".txt"))
|
|
if os.IsNotExist(err) || info.IsDir() || info.Size() == 0 {
|
|
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":
|
|
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
|
|
}
|