implement scary confirmation ui
parent
07f15d1701
commit
10d962e5ef
|
@ -1,6 +1,8 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.sr.ht/~rockorager/vaxis"
|
"git.sr.ht/~rockorager/vaxis"
|
||||||
"git.sr.ht/~rockorager/vaxis/widgets/list"
|
"git.sr.ht/~rockorager/vaxis/widgets/list"
|
||||||
"git.tilde.town/nbsp/neofeels/ui"
|
"git.tilde.town/nbsp/neofeels/ui"
|
||||||
|
@ -46,10 +48,19 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
|
||||||
ui.ViewChange <- NewMainMenu()
|
ui.ViewChange <- NewMainMenu()
|
||||||
case "Enter", "l", "Right":
|
case "Enter", "l", "Right":
|
||||||
switch management.list.Index() {
|
switch management.list.Index() {
|
||||||
|
case 6:
|
||||||
|
management.Confirmation(state, func() {}, "feels purged")
|
||||||
|
case 7:
|
||||||
|
management.Confirmation(state, func() {}, "feels account wiped")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processed = true
|
processed = true
|
||||||
}
|
}
|
||||||
|
management.Draw(state)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (management *Management) Draw(state *ui.State) {
|
||||||
win := state.Window()
|
win := state.Window()
|
||||||
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: management.title})
|
win.New(win.Width/2-10, win.Height/2-8, 20, 5).Print(vaxis.Segment{Text: management.title})
|
||||||
management.list.Draw(vaxis.Window{
|
management.list.Draw(vaxis.Window{
|
||||||
|
@ -60,6 +71,68 @@ func (management *Management) Event(state *ui.State, event vaxis.Event) (process
|
||||||
Width: 28,
|
Width: 28,
|
||||||
Height: 10,
|
Height: 10,
|
||||||
})
|
})
|
||||||
win.New(win.Width/2-14, win.Height/2+7, 28, 1).Print(vaxis.Segment{Text: management.help})
|
win.New(win.Width/2-15, win.Height/2+7, 30, 1).Print(vaxis.Segment{Text: management.help})
|
||||||
return
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue