initial commit
commit
13c0ee4543
|
@ -0,0 +1,47 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.sr.ht/~rockorager/vaxis"
|
||||||
|
"git.tilde.town/nbsp/neofeels/ui"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Credits struct {
|
||||||
|
title string
|
||||||
|
credits string
|
||||||
|
help string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCredits() *Credits {
|
||||||
|
return &Credits{
|
||||||
|
` ___ __
|
||||||
|
/ _/__ ___ / /__
|
||||||
|
/ _/ -_) -_) (_-<
|
||||||
|
/_/ \__/\__/_/___/
|
||||||
|
neofeels 0.1.0`,
|
||||||
|
`ttbp written for tilde.town by ~endorphant in python
|
||||||
|
neofeels written by ~nbsp in go
|
||||||
|
|
||||||
|
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",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (credits *Credits) 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: 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})
|
||||||
|
return
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.sr.ht/~rockorager/vaxis"
|
||||||
|
"git.sr.ht/~rockorager/vaxis/widgets/list"
|
||||||
|
"git.tilde.town/nbsp/neofeels/ui"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MainMenu struct {
|
||||||
|
title string
|
||||||
|
list list.List
|
||||||
|
help string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMainMenu() *MainMenu {
|
||||||
|
return &MainMenu{
|
||||||
|
` ___ __
|
||||||
|
/ _/__ ___ / /__
|
||||||
|
/ _/ -_) -_) (_-<
|
||||||
|
/_/ \__/\__/_/___/
|
||||||
|
neofeels 0.1.0`,
|
||||||
|
list.New([]string{
|
||||||
|
" record some feels ",
|
||||||
|
" manage your feels ",
|
||||||
|
" check out your neighbors ",
|
||||||
|
" browse global feels ",
|
||||||
|
" visit your subscriptions ",
|
||||||
|
" scribble some graffiti ",
|
||||||
|
" change your settings ",
|
||||||
|
" send some feedback ",
|
||||||
|
" see credits ",
|
||||||
|
" read documentation ",
|
||||||
|
}),
|
||||||
|
"↑↓/kj move ↵ enter q exit",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (menu *MainMenu) 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", "q":
|
||||||
|
close(ui.Quit)
|
||||||
|
case "Down", "j":
|
||||||
|
menu.list.Down()
|
||||||
|
case "Up", "k":
|
||||||
|
menu.list.Up()
|
||||||
|
case "End":
|
||||||
|
menu.list.End()
|
||||||
|
case "Home":
|
||||||
|
menu.list.Home()
|
||||||
|
case "Enter":
|
||||||
|
ui.ViewChange <- NewCredits()
|
||||||
|
}
|
||||||
|
processed = true
|
||||||
|
}
|
||||||
|
win := state.Window()
|
||||||
|
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: menu.title})
|
||||||
|
menu.list.Draw(vaxis.Window{
|
||||||
|
Vx: win.Vx,
|
||||||
|
Parent: nil,
|
||||||
|
Column: win.Width/2 - 14,
|
||||||
|
Row: win.Height/2 - 2,
|
||||||
|
Width: 28,
|
||||||
|
Height: 10,
|
||||||
|
})
|
||||||
|
win.New(win.Width/2-14, win.Height/2+9, 28, 1).Print(vaxis.Segment{Text: menu.help})
|
||||||
|
return
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
module git.tilde.town/nbsp/neofeels
|
||||||
|
|
||||||
|
go 1.23.4
|
||||||
|
|
||||||
|
require (
|
||||||
|
git.sr.ht/~rockorager/vaxis v0.11.0 // indirect
|
||||||
|
github.com/containerd/console v1.0.3 // indirect
|
||||||
|
github.com/mattn/go-runewidth v0.0.14 // indirect
|
||||||
|
github.com/mattn/go-sixel v0.0.5 // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.4 // indirect
|
||||||
|
github.com/soniakeys/quant v1.0.0 // indirect
|
||||||
|
golang.org/x/image v0.9.0 // indirect
|
||||||
|
golang.org/x/sys v0.10.0 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,49 @@
|
||||||
|
git.sr.ht/~rockorager/vaxis v0.11.0 h1:FDEaYCVlC1JVooqrVfMh4Y2GtZBpbkrf/LBAaiLnUbw=
|
||||||
|
git.sr.ht/~rockorager/vaxis v0.11.0/go.mod h1:h94aKek3frIV1hJbdXjqnBqaLkbWXvV+UxAsQHg9bns=
|
||||||
|
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
|
||||||
|
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
|
||||||
|
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
|
||||||
|
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/mattn/go-sixel v0.0.5 h1:55w2FR5ncuhKhXrM5ly1eiqMQfZsnAHIpYNGZX03Cv8=
|
||||||
|
github.com/mattn/go-sixel v0.0.5/go.mod h1:h2Sss+DiUEHy0pUqcIB6PFXo5Cy8sTQEFr3a9/5ZLNw=
|
||||||
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
|
||||||
|
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/soniakeys/quant v1.0.0 h1:N1um9ktjbkZVcywBVAAYpZYSHxEfJGzshHCxx/DaI0Y=
|
||||||
|
github.com/soniakeys/quant v1.0.0/go.mod h1:HI1k023QuVbD4H8i9YdfZP2munIHU4QpjsImz6Y6zds=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
|
||||||
|
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||||
|
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
@ -0,0 +1,26 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.tilde.town/nbsp/neofeels/app"
|
||||||
|
"git.tilde.town/nbsp/neofeels/ui"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.sr.ht/~rockorager/vaxis"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Context struct {
|
||||||
|
Window vaxis.Window
|
||||||
|
x, y int
|
||||||
|
}
|
||||||
|
|
||||||
|
type View interface {
|
||||||
|
Event(state *State, event vaxis.Event) bool
|
||||||
|
// MouseEvent(localX int, localY int, event vaxis.Event)
|
||||||
|
}
|
||||||
|
|
||||||
|
var Events = make(chan vaxis.Event)
|
||||||
|
var Quit = make(chan struct{})
|
||||||
|
var ViewChange = make(chan View, 1)
|
||||||
|
|
||||||
|
type State struct {
|
||||||
|
content View
|
||||||
|
vx *vaxis.Vaxis
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(view View) (state State, err error) {
|
||||||
|
vx, err := vaxis.New(vaxis.Options{
|
||||||
|
DisableMouse: false,
|
||||||
|
CSIuBitMask: vaxis.CSIuDisambiguate | vaxis.CSIuReportEvents | vaxis.CSIuAlternateKeys | vaxis.CSIuAllKeys | vaxis.CSIuAssociatedText,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
state = State{
|
||||||
|
content: view,
|
||||||
|
vx: vx,
|
||||||
|
}
|
||||||
|
state.vx.SetTitle("neofeels")
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for event := range state.vx.Events() {
|
||||||
|
state.vx.Window().Clear()
|
||||||
|
Events <- event
|
||||||
|
}
|
||||||
|
close(Events)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (state *State) HandleEvent(event vaxis.Event) {
|
||||||
|
state.content.Event(state, event)
|
||||||
|
state.vx.Render()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (state *State) HandleViewChange(view View) {
|
||||||
|
state.vx.Window().Clear()
|
||||||
|
state.content = view
|
||||||
|
state.content.Event(state, vaxis.Redraw{})
|
||||||
|
state.vx.Render()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (state *State) Close() {
|
||||||
|
state.vx.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (state *State) Redraw() {
|
||||||
|
state.vx.Render()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (state *State) Window() vaxis.Window {
|
||||||
|
return state.vx.Window()
|
||||||
|
}
|
Loading…
Reference in New Issue