welcome/app/settings.go

97 lines
2.4 KiB
Go
Raw Normal View History

2025-01-18 22:06:25 +00:00
package app
import (
"git.sr.ht/~rockorager/vaxis"
"git.sr.ht/~rockorager/vaxis/widgets/textinput"
"git.tilde.town/nbsp/welcome/ui"
)
type Settings struct {
index int
inputs [3]textinput.Model
}
func (view *Settings) 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 "Up":
if view.index > 0 {
view.index--
}
case "Down":
if view.index < 3 {
view.index++
}
case "Enter":
if view.index == 3 {
2025-01-18 22:54:05 +00:00
// TODO: save settings
ui.ViewChange <- &Shell{}
2025-01-18 22:06:25 +00:00
}
if view.index < 3 {
view.index++
}
default:
if view.index != 3 {
view.inputs[view.index].Update(event)
}
}
processed = true
}
enterStyle := vaxis.AttributeMask(vaxis.AttrNone)
if view.index == 3 {
enterStyle = vaxis.AttrReverse
}
win := state.Window()
win.Print(vaxis.Segment{Text: ` initial settings
let's get you set up with some useful settings. you can press or to move
between the inputs. feel free to leave any of them empty! you can always set
them later, or leave them unset.
1. what are your pronouns? this is useful information for folks to be able to
refer to you in the third person. common pronoun sets are he/him, she/her,
and they/them.
>
2. when's your birthday? this will show up in certain places, so people can wish
you a happy birthday :) format is MM/YY.
>
3. what's your timezone? this will change all times you view in town to your
local timezone, so you don't have to convert from utc in your head.
the format for timezones can be found here:
`},
vaxis.Segment{
Text: "https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List",
Style: vaxis.Style{
Foreground: vaxis.IndexColor(4),
// UnderlineColor: vaxis.IndexColor(3),
UnderlineStyle: vaxis.UnderlineSingle,
},
},
vaxis.Segment{Text: `
it should look something like America/New_York.
>
`},
vaxis.Segment{Text: " press ↲ to continue ", Style: vaxis.Style{Attribute: enterStyle}},
)
rows := [3]int{10, 15, 23}
for i, input := range view.inputs {
input.Draw(vaxis.Window{win.Vx, &win, 5, rows[i], 74, 1})
if i == view.index {
win.SetStyle(3, rows[i], vaxis.Style{Attribute: vaxis.AttrReverse})
}
}
state.HideCursor()
return
}