|
|
|
@ -2,6 +2,7 @@ package keybase
@@ -2,6 +2,7 @@ package keybase
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bufio" |
|
|
|
|
"bytes" |
|
|
|
|
"context" |
|
|
|
|
"encoding/json" |
|
|
|
|
"fmt" |
|
|
|
@ -220,16 +221,26 @@ func (a *ChatAPI) initPipes(ctx context.Context, pipes Pipes) {
@@ -220,16 +221,26 @@ func (a *ChatAPI) initPipes(ctx context.Context, pipes Pipes) {
|
|
|
|
|
// reader
|
|
|
|
|
go func() { |
|
|
|
|
r := bufio.NewReader(keyOut) |
|
|
|
|
var buf bytes.Buffer |
|
|
|
|
for { |
|
|
|
|
select { |
|
|
|
|
case <-ctx.Done(): |
|
|
|
|
return |
|
|
|
|
default: |
|
|
|
|
line, err := r.ReadBytes('\n') |
|
|
|
|
line, isPrefix, err := r.ReadLine() |
|
|
|
|
if err != nil { |
|
|
|
|
a.errChan <- err |
|
|
|
|
} |
|
|
|
|
if isPrefix { |
|
|
|
|
// if its not a complete line, write it to the buffer only so we loop again
|
|
|
|
|
buf.Write(line) |
|
|
|
|
} else { |
|
|
|
|
a.outChan <- line |
|
|
|
|
// if the line is complete, write it to the buffer
|
|
|
|
|
buf.Write(line) |
|
|
|
|
// then write the entire buffer to the channel
|
|
|
|
|
a.outChan <- buf.Bytes() |
|
|
|
|
// then reset the buffer so it can be re-used
|
|
|
|
|
buf.Reset() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|