fix terminal freezing

trunk
aoife cassidy 2025-01-19 12:32:59 +02:00
parent c9aec29b0c
commit fd79bceb79
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
2 changed files with 22 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package app
import ( import (
"fmt" "fmt"
"os"
"os/exec" "os/exec"
"os/user" "os/user"
@ -10,7 +11,9 @@ import (
"git.tilde.town/nbsp/welcome/ui" "git.tilde.town/nbsp/welcome/ui"
) )
type Editor struct{} type Editor struct {
loaded bool
}
func (view *Editor) Draw(state *ui.State) { func (view *Editor) Draw(state *ui.State) {
win := state.Window() 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) { 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) view.Draw(state)
vt := term.New() vt := term.New()
vt.Draw(win.New(0, 16, 80, 80)) vt.TERM = os.Getenv("TERM")
vt.Attach(state.PostEvent()) vt.Attach(state.PostEvent())
vt.Focus() vt.Focus()
err := vt.Start(exec.Command("bash", "-l")) err := vt.Start(exec.Command("bash", "-l"))
@ -76,7 +84,7 @@ func (view *Editor) Event(state *ui.State, event vaxis.Event) (processed bool) {
return return
case vaxis.Redraw: case vaxis.Redraw:
view.Draw(state) view.Draw(state)
vt.Draw(win.New(0, 16, 80, 80)) vt.Draw(win)
state.Render() state.Render()
continue continue
} }

View File

@ -1,6 +1,7 @@
package app package app
import ( import (
"os"
"os/exec" "os/exec"
"git.sr.ht/~rockorager/vaxis" "git.sr.ht/~rockorager/vaxis"
@ -8,7 +9,9 @@ import (
"git.tilde.town/nbsp/welcome/ui" "git.tilde.town/nbsp/welcome/ui"
) )
type Shell struct{} type Shell struct {
loaded bool
}
func (view *Shell) Draw(state *ui.State) { func (view *Shell) Draw(state *ui.State) {
win := state.Window() win := state.Window()
@ -43,11 +46,16 @@ you're ready.`},
} }
func (view *Shell) Event(state *ui.State, event vaxis.Event) (processed bool) { 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) win := state.Window().New(0, 16, 80, 80)
view.Draw(state) view.Draw(state)
vt := term.New() vt := term.New()
vt.Draw(win) vt.TERM = os.Getenv("TERM")
vt.Attach(state.PostEvent()) vt.Attach(state.PostEvent())
vt.Focus() vt.Focus()
err := vt.Start(exec.Command("bash", "-l")) err := vt.Start(exec.Command("bash", "-l"))