From 4dbeb6984f5e9932ed08c3e7386634899cab8ca2 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Fri, 10 Feb 2023 19:47:09 +0000 Subject: [PATCH] record user inputs --- cmd/signup/main.go | 85 +++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 31 deletions(-) diff --git a/cmd/signup/main.go b/cmd/signup/main.go index 20f8c8b..40e7679 100644 --- a/cmd/signup/main.go +++ b/cmd/signup/main.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "fmt" "io" "os" @@ -29,6 +30,8 @@ auth [success=done default=ignore] pam_succeed_if.so user ingroup join in /etc/pam.d/sshd */ +const maxInputLength int = 4000 + type TownApplication struct { Email string @@ -48,6 +51,7 @@ func cli(s *streams) error { input := tview.NewTextArea() input.SetBorder(true).SetBorderColor(tcell.ColorPaleTurquoise) input.SetTitle("press ctrl+d to send") + input.SetMaxLength(2000) title := tview.NewTextView() title.SetDynamicColors(true) @@ -75,7 +79,6 @@ func cli(s *streams) error { try a [-:-:b]verb[-:-:-] using [-:-:b]/[-:-:-] like: [-:-:b]/nod[-:-:-] - `)) innerFlex.SetDirection(tview.FlexColumn) @@ -94,7 +97,7 @@ func cli(s *streams) error { player := newCharacter("you", "TODO") - currentScreen := "start" + currentScene := "start" sceneTransition := func(text string) { fmt.Fprintln(msgScroll, heredoc.Doc(` @@ -105,9 +108,15 @@ func cli(s *streams) error { fmt.Fprintln(msgScroll, text) } - scenes := map[string]func(){ - "start": func() { - fmt.Fprintln(msgScroll, heredoc.Doc(` + type scene struct { + Description string + InBuff io.ReadWriter + InLength int + } + + scenes := map[string]*scene{ + "start": { + Description: heredoc.Doc(` You open your eyes. 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? just say it out loud. as many times as you need. to get it right. when you're ready to move on, [-:-:b]/nod[-:-:-] - `)) + `), + InBuff: bytes.NewBuffer([]byte{}), }, - "nodded": func() { - sceneTransition(heredoc.Doc(` + "nodded": { + Description: heredoc.Doc(` The workshop fades away. You hear the sound of a dial up modem 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[-:-:-] against a tree. - `)) + `), + InBuff: bytes.NewBuffer([]byte{}), }, - "leaned": func() { - sceneTransition(heredoc.Doc(` + "leaned": { + Description: heredoc.Doc(` 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 @@ -158,10 +169,11 @@ func cli(s *streams) error { as usual, just say your answer. when you're satisfied, please [-:-:b]/spin[-:-:-] around in this void. - `)) + `), + InBuff: bytes.NewBuffer([]byte{}), }, - "spun": func() { - sceneTransition(heredoc.Doc(` + "spun": { + Description: heredoc.Doc(` 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 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 store. just [-:-:b]/open[-:-:-] the door. - `)) + `), + InBuff: bytes.NewBuffer([]byte{}), }, - "done": func() { - sceneTransition(heredoc.Doc(` + "done": { + Description: heredoc.Doc(` thank you for applying to 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 ok bye have a good one~ - `)) + `), + InBuff: bytes.NewBuffer([]byte{}), }, } @@ -207,35 +221,44 @@ func cli(s *streams) error { switch strings.TrimPrefix(trimmed, "/") { case "quit": os.Exit(0) + case "look": + fmt.Fprintln(msgScroll, "") + fmt.Fprintln(msgScroll, scenes[currentScene].Description) // TODO refactor into a state machine case "nod": - if currentScreen != "start" { + if currentScene != "start" { return } - currentScreen = "nodded" - scenes[currentScreen]() + if scenes[currentScene].InLength > 0 { + currentScene = "nodded" + sceneTransition(scenes[currentScene].Description) + } else { + // say sorry, ask for input + } case "lean": - if currentScreen != "nodded" { + if currentScene != "nodded" { return } - currentScreen = "leaned" - scenes[currentScreen]() + currentScene = "leaned" + sceneTransition(scenes[currentScene].Description) case "spin": - if currentScreen != "leaned" { + if currentScene != "leaned" { return } - currentScreen = "spun" - scenes[currentScreen]() + currentScene = "spun" + sceneTransition(scenes[currentScene].Description) case "open": - if currentScreen != "spun" { + if currentScene != "spun" { return } - currentScreen = "done" - scenes[currentScreen]() + currentScene = "done" + sceneTransition(scenes[currentScene].Description) } return } 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 { @@ -250,7 +273,7 @@ func cli(s *streams) error { }) app.SetAfterDrawFunc(func(_ tcell.Screen) { - scenes[currentScreen]() + fmt.Fprintln(msgScroll, scenes[currentScene].Description) app.SetAfterDrawFunc(nil) })