Compare commits

...

3 Commits

Author SHA1 Message Date
aoife cassidy
0adaf9e90c
apply settings 2025-01-19 14:01:44 +02:00
aoife cassidy
fd79bceb79
fix terminal freezing 2025-01-19 13:52:00 +02:00
aoife cassidy
c9aec29b0c
fix terminal doubling inputs 2025-01-19 13:51:42 +02:00
4 changed files with 45 additions and 16 deletions

View File

@ -2,6 +2,7 @@ package app
import (
"fmt"
"os"
"os/exec"
"os/user"
@ -10,7 +11,9 @@ import (
"git.tilde.town/nbsp/welcome/ui"
)
type Editor struct{}
type Editor struct {
loaded bool
}
func (view *Editor) Draw(state *ui.State) {
win := state.Window()
@ -52,11 +55,16 @@ like before, when you're done, type `},
}
func (view *Editor) Event(state *ui.State, event vaxis.Event) (processed bool) {
win := state.Window()
if view.loaded {
return
}
view.loaded = true
win := state.Window().New(0, 16, 80, 80)
view.Draw(state)
vt := term.New()
vt.Draw(win.New(0, 16, 80, 80))
vt.TERM = os.Getenv("TERM")
vt.Attach(state.PostEvent())
vt.Focus()
err := vt.Start(exec.Command("bash", "-l"))
@ -76,15 +84,12 @@ func (view *Editor) Event(state *ui.State, event vaxis.Event) (processed bool) {
return
case vaxis.Redraw:
view.Draw(state)
vt.Draw(win.New(0, 16, 80, 80))
vt.Draw(win)
state.Render()
continue
}
// for some reason vaxis doubles all events for Press/Release so this just ignores releases
if key, ok := ev.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
vt.Update(ev)
}
vt.Update(ev)
}
return

View File

@ -1,6 +1,10 @@
package app
import (
"fmt"
"os"
"strings"
"git.sr.ht/~rockorager/vaxis"
"git.sr.ht/~rockorager/vaxis/widgets/textinput"
"git.tilde.town/nbsp/welcome/ui"
@ -26,7 +30,23 @@ func (view *Settings) Event(state *ui.State, event vaxis.Event) (processed bool)
}
case "Enter":
if view.index == 3 {
// TODO: save settings
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 File

@ -1,6 +1,7 @@
package app
import (
"os"
"os/exec"
"git.sr.ht/~rockorager/vaxis"
@ -8,7 +9,9 @@ import (
"git.tilde.town/nbsp/welcome/ui"
)
type Shell struct{}
type Shell struct {
loaded bool
}
func (view *Shell) Draw(state *ui.State) {
win := state.Window()
@ -43,11 +46,16 @@ you're ready.`},
}
func (view *Shell) Event(state *ui.State, event vaxis.Event) (processed bool) {
if view.loaded {
return
}
view.loaded = true
win := state.Window().New(0, 16, 80, 80)
view.Draw(state)
vt := term.New()
vt.Draw(win)
vt.TERM = os.Getenv("TERM")
vt.Attach(state.PostEvent())
vt.Focus()
err := vt.Start(exec.Command("bash", "-l"))
@ -72,10 +80,7 @@ func (view *Shell) Event(state *ui.State, event vaxis.Event) (processed bool) {
continue
}
// for some reason vaxis doubles all events for Press/Release so this just ignores releases
if key, ok := ev.(vaxis.Key); ok && key.EventType == vaxis.EventPress {
vt.Update(ev)
}
vt.Update(ev)
}
return

View File

@ -25,7 +25,6 @@ type State struct {
func New(view View) (state State, err error) {
vx, err := vaxis.New(vaxis.Options{
DisableMouse: true,
CSIuBitMask: vaxis.CSIuDisambiguate | vaxis.CSIuReportEvents | vaxis.CSIuAlternateKeys | vaxis.CSIuAllKeys | vaxis.CSIuAssociatedText,
})
if err != nil {
return