Compare commits

..

No commits in common. "31202109314f777620cb85f0f83480119b2888fd" and "07f15d17011a6f25fb1a4be37055b3287c15fc5a" have entirely different histories.

3 changed files with 26 additions and 201 deletions

View File

@ -1,31 +1,29 @@
package app
import (
"fmt"
"strconv"
"git.sr.ht/~rockorager/vaxis"
"git.sr.ht/~rockorager/vaxis/widgets/list"
"git.tilde.town/nbsp/neofeels/ui"
)
type Management struct {
title string
list ui.List
list list.List
help string
}
func NewManagement() *Management {
return &Management{
title,
ui.NewList([]string{
"read over feels", // TODO
"modify feels publishing", // TODO
"backup your feels", // TODO
"import a feels backup", // TODO
"bury some feels", // TODO
"delete feels by day", // TODO
"purge all feels", // TODO
"wipe feels account", // TODO
list.New([]string{
" read over feels ", // TODO
" modify feels publishing ", // TODO
" backup your feels ", // TODO
" import a feels backup ", // TODO
" bury some feels ", // TODO
" delete feels by day ", // TODO
" purge all feels ", // TODO
" wipe feels account ", // TODO
}),
"↑↓/kj move ↵ enter q return",
}
@ -44,26 +42,14 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
management.list.End()
case "Home", "g":
management.list.Home()
case "0", "1", "2", "3", "4", "5", "6", "7":
i, _ := strconv.Atoi(key.String())
management.list.SetIndex(i)
case "q", "h", "Left":
ui.ViewChange <- NewMainMenu()
case "Enter", "l", "Right":
switch management.list.Index() {
case 6:
management.Confirmation(state, func() {}, "feels purged")
case 7:
management.Confirmation(state, func() {}, "feels account wiped")
}
}
processed = true
}
management.Draw(state)
return
}
func (management *Management) Draw(state *ui.State) {
win := state.Window()
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: management.title})
management.list.Draw(vaxis.Window{
@ -74,68 +60,6 @@ func (management *Management) Draw(state *ui.State) {
Width: 28,
Height: 10,
})
win.New(win.Width/2-15, win.Height/2+7, 30, 1).Print(vaxis.Segment{Text: management.help})
}
// TODO: abstract this to our own List type
// TODO: figure out a less janky way instead of nesting event channels
func (management *Management) Confirmation(state *ui.State, action func(), message string) {
management.Draw(state)
win := state.Window()
win.New(win.Width/2-14, win.Height/2-2+management.list.Index(), 28, 1).Print(vaxis.Segment{
Text: " are you sure? ",
Style: vaxis.Style{
Foreground: vaxis.IndexColor(1),
Attribute: vaxis.AttrReverse,
},
})
state.Render()
loop:
for ev := range state.Events() {
switch ev.(type) {
case vaxis.Resize, vaxis.Redraw:
management.Draw(state)
win.New(win.Width/2-14, win.Height/2-2+management.list.Index(), 28, 1).Print(vaxis.Segment{
Text: " are you sure? ",
Style: vaxis.Style{
Foreground: vaxis.IndexColor(1),
Attribute: vaxis.AttrReverse,
},
})
state.Render()
case vaxis.Key:
switch ev.(vaxis.Key).String() {
case "Enter", "l", "Right":
action()
management.Draw(state)
win.New(win.Width/2-14, win.Height/2-2+management.list.Index(), 28, 1).Print(vaxis.Segment{
Text: fmt.Sprintf(" %-26s", message),
Style: vaxis.Style{
Foreground: vaxis.IndexColor(1),
Attribute: vaxis.AttrReverse,
},
})
state.Render()
for ev := range state.Events() {
switch ev.(type) {
case vaxis.Resize, vaxis.Redraw:
management.Draw(state)
win.New(win.Width/2-14, win.Height/2-2+management.list.Index(), 28, 1).Print(vaxis.Segment{
Text: fmt.Sprintf(" %26s", message),
Style: vaxis.Style{
Foreground: vaxis.IndexColor(1),
Attribute: vaxis.AttrReverse,
},
})
state.Render()
case vaxis.Key:
if ev.(vaxis.Key).EventType == vaxis.EventPress {
break loop
}
}
}
}
break loop
}
}
win.New(win.Width/2-14, win.Height/2+7, 28, 1).Print(vaxis.Segment{Text: management.help})
return
}

