|
|
|
@ -8,6 +8,7 @@ import (
@@ -8,6 +8,7 @@ import (
|
|
|
|
|
"io" |
|
|
|
|
"log" |
|
|
|
|
"os/exec" |
|
|
|
|
"sync" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Options holds... run... options...
|
|
|
|
@ -57,12 +58,13 @@ func (r *Options) buildBaseCommand(args ...string) []string {
@@ -57,12 +58,13 @@ func (r *Options) buildBaseCommand(args ...string) []string {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type ChatAPI struct { |
|
|
|
|
sync.Mutex |
|
|
|
|
opts *Options |
|
|
|
|
Capacity int |
|
|
|
|
Reset int |
|
|
|
|
Gas int |
|
|
|
|
inChan chan string |
|
|
|
|
outChan chan string |
|
|
|
|
inChan chan []byte |
|
|
|
|
outChan chan []byte |
|
|
|
|
errChan chan error |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -83,8 +85,8 @@ type KeybaseAPIResponse struct {
@@ -83,8 +85,8 @@ type KeybaseAPIResponse struct {
|
|
|
|
|
func NewAPI(options *Options) *ChatAPI { |
|
|
|
|
return &ChatAPI{ |
|
|
|
|
opts: options, |
|
|
|
|
inChan: make(chan string, 10), |
|
|
|
|
outChan: make(chan string, 10), |
|
|
|
|
inChan: make(chan []byte, 10), |
|
|
|
|
outChan: make(chan []byte, 10), |
|
|
|
|
errChan: make(chan error, 10), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -210,7 +212,7 @@ func (a *ChatAPI) initPipes(ctx context.Context, pipes Pipes) {
@@ -210,7 +212,7 @@ func (a *ChatAPI) initPipes(ctx context.Context, pipes Pipes) {
|
|
|
|
|
case <-ctx.Done(): |
|
|
|
|
return |
|
|
|
|
default: |
|
|
|
|
line, err := r.ReadString('\n') |
|
|
|
|
line, err := r.ReadBytes('\n') |
|
|
|
|
if err != nil { |
|
|
|
|
a.errChan <- err |
|
|
|
|
} else { |
|
|
|
@ -225,7 +227,7 @@ func (a *ChatAPI) initPipes(ctx context.Context, pipes Pipes) {
@@ -225,7 +227,7 @@ func (a *ChatAPI) initPipes(ctx context.Context, pipes Pipes) {
|
|
|
|
|
for { |
|
|
|
|
select { |
|
|
|
|
case msg := <-a.inChan: |
|
|
|
|
_, err := keyIn.Write([]byte(msg)) |
|
|
|
|
_, err := keyIn.Write(msg) |
|
|
|
|
if err != nil { |
|
|
|
|
a.errChan <- err |
|
|
|
|
} |
|
|
|
|