mirror of
https://github.com/hymkor/lispect.git
synced 2026-09-05 16:47:42 -04:00
NewWatcher(pty.Pty) → NewWatcher(io.ReadWriter)
This commit is contained in:
+4
-6
@@ -5,8 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aymanbagabas/go-pty"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Watcher struct {
|
type Watcher struct {
|
||||||
@@ -14,19 +12,19 @@ type Watcher struct {
|
|||||||
lastline string
|
lastline string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWatcher(ptmx pty.Pty) *Watcher {
|
func NewWatcher(pty io.ReadWriter) *Watcher {
|
||||||
pipeline := make(chan string, 1024)
|
pipeline := make(chan string, 1024)
|
||||||
go io.Copy(ptmx, os.Stdin)
|
go io.Copy(pty, os.Stdin)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
var buffer [1024]byte
|
var buffer [1024]byte
|
||||||
n, err := ptmx.Read(buffer[:])
|
n, err := pty.Read(buffer[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
close(pipeline)
|
close(pipeline)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If the code below spends a lot of time,
|
// 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.
|
// The reason is unknown.
|
||||||
os.Stdout.Write(buffer[:n])
|
os.Stdout.Write(buffer[:n])
|
||||||
pipeline <- string(buffer[:n])
|
pipeline <- string(buffer[:n])
|
||||||
|
|||||||
Reference in New Issue
Block a user