From b46f2c92b84c1935c1adecd311d48e9c555db8e7 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Fri, 8 May 2026 12:08:48 +0200 Subject: [PATCH] use chatwait for streaming instead of statewait polling --- .gitignore | 1 + main.go | 33 +++++++++++---------------------- 2 files changed, 12 insertions(+), 22 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43204c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +ollie-acme diff --git a/main.go b/main.go index 5c41afd..66f4079 100644 --- a/main.go +++ b/main.go @@ -203,38 +203,27 @@ func (cw *chatWin) eventLoop() { } } -// tail polls the chat file and appends new content to the window. +// tail reads chatwait in a loop to stream new content to the window. func (cw *chatWin) tail() { - chatPath := filepath.Join(ollie, "s", cw.sid, "chat") - swPath := filepath.Join(ollie, "s", cw.sid, "statewait") + cwPath := filepath.Join(ollie, "s", cw.sid, "chatwait") for { - // statewait blocks until a state transition. - _, err := os.ReadFile(swPath) + data, err := os.ReadFile(cwPath) if err != nil { - // Session gone — stop tailing. if os.IsNotExist(err) { return } time.Sleep(500 * time.Millisecond) continue } - cw.flush(chatPath) - } -} - -func (cw *chatWin) flush(chatPath string) { - data, err := os.ReadFile(chatPath) - if err != nil { - return - } - cw.mu.Lock() - defer cw.mu.Unlock() - if len(data) > cw.offset { - cw.win.Addr("$") - cw.win.Write("data", data[cw.offset:]) - cw.offset = len(data) - cw.win.Ctl("clean") + if len(data) > 0 { + cw.mu.Lock() + cw.win.Addr("$") + cw.win.Write("data", data) + cw.offset += len(data) + cw.win.Ctl("clean") + cw.mu.Unlock() + } } }