View File

@ -4,17 +4,17 @@ import (
"os"
"os/exec"
"path"
"strconv"
"time"
"git.sr.ht/~rockorager/vaxis"
"git.sr.ht/~rockorager/vaxis/widgets/list"
"git.sr.ht/~rockorager/vaxis/widgets/term"
"git.tilde.town/nbsp/neofeels/ui"
)
type MainMenu struct {
title string
list ui.List
list list.List
help string
}
@ -27,17 +27,17 @@ const title = ` ___ __
func NewMainMenu() *MainMenu {
return &MainMenu{
title,
ui.NewList([]string{
"record some feels",
"manage your feels ",
"check out your neighbors", // TODO
"browse global feels", // TODO
"visit your subscriptions", // TODO
"scribble some graffiti", // TODO
"change your settings", // TODO
"send some feedback", // TODO
"see credits",
"read documentation",
list.New([]string{
" record some feels ",
" manage your feels ",
" check out your neighbors ", // TODO
" browse global feels ", // TODO
" visit your subscriptions ", // TODO
" scribble some graffiti ", // TODO
" change your settings ", // TODO
" send some feedback ", // TODO
" see credits ",
" read documentation ",
}),
"↑↓/kj move ↵ enter q exit",
}
@ -56,9 +56,6 @@ func (menu *MainMenu) Event(state *ui.State, event vaxis.Event) (processed bool)
menu.list.End()
case "Home", "g":
menu.list.Home()
case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9":
i, _ := strconv.Atoi(key.String())
menu.list.SetIndex(i)
case "Enter", "l", "Right":
switch menu.list.Index() {
case 0:

View File

@ -1,96 +0,0 @@
/**
* vaxis/widget/list, edited to support wraparounds and number seeking
* soon to support confirmations, once i get around to that
*/
package ui
import (
"fmt"
"strconv"
"git.sr.ht/~rockorager/vaxis"
)
type List struct {
index int
items []string
offset int
}
func NewList(items []string) List {
return List{
items: items,
}
}
func (m *List) Draw(win vaxis.Window) {
_, height := win.Size()
if m.index >= m.offset+height {
m.offset = m.index - height + 1
} else if m.index < m.offset {
m.offset = m.index
}
defaultStyle := vaxis.Style{}
selectedStyle := vaxis.Style{Attribute: vaxis.AttrReverse}
index := m.index - m.offset
for i, subject := range m.items[m.offset:] {
var style vaxis.Style
if i == index {
style = selectedStyle
} else {
style = defaultStyle
}
win.Println(i, vaxis.Segment{Text: fmt.Sprintf(" %-"+strconv.Itoa(win.Width-2)+"s", subject), Style: style})
}
}
func (m *List) Down() {
if m.index == len(m.items)-1 {
m.index = 0
} else {
m.index++
}
}
func (m *List) Up() {
if m.index == 0 {
m.index = len(m.items) - 1
} else {
m.index--
}
}
func (m *List) Home() {
m.index = 0
}
func (m *List) End() {
m.index = len(m.items) - 1
}
func (m *List) PageDown(win vaxis.Window) {
_, height := win.Size()
m.index = min(len(m.items)-1, m.index+height)
}
func (m *List) PageUp(win vaxis.Window) {
_, height := win.Size()
m.index = max(0, m.index-height)
}
func (m *List) SetItems(items []string) {
m.items = items
m.index = min(len(items)-1, m.index)
}
// Returns the index of the currently selected item.
func (m *List) Index() int {
return m.index
}
func (m *List) SetIndex(index int) {
m.index = index
}