package app import ( "fmt" "os/exec" "os/user" "git.sr.ht/~rockorager/vaxis" "git.sr.ht/~rockorager/vaxis/widgets/term" "git.tilde.town/nbsp/welcome/ui" ) type Editor struct{} func (view *Editor) Draw(state *ui.State) { win := state.Window() user, _ := user.Current() win.Print( vaxis.Segment{Text: ` ──── editing your homepage ──── nice work! you'll get used to the shell in no time. one of the main things you're going to do in town is editing text files. the program we use to do this is aptly called an `}, vaxis.Segment{Text: "editor", Style: vaxis.Style{Foreground: vaxis.IndexColor(3)}}, vaxis.Segment{Text: `. take your homepage, for example: `}, vaxis.Segment{Text: fmt.Sprintf("https://tilde.town/~%s", user.Username), Style: vaxis.Style{ Foreground: vaxis.IndexColor(4), UnderlineStyle: vaxis.UnderlineSingle, }, }, vaxis.Segment{Text: ` looks pretty barren, doesn't it? let's edit it to add some more words. type `}, vaxis.Segment{Text: "nano public_html/index.html", Style: vaxis.Style{Foreground: vaxis.IndexColor(3)}}, vaxis.Segment{Text: ` to open nano, our text editor of choice. in it, make some changes, and press `}, vaxis.Segment{Text: "Ctrl+O", Style: vaxis.Style{Foreground: vaxis.IndexColor(3)}}, vaxis.Segment{Text: ` to save and look at the changes in your browser. press `}, vaxis.Segment{Text: "Ctrl+X", Style: vaxis.Style{Foreground: vaxis.IndexColor(3)}}, vaxis.Segment{Text: ` to save and exit nano. like before, when you're done, type `}, vaxis.Segment{Text: "exit", Style: vaxis.Style{Foreground: vaxis.IndexColor(3)}}, vaxis.Segment{Text: ` in your shell to continue.`}, ) } func (view *Editor) Event(state *ui.State, event vaxis.Event) (processed bool) { win := state.Window() view.Draw(state) vt := term.New() vt.Draw(win.New(0, 16, 80, 80)) vt.Attach(state.PostEvent()) vt.Focus() err := vt.Start(exec.Command("bash", "-i")) if err != nil { panic(err) } defer vt.Close() for ev := range state.Events() { switch ev.(type) { case term.EventClosed: state.HideCursor() vt.Detach() vt.Close() state.Window().Clear() ui.ViewChange <- &Help{} return case vaxis.Redraw: view.Draw(state) vt.Draw(win.New(0, 16, 80, 80)) 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) } } return }