Updated the printing to follow the new specs
This commit is contained in:
parent
418be9217b
commit
ddf5882c7c
25
common.go
25
common.go
@ -5,6 +5,7 @@ package jsh
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type JshFrame struct {
|
type JshFrame struct {
|
||||||
@ -22,22 +23,44 @@ func (j JshFrame) ToJson() *string {
|
|||||||
return &jsonString
|
return &jsonString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (j JshFrame) StdOutToJson() *string {
|
||||||
|
jsonOut, err := json.Marshal(j.StdOut)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
jsonString := string(jsonOut)
|
||||||
|
return &jsonString
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j JshFrame) StdErrToJson() *string {
|
||||||
|
jsonOut, err := json.Marshal(j.StdErr)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
jsonString := string(jsonOut)
|
||||||
|
return &jsonString
|
||||||
|
}
|
||||||
|
|
||||||
// goroutine for outputing frames. Pass it a channel of pointers to JshFrames,
|
// goroutine for outputing frames. Pass it a channel of pointers to JshFrames,
|
||||||
// and it will send "true" to the done channel once you close the queue channel.
|
// and it will send "true" to the done channel once you close the queue channel.
|
||||||
func OutputFrames(queue chan *JshFrame, done chan bool) {
|
func OutputFrames(queue chan *JshFrame, done chan bool) {
|
||||||
fmt.Printf("[")
|
fmt.Printf("[")
|
||||||
|
fmt.Fprintf(os.Stderr, "[")
|
||||||
isFirst := true
|
isFirst := true
|
||||||
for {
|
for {
|
||||||
frame, more := <-queue
|
frame, more := <-queue
|
||||||
if more {
|
if more {
|
||||||
if !isFirst {
|
if !isFirst {
|
||||||
fmt.Printf(",")
|
fmt.Printf(",")
|
||||||
|
fmt.Fprintf(os.Stderr, ",")
|
||||||
} else {
|
} else {
|
||||||
isFirst = false
|
isFirst = false
|
||||||
}
|
}
|
||||||
fmt.Printf(*frame.ToJson())
|
fmt.Printf(*frame.StdOutToJson())
|
||||||
|
fmt.Fprintf(os.Stderr, *frame.StdErrToJson())
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("]\n")
|
fmt.Printf("]\n")
|
||||||
|
fmt.Fprintf(os.Stderr, "]\n")
|
||||||
done <- true
|
done <- true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user