forked from tildetown/town
245 lines
5.8 KiB
Go
245 lines
5.8 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/MakeNowJust/heredoc/v2"
|
|
"github.com/gdamore/tcell/v2"
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
/*
|
|
Assumes:
|
|
|
|
Match User join
|
|
ForceCommand /town/src/town/cmd/signup/signup
|
|
PubkeyAuthentication no
|
|
KbdInteractiveAuthentication no
|
|
PasswordAuthentication yes
|
|
PermitEmptyPasswords yes
|
|
DisableForwarding yes
|
|
|
|
in sshd_config, and:
|
|
|
|
auth [success=done default=ignore] pam_succeed_if.so user ingroup join
|
|
|
|
in /etc/pam.d/sshd
|
|
*/
|
|
|
|
type TownApplication struct {
|
|
Email string
|
|
|
|
// TODO
|
|
}
|
|
|
|
type streams struct {
|
|
In io.Reader
|
|
Out io.Writer
|
|
Err io.Writer
|
|
}
|
|
|
|
func cli(s *streams) error {
|
|
pages := tview.NewPages()
|
|
mainFlex := tview.NewFlex()
|
|
innerFlex := tview.NewFlex()
|
|
input := tview.NewTextArea()
|
|
|
|
title := tview.NewTextView()
|
|
title.SetDynamicColors(true)
|
|
title.SetTextAlign(tview.AlignCenter)
|
|
title.SetText("[purple]the tilde town sign up portal[-]")
|
|
|
|
msgScroll := tview.NewTextView()
|
|
msgScroll.SetDynamicColors(true)
|
|
|
|
sidebar := tview.NewTextView()
|
|
sidebar.SetBorder(true)
|
|
sidebar.SetDynamicColors(true)
|
|
sidebar.SetText(heredoc.Doc(`
|
|
[-:-:b]hey here are some hints[-:-:-]
|
|
|
|
quit by pressing [-:-:b]ctrl-c[-:-:-]
|
|
(your responses won't be saved)
|
|
|
|
type stuff. send it with [-:-:b]ctrl+d[-:-:-]
|
|
|
|
try a [-:-:b]verb[-:-:-] using [-:-:b]/[-:-:-] like:
|
|
|
|
[-:-:b]/go north[-:-:-]
|
|
|
|
`))
|
|
|
|
innerFlex.SetDirection(tview.FlexColumn)
|
|
innerFlex.AddItem(msgScroll, 0, 2, false)
|
|
innerFlex.AddItem(sidebar, 0, 1, false)
|
|
|
|
mainFlex.SetDirection(tview.FlexRow)
|
|
mainFlex.AddItem(title, 1, -1, false)
|
|
mainFlex.AddItem(innerFlex, 0, 1, false)
|
|
mainFlex.AddItem(input, 5, -1, true)
|
|
|
|
pages.AddPage("main", mainFlex, true, true)
|
|
|
|
app := tview.NewApplication()
|
|
app.SetRoot(pages, true)
|
|
|
|
player := newCharacter("you", "TODO")
|
|
|
|
handleInput := func(msg string) {
|
|
if strings.HasPrefix(msg, "/") {
|
|
// TODO handle command
|
|
}
|
|
fmt.Fprintln(msgScroll, player.Say(msg))
|
|
}
|
|
|
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
|
switch event.Key() {
|
|
case tcell.KeyCtrlD:
|
|
handleInput(input.GetText())
|
|
input.SetText("", false)
|
|
return nil
|
|
}
|
|
|
|
return event
|
|
})
|
|
|
|
return app.Run()
|
|
}
|
|
|
|
type character struct {
|
|
Name string
|
|
Description string
|
|
}
|
|
|
|
func newCharacter(name, description string) *character {
|
|
return &character{
|
|
Name: name,
|
|
Description: description,
|
|
}
|
|
}
|
|
|
|
func (c *character) Say(msg string) string {
|
|
verb := "says"
|
|
if c.Name == "you" {
|
|
verb = "say"
|
|
}
|
|
return fmt.Sprintf("[-:-:b]%s[-:-:-] %s: '%s'",
|
|
c.Name,
|
|
verb,
|
|
strings.TrimSpace(msg))
|
|
}
|
|
|
|
func main() {
|
|
s := &streams{
|
|
In: os.Stdin,
|
|
Out: os.Stdout,
|
|
Err: os.Stderr,
|
|
}
|
|
err := cli(s)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
/*
|
|
type answers struct {
|
|
username string
|
|
email string
|
|
applied time.Time
|
|
|
|
howDay string
|
|
howHeard string
|
|
reasons string
|
|
plans string
|
|
socials string
|
|
sshKey string
|
|
}
|
|
|
|
func _main(args []string, s *streams) error {
|
|
p.Say("you are standing in a field.")
|
|
p.Pause()
|
|
p.Say("there are flowers around you. you are standing in a slight depression and before you is grass touching a purple sky.")
|
|
p.Pause()
|
|
p.Say("you are not sure how long it's been when a cube about a meter high appears at the top of the hill before you.")
|
|
p.Say("the cube's surface is murky but iridescently reflective like an oil slick.")
|
|
p.Pause()
|
|
p.CharSay("cube", "hello. how is your day going?")
|
|
p.Say("(you can type a response and hit enter to talk to the cube)")
|
|
p.Pause()
|
|
|
|
howDay := InputAnswer{}
|
|
err := p.Ask("you say:", &howDay)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
a.howDay = howDay.Value
|
|
|
|
p.Say("the cube inclines towards you gently as if nodding.")
|
|
p.CharSay("cube", "i see.")
|
|
p.Pause()
|
|
|
|
p.CharSay("cube", "i am guessing that if you are here, you want to be there.")
|
|
p.Pause()
|
|
|
|
p.Say("you blink and are somewhere else.")
|
|
p.Pause()
|
|
|
|
p.Say("the field of flowers is behind you and now you are up on the hill. the cube is next to you.")
|
|
p.Pause()
|
|
p.Say("you can see clear across a wide open plain. structures large and small dot the landscape. you catch a whiff of a savory smell and can just barely hear voices on the wind.")
|
|
p.Pause()
|
|
|
|
p.CharSay("cube", "the tilde town lies before us. if you want to continue, i'll ask you some questions about acquiring a home down in the town. you'll be free to edit your responses before i carry them off.")
|
|
p.Pause()
|
|
|
|
p.CharSay("cube", "first, i'm curious how you found out about the town?")
|
|
p.Pause()
|
|
|
|
answer := InputAnswer{}
|
|
|
|
if err := p.Ask("you say:", &answer); err != nil {
|
|
return err
|
|
}
|
|
a.howHeard = answer.Value
|
|
|
|
p.CharSay("cube", "interesting, thanks.")
|
|
p.CharSay("cube", "what sort of stuff do you want to get up to on the town?")
|
|
|
|
if err := p.Ask("you say:", &answer); err != nil {
|
|
return err
|
|
}
|
|
a.plans = answer.Value
|
|
|
|
p.CharSay("cube", "thanks.")
|
|
p.CharSay("cube", "what do you like about the town?")
|
|
|
|
if err := p.Ask("you say:", &answer); err != nil {
|
|
return err
|
|
}
|
|
a.reasons = answer.Value
|
|
|
|
p.CharSay("cube", "i appreciate it.")
|
|
p.CharSay("cube", "can you paste some links to other places you are active online? maybe a homepage or social media profile? if you aren't comfortable sharing or there are none, just say so.")
|
|
|
|
if err := p.Ask("you say:", &answer); err != nil {
|
|
return err
|
|
}
|
|
a.socials = answer.Value
|
|
|
|
p.CharSay("cube", "ok, last thing. in order to break ground in the town, you'll need an SSH key. If you don't know what that is, you can check out this link: https://tilde.town/ssh.html .")
|
|
p.Pause()
|
|
|
|
if err := p.AskLong("paste SSH public key; press control+d to submit:", &answer); err != nil {
|
|
return err
|
|
}
|
|
a.sshKey = answer.Value
|
|
|
|
p.CharSay("cube", "i know that was a lot so i appreciate it. i've got everything written down here. before i carry it off, do you want to review and edit what you wrote?")
|
|
|
|
}
|
|
*/
|