posting feels

trunk
nbsp 2025-01-05 21:42:53 +02:00
parent c825888147
commit 9eac46a2aa
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
4 changed files with 96 additions and 12 deletions

View File

@ -16,7 +16,7 @@ make
- [x] credits
- [ ] feels browser
- [ ] configuration editor
- [ ] feels publishing
- [x] feels publishing
- [ ] graffiti
- [ ] feedback
- [ ] documentation with manpages

View File

@ -13,11 +13,7 @@ type Credits struct {
func NewCredits() *Credits {
return &Credits{
` ___ __
/ _/__ ___ / /__
/ _/ -_) -_) (_-<
/_/ \__/\__/_/___/
neofeels 0.1.0`,
title,
`ttbp written for tilde.town by ~endorphant in python
neofeels written by ~nbsp in go
@ -25,7 +21,7 @@ tips for development of ttbp are accepted at https://liberapay.com/modgethanc/
tips for development of neofeels are accepted at https://liberapay.com/nbsp/
kind words are also extremely appreciated :)`,
"q exit",
"q return",
}
}
@ -42,6 +38,6 @@ func (credits *Credits) Event(state *ui.State, event vaxis.Event) (processed boo
win := state.Window()
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: credits.title})
win.New(win.Width/2-40, win.Height/2-2, 80, 7).Print(vaxis.Segment{Text: credits.credits})
win.New(win.Width/2-3, win.Height/2+6, 6, 1).Print(vaxis.Segment{Text: credits.help})
win.New(win.Width/2-4, win.Height/2+6, 8, 1).Print(vaxis.Segment{Text: credits.help})
return
}

View File

@ -3,6 +3,8 @@ package app
import (
"os"
"os/exec"
"path"
"time"
"git.sr.ht/~rockorager/vaxis"
"git.sr.ht/~rockorager/vaxis/widgets/list"
@ -16,13 +18,15 @@ type MainMenu struct {
help string
}
func NewMainMenu() *MainMenu {
return &MainMenu{
` ___ __
const title = ` ___ __
/ _/__ ___ / /__
/ _/ -_) -_) (_-<
/_/ \__/\__/_/___/
neofeels 0.1.0`,
neofeels 0.1.0`
func NewMainMenu() *MainMenu {
return &MainMenu{
title,
list.New([]string{
" record some feels ",
" manage your feels ",
@ -54,6 +58,8 @@ func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool)
menu.list.Home()
case "Enter":
switch menu.list.Index() {
case 0:
newFeels(state)
case 8:
ui.ViewChange <- NewCredits()
case 9:
@ -106,3 +112,35 @@ func showManpage(state *ui.State) {
}
}
}
func newFeels(state *ui.State) {
state.HideCursor()
vt := term.New()
vt.TERM = os.Getenv("TERM")
vt.Attach(state.PostEvent())
vt.Focus()
err := vt.Start(exec.Command(os.Getenv("EDITOR"), path.Join(os.Getenv("HOME"), ".ttbp/entries", time.Now().Format("20060102")+".txt")))
if err != nil {
panic(err)
}
defer vt.Close()
for ev := range state.Events() {
switch ev.(type) {
case term.EventClosed:
state.HideCursor()
state.Window().Clear()
ui.ViewChange <- NewPosted()
return
case vaxis.Redraw:
vt.Draw(state.Window())
state.Render()
continue
}
// for some reason vaxis doubles all events for Press/Release so this just ignores releases
if key, ok := ev.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
vt.Update(ev)
}
}
}

50
app/posted.go 100644
View File

@ -0,0 +1,50 @@
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
}