116 lines
2.9 KiB
Go
116 lines
2.9 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"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 {
|
|
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 != "" {
|
|
os.WriteFile(".pronouns", []byte(pronouns), 0644)
|
|
}
|
|
if birthday != "" {
|
|
os.WriteFile(".birthday", []byte(pronouns), 0644)
|
|
}
|
|
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()
|
|
}
|
|
|
|
ui.ViewChange <- &Shell{}
|
|
}
|
|
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/DD.
|
|
|
|
>
|
|
|
|
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),
|
|
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
|
|
}
|