Browse Source

Updated the printing to follow the new specs

Fredric Silberberg 5 years ago
parent
commit
ddf5882c7c
1 changed files with 24 additions and 1 deletions
  1. 24
    1
      common.go

+ 24
- 1
common.go View File

@@ -5,6 +5,7 @@ package jsh
5 5
 import (
6 6
 	"encoding/json"
7 7
 	"fmt"
8
+	"os"
8 9
 )
9 10
 
10 11
 type JshFrame struct {
@@ -22,22 +23,44 @@ func (j JshFrame) ToJson() *string {
22 23
 	return &jsonString
23 24
 }
24 25
 
26
+func (j JshFrame) StdOutToJson() *string {
27
+	jsonOut, err := json.Marshal(j.StdOut)
28
+	if err != nil {
29
+		panic(err)
30
+	}
31
+	jsonString := string(jsonOut)
32
+	return &jsonString
33
+}
34
+
35
+func (j JshFrame) StdErrToJson() *string {
36
+	jsonOut, err := json.Marshal(j.StdErr)
37
+	if err != nil {
38
+		panic(err)
39
+	}
40
+	jsonString := string(jsonOut)
41
+	return &jsonString
42
+}
43
+
25 44
 // goroutine for outputing frames. Pass it a channel of pointers to JshFrames,
26 45
 // and it will send "true" to the done channel once you close the queue channel.
27 46
 func OutputFrames(queue chan *JshFrame, done chan bool) {
28 47
 	fmt.Printf("[")
48
+	fmt.Fprintf(os.Stderr, "[")
29 49
 	isFirst := true
30 50
 	for {
31 51
 		frame, more := <-queue
32 52
 		if more {
33 53
 			if !isFirst {
34 54
 				fmt.Printf(",")
55
+				fmt.Fprintf(os.Stderr, ",")
35 56
 			} else {
36 57
 				isFirst = false
37 58
 			}
38
-			fmt.Printf(*frame.ToJson())
59
+			fmt.Printf(*frame.StdOutToJson())
60
+			fmt.Fprintf(os.Stderr, *frame.StdErrToJson())
39 61
 		} else {
40 62
 			fmt.Printf("]\n")
63
+			fmt.Fprintf(os.Stderr, "]\n")
41 64
 			done <- true
42 65
 			return
43 66
 		}

Loading…
Cancel
Save