Browse Source

Updated the printing to follow the new specs

Fredric Silberberg 5 years ago
parent
commit
66f1bc01a2
2 changed files with 28 additions and 5 deletions
  1. 24
    1
      common.go
  2. 4
    4
      ls/main.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
 		}

+ 4
- 4
ls/main.go View File

@@ -48,17 +48,17 @@ func main() {
48 48
 	root := "." //flag.Arg(0)
49 49
 	dir, _ := ioutil.ReadDir(root)
50 50
 
51
-	fmt.Printf("[{\"StdOut\": [\n")
51
+	fmt.Printf("[\n")
52 52
 
53 53
 	if !a_flag {
54 54
 		for _, entry := range dir {
55 55
 			if entry.Name()[0] != '.' {
56 56
 				if !first {
57
-					fmt.Printf(",")
57
+					fmt.Printf(",\n")
58 58
 				} else {
59 59
 					first = false
60 60
 				}
61
-				fmt.Printf("%s\n", get_fileinfo(entry.Name(), size_flag, mode_flag, inode_flag))
61
+				fmt.Printf("%s", get_fileinfo(entry.Name(), size_flag, mode_flag, inode_flag))
62 62
 			}
63 63
 		}
64 64
 	} else {
@@ -71,5 +71,5 @@ func main() {
71 71
 			fmt.Printf("%s\n", get_fileinfo(entry.Name(), size_flag, mode_flag, inode_flag))
72 72
 		}
73 73
 	}
74
-	fmt.Printf("], \"StdErr\": []}]\n")
74
+	fmt.Printf("\n]\n")
75 75
 }

Loading…
Cancel
Save