welcome/app/settings.go

116 lines
2.9 KiB
Go
Raw Normal View History

2025-01-18 22:06:25 +00:00
package app
import (
2025-01-19 12:01:37 +00:00
"fmt"
"os"
"strings"
2025-01-18 22:06:25 +00:00
"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-19 12:01:37 +00:00
pronouns := strings.TrimSpace(view.inputs[0].String())
birthday := strings.TrimSpace(view.inputs[1].String())
timezone := strings.TrimSpace(view.inputs[2].String())
// XXX: this assumes nothing will break
if pronouns != "" {
2025-01-19 13:29:07 +00:00
os.WriteFile(".pronouns", []byte(pronouns+"\n"), 0644)
2025-01-19 12:01:37 +00:00
}
if birthday != "" {
2025-01-19 13:29:07 +00:00
os.WriteFile(".birthday", []byte(birthday+"\n"), 0644)
2025-01-19 12:01:37 +00:00
}
if timezone != "" {
f, _ := os.OpenFile(".bashrc", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
f.Write([]byte(fmt.Sprintf("export TZ='%s'\n", timezone)))
f.Close()
}
2025-01-18 22:54:05 +00:00
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
2025-01-18 23:47:22 +00:00
you a happy birthday :) format is MM/DD.
2025-01-18 22:06:25 +00:00
>
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{
2025-01-18 23:47:22 +00:00
Foreground: vaxis.IndexColor(4),
2025-01-18 22:06:25 +00:00
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
}