From 97cc11332956d147017631c272ab76567218a7c4 Mon Sep 17 00:00:00 2001 From: Sundog Date: Fri, 16 Apr 2021 14:48:56 -0700 Subject: [PATCH] one more i/o fix in door handler - prompt doesn't always have a newline --- main.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 9c32b6c..b738593 100644 --- a/main.go +++ b/main.go @@ -266,12 +266,6 @@ func doorHandler(ctx context.Context, c net.Conn, w *gaio.Watcher, menuwg *sync. defer menuwg.Done() var wg sync.WaitGroup - const bannerText = "\r\nCOLOSSAL CAVE\r\n\r\n" - - err := w.Write(ctx, c, []byte(bannerText)) - if err != nil { - log.Printf("error writing to connection: %v\n", err) - } var inChan, _ chan gaio.OpResult var ok bool @@ -354,10 +348,13 @@ func doorHandler(ctx context.Context, c net.Conn, w *gaio.Watcher, menuwg *sync. if l > 0 { w.Write(ctx, c, outBuf[:l]) log.Printf("wrote %d bytes to watcher: %v\n", l, string(outBuf[:l])) - waitingForInput = true + if strings.Contains(string(outBuf[:l]), ">") { + // a prompt appeared! + waitingForInput = true + } } else { // zero output? let's get some input? - waitingForInput = true + // waitingForInput = true w.Read(ctx, c, nil) } }