record user inputs
parent
39396eba4e
commit
4dbeb6984f
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -29,6 +30,8 @@ auth [success=done default=ignore] pam_succeed_if.so user ingroup join
|
||||||
in /etc/pam.d/sshd
|
in /etc/pam.d/sshd
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const maxInputLength int = 4000
|
||||||
|
|
||||||
type TownApplication struct {
|
type TownApplication struct {
|
||||||
Email string
|
Email string
|
||||||
|
|
||||||
|
@ -48,6 +51,7 @@ func cli(s *streams) error {
|
||||||
input := tview.NewTextArea()
|
input := tview.NewTextArea()
|
||||||
input.SetBorder(true).SetBorderColor(tcell.ColorPaleTurquoise)
|
input.SetBorder(true).SetBorderColor(tcell.ColorPaleTurquoise)
|
||||||
input.SetTitle("press ctrl+d to send")
|
input.SetTitle("press ctrl+d to send")
|
||||||
|
input.SetMaxLength(2000)
|
||||||
|
|
||||||
title := tview.NewTextView()
|
title := tview.NewTextView()
|
||||||
title.SetDynamicColors(true)
|
title.SetDynamicColors(true)
|
||||||
|
@ -75,7 +79,6 @@ func cli(s *streams) error {
|
||||||
try a [-:-:b]verb[-:-:-] using [-:-:b]/[-:-:-] like:
|
try a [-:-:b]verb[-:-:-] using [-:-:b]/[-:-:-] like:
|
||||||
|
|
||||||
[-:-:b]/nod[-:-:-]
|
[-:-:b]/nod[-:-:-]
|
||||||
|
|
||||||
`))
|
`))
|
||||||
|
|
||||||
innerFlex.SetDirection(tview.FlexColumn)
|
innerFlex.SetDirection(tview.FlexColumn)
|
||||||
|
@ -94,7 +97,7 @@ func cli(s *streams) error {
|
||||||
|
|
||||||
player := newCharacter("you", "TODO")
|
player := newCharacter("you", "TODO")
|
||||||
|
|
||||||
currentScreen := "start"
|
currentScene := "start"
|
||||||
|
|
||||||
sceneTransition := func(text string) {
|
sceneTransition := func(text string) {
|
||||||
fmt.Fprintln(msgScroll, heredoc.Doc(`
|
fmt.Fprintln(msgScroll, heredoc.Doc(`
|
||||||
|
@ -105,9 +108,15 @@ func cli(s *streams) error {
|
||||||
fmt.Fprintln(msgScroll, text)
|
fmt.Fprintln(msgScroll, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
scenes := map[string]func(){
|
type scene struct {
|
||||||
"start": func() {
|
Description string
|
||||||
fmt.Fprintln(msgScroll, heredoc.Doc(`
|
InBuff io.ReadWriter
|
||||||
|
InLength int
|
||||||
|
}
|
||||||
|
|
||||||
|
scenes := map[string]*scene{
|
||||||
|
"start": {
|
||||||
|
Description: heredoc.Doc(`
|
||||||
You open your eyes.
|
You open your eyes.
|
||||||
|
|
||||||
You're in some kind of workshop.
|
You're in some kind of workshop.
|
||||||
|
@ -122,10 +131,11 @@ func cli(s *streams) error {
|
||||||
first, please let me know what a good [-:-:b]email address[-:-:-] is for you?
|
first, please let me know what a good [-:-:b]email address[-:-:-] is for you?
|
||||||
just say it out loud. as many times as you need. to get it right.
|
just say it out loud. as many times as you need. to get it right.
|
||||||
when you're ready to move on, [-:-:b]/nod[-:-:-]
|
when you're ready to move on, [-:-:b]/nod[-:-:-]
|
||||||
`))
|
`),
|
||||||
|
InBuff: bytes.NewBuffer([]byte{}),
|
||||||
},
|
},
|
||||||
"nodded": func() {
|
"nodded": {
|
||||||
sceneTransition(heredoc.Doc(`
|
Description: heredoc.Doc(`
|
||||||
The workshop fades away. You hear the sound of a dial up modem
|
The workshop fades away. You hear the sound of a dial up modem
|
||||||
in the distance.
|
in the distance.
|
||||||
|
|
||||||
|
@ -142,10 +152,11 @@ func cli(s *streams) error {
|
||||||
|
|
||||||
just say your answer out loud. when you've said what you want, [-:-:b]/lean[-:-:-]
|
just say your answer out loud. when you've said what you want, [-:-:b]/lean[-:-:-]
|
||||||
against a tree.
|
against a tree.
|
||||||
`))
|
`),
|
||||||
|
InBuff: bytes.NewBuffer([]byte{}),
|
||||||
},
|
},
|
||||||
"leaned": func() {
|
"leaned": {
|
||||||
sceneTransition(heredoc.Doc(`
|
Description: heredoc.Doc(`
|
||||||
You sink backwards into the forest. You find yourself floating in darkness.
|
You sink backwards into the forest. You find yourself floating in darkness.
|
||||||
|
|
||||||
At the far reaches of your vision you can make out a faint neon grid. Around you
|
At the far reaches of your vision you can make out a faint neon grid. Around you
|
||||||
|
@ -158,10 +169,11 @@ func cli(s *streams) error {
|
||||||
|
|
||||||
as usual, just say your answer. when you're satisfied, please [-:-:b]/spin[-:-:-]
|
as usual, just say your answer. when you're satisfied, please [-:-:b]/spin[-:-:-]
|
||||||
around in this void.
|
around in this void.
|
||||||
`))
|
`),
|
||||||
|
InBuff: bytes.NewBuffer([]byte{}),
|
||||||
},
|
},
|
||||||
"spun": func() {
|
"spun": {
|
||||||
sceneTransition(heredoc.Doc(`
|
Description: heredoc.Doc(`
|
||||||
You realize your eyes have been shut. You open them and, in an instant,
|
You realize your eyes have been shut. You open them and, in an instant,
|
||||||
the neon grid and polygons are gone. You're in a convenience store. Outside
|
the neon grid and polygons are gone. You're in a convenience store. Outside
|
||||||
it's dark besides a single pool of light coming from a street lamp. it's illuminating
|
it's dark besides a single pool of light coming from a street lamp. it's illuminating
|
||||||
|
@ -179,10 +191,11 @@ func cli(s *streams) error {
|
||||||
|
|
||||||
when you're happy you can submit this whole experience by leaving the
|
when you're happy you can submit this whole experience by leaving the
|
||||||
store. just [-:-:b]/open[-:-:-] the door.
|
store. just [-:-:b]/open[-:-:-] the door.
|
||||||
`))
|
`),
|
||||||
|
InBuff: bytes.NewBuffer([]byte{}),
|
||||||
},
|
},
|
||||||
"done": func() {
|
"done": {
|
||||||
sceneTransition(heredoc.Doc(`
|
Description: heredoc.Doc(`
|
||||||
thank you for applying to tilde.town!
|
thank you for applying to tilde.town!
|
||||||
|
|
||||||
please be on the look out for an email from [-:-:b]root@tilde.town[-:-:-]
|
please be on the look out for an email from [-:-:b]root@tilde.town[-:-:-]
|
||||||
|
@ -190,7 +203,8 @@ func cli(s *streams) error {
|
||||||
you can [-:-:b]/quit[-:-:-] now
|
you can [-:-:b]/quit[-:-:-] now
|
||||||
|
|
||||||
ok bye have a good one~
|
ok bye have a good one~
|
||||||
`))
|
`),
|
||||||
|
InBuff: bytes.NewBuffer([]byte{}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,35 +221,44 @@ func cli(s *streams) error {
|
||||||
switch strings.TrimPrefix(trimmed, "/") {
|
switch strings.TrimPrefix(trimmed, "/") {
|
||||||
case "quit":
|
case "quit":
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
case "look":
|
||||||
|
fmt.Fprintln(msgScroll, "")
|
||||||
|
fmt.Fprintln(msgScroll, scenes[currentScene].Description)
|
||||||
// TODO refactor into a state machine
|
// TODO refactor into a state machine
|
||||||
case "nod":
|
case "nod":
|
||||||
if currentScreen != "start" {
|
if currentScene != "start" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentScreen = "nodded"
|
if scenes[currentScene].InLength > 0 {
|
||||||
scenes[currentScreen]()
|
currentScene = "nodded"
|
||||||
|
sceneTransition(scenes[currentScene].Description)
|
||||||
|
} else {
|
||||||
|
// say sorry, ask for input
|
||||||
|
}
|
||||||
case "lean":
|
case "lean":
|
||||||
if currentScreen != "nodded" {
|
if currentScene != "nodded" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentScreen = "leaned"
|
currentScene = "leaned"
|
||||||
scenes[currentScreen]()
|
sceneTransition(scenes[currentScene].Description)
|
||||||
case "spin":
|
case "spin":
|
||||||
if currentScreen != "leaned" {
|
if currentScene != "leaned" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentScreen = "spun"
|
currentScene = "spun"
|
||||||
scenes[currentScreen]()
|
sceneTransition(scenes[currentScene].Description)
|
||||||
case "open":
|
case "open":
|
||||||
if currentScreen != "spun" {
|
if currentScene != "spun" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentScreen = "done"
|
currentScene = "done"
|
||||||
scenes[currentScreen]()
|
sceneTransition(scenes[currentScene].Description)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Fprintln(msgScroll, player.Say(msg))
|
fmt.Fprintln(msgScroll, player.Say(msg))
|
||||||
|
fmt.Fprintln(scenes[currentScene].InBuff, msg)
|
||||||
|
scenes[currentScene].InLength += len(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
|
@ -250,7 +273,7 @@ func cli(s *streams) error {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.SetAfterDrawFunc(func(_ tcell.Screen) {
|
app.SetAfterDrawFunc(func(_ tcell.Screen) {
|
||||||
scenes[currentScreen]()
|
fmt.Fprintln(msgScroll, scenes[currentScene].Description)
|
||||||
app.SetAfterDrawFunc(nil)
|
app.SetAfterDrawFunc(nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue