From 3f48724fad0d6f99972cae5ca72f4588105909d3 Mon Sep 17 00:00:00 2001 From: HAYAMA_Kaoru Date: Fri, 29 Nov 2024 17:59:41 +0900 Subject: [PATCH] Fix: the read pointer was not advanced when target was found --- watcher.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/watcher.go b/watcher.go index 0e95bc7..702af95 100644 --- a/watcher.go +++ b/watcher.go @@ -35,21 +35,20 @@ func NewWatcher(pty io.ReadWriter) *Watcher { } func (W *Watcher) updateLastLine() { - newLinePos := strings.LastIndexByte(W.lastline, '\n') - if newLinePos >= 0 { - W.lastline = W.lastline[newLinePos+1:] - } } func (W *Watcher) checkWords(token string, words []string) int { W.lastline += token for i, word := range words { - if strings.Contains(W.lastline, word) { - W.updateLastLine() + if pos := strings.Index(W.lastline, word); pos >= 0 { + W.lastline = W.lastline[pos+len(word):] return i } } - W.updateLastLine() + newLinePos := strings.LastIndexByte(W.lastline, '\n') + if newLinePos >= 0 { + W.lastline = W.lastline[newLinePos+1:] + } return -1 }