add editor guide

trunk
aoife cassidy 2025-01-19 01:47:22 +02:00
parent 4cd2b8bd81
commit d480b77590
No known key found for this signature in database
GPG Key ID: 7184AC1C9835CE48
4 changed files with 94 additions and 8 deletions

4
TODO
View File

@ -1,4 +0,0 @@
- editing your homepage
- checking your mail
- joining irc
- goodbye & link to town explore and wiki

91
app/editor.go 100644
View File

@ -0,0 +1,91 @@
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
}

View File

@ -59,7 +59,7 @@ them later, or leave them unset.
>
2. when's your birthday? this will show up in certain places, so people can wish
you a happy birthday :) format is MM/YY.
you a happy birthday :) format is MM/DD.
>
@ -71,7 +71,6 @@ them later, or leave them unset.
Text: "https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List",
Style: vaxis.Style{
Foreground: vaxis.IndexColor(4),
// UnderlineColor: vaxis.IndexColor(3),
UnderlineStyle: vaxis.UnderlineSingle,
},
},

View File

@ -63,7 +63,7 @@ func (view *Shell) Event(state *ui.State, event vaxis.Event) (processed bool) {
vt.Detach()
vt.Close()
state.Window().Clear()
ui.ViewChange <- &Help{}
ui.ViewChange <- &Editor{}
return
case vaxis.Redraw:
view.Draw(state)