From 98f350ad899ae591d2c9ab41bd439a409952767b Mon Sep 17 00:00:00 2001 From: HAYAMA_Kaoru Date: Fri, 29 Nov 2024 13:31:27 +0900 Subject: [PATCH] =?UTF-8?q?`NewWatcher(pty.Pty)`=20=E2=86=92=20`NewWatcher?= =?UTF-8?q?(io.ReadWriter)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- watcher.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/watcher.go b/watcher.go index 9a0a4ec..0e95bc7 100644 --- a/watcher.go +++ b/watcher.go @@ -5,8 +5,6 @@ import ( "os" "strings" "time" - - "github.com/aymanbagabas/go-pty" ) type Watcher struct { @@ -14,19 +12,19 @@ type Watcher struct { lastline string } -func NewWatcher(ptmx pty.Pty) *Watcher { +func NewWatcher(pty io.ReadWriter) *Watcher { pipeline := make(chan string, 1024) - go io.Copy(ptmx, os.Stdin) + go io.Copy(pty, os.Stdin) go func() { for { var buffer [1024]byte - n, err := ptmx.Read(buffer[:]) + n, err := pty.Read(buffer[:]) if err != nil { close(pipeline) return } // If the code below spends a lot of time, - // It hangs up to io.Copy(ptmx, os.Stdin) + // It hangs up to io.Copy(pty, os.Stdin) // The reason is unknown. os.Stdout.Write(buffer[:n]) pipeline <- string(buffer[:n])