diff --git a/.travis.yml b/.travis.yml index 897bc65..73d231d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: go go: - - "1.8" - "1.10.x" - master diff --git a/Makefile b/Makefile index b6cb58e..1f1f78c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ default: build installdep: - @go get github.com/golang/lint/golint + @go get golang.org/x/lint/golint @go get build: installdep diff --git a/jsonui.go b/jsonui.go index 1f6fa0d..250c803 100644 --- a/jsonui.go +++ b/jsonui.go @@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "io/ioutil" "log" @@ -30,6 +31,17 @@ func (p position) getCoordinate(max int) int { return int(p.prc*float32(max)) - p.margin } +type cmdLineArgs struct { + linejson bool +} + +func parseArgs() cmdLineArgs { + var args cmdLineArgs + flag.BoolVar(&args.linejson, "line", false, "to read a linejson file") + flag.Parse() + return args +} + type viewPosition struct { x0, y0, x1, y1 position } @@ -74,7 +86,8 @@ var tree treeNode func main() { var err error - tree, err = fromReader(os.Stdin) + args := parseArgs() + tree, err = fromReader(os.Stdin, args.linejson) if err != nil { log.Panicln(err) } diff --git a/test_big_line.jsonl b/test_big_line.jsonl new file mode 100644 index 0000000..2e7057d --- /dev/null +++ b/test_big_line.jsonl @@ -0,0 +1,5 @@ +{"_id": "5aad46661d83f1d4478a70d6", "index": 0, "guid": "533e17ee-ecbb-4540-ab01-18b1fbff229b", "isActive": false, "balance": "$1,572.83", "picture": "http://placehold.it/32x32", "age": 33, "eyeColor": "green", "name": "Lee Potts", "gender": "female", "company": "HOMELUX", "email": "leepotts@homelux.com", "phone": "+1 (860) 473-2707", "address": "321 Krier Place, Kennedyville, South Dakota, 2338", "about": "Aute deserunt consectetur labore consequat in amet laboris dolor amet aute anim adipisicing incididunt. Nulla nisi culpa deserunt reprehenderit ut cillum pariatur labore velit. Commodo magna anim sit amet officia. Et ea et cillum reprehenderit officia incididunt enim ea fugiat. Sit aliquip id Lorem et nulla aliqua minim exercitation aliquip Lorem.\r\n", "registered": "2017-01-06T04:10:33 -01:00", "latitude": 89.450692, "longitude": 171.363255, "tags": ["esse", "minim", "ullamco", "amet", "laboris", "aliqua", "eu"], "friends": [{"id": 0, "name": "Bernadette Dodson"}, {"id": 1, "name": "Francesca Oconnor"}, {"id": 2, "name": "Joni Pierce"}], "greeting": "Hello, Lee Potts! You have 2 unread messages.", "favoriteFruit": "apple"} +{"_id": "5aad466678c7582cf847cb3d", "index": 1, "guid": "ca7902b9-97ff-45f6-b518-58a5b415f88a", "isActive": false, "balance": "$2,476.45", "picture": "http://placehold.it/32x32", "age": 29, "eyeColor": "green", "name": "Anderson Black", "gender": "male", "company": "KENEGY", "email": "andersonblack@kenegy.com", "phone": "+1 (832) 577-3506", "address": "877 Conduit Boulevard, Kenwood, Alaska, 9413", "about": "Esse ad duis fugiat laboris velit aliqua eiusmod in anim anim mollit. Nulla ad eu officia culpa deserunt sit Lorem fugiat incididunt commodo incididunt. Velit veniam laboris magna ipsum deserunt magna.\r\n", "registered": "2014-08-26T10:27:19 -02:00", "latitude": 87.57076, "longitude": -135.016354, "tags": ["officia", "officia", "laborum", "ullamco", "ipsum", "consequat", "ad"], "friends": [{"id": 0, "name": "Tamra Brewer"}, {"id": 1, "name": "Krystal Moore"}, {"id": 2, "name": "Rosalyn Ward"}], "greeting": "Hello, Anderson Black! You have 4 unread messages.", "favoriteFruit": "strawberry"} +{"_id": "5aad4666afaf5db20037e534", "index": 2, "guid": "94c7e87d-a7b6-45db-b20a-99e290e22754", "isActive": true, "balance": "$2,494.85", "picture": "http://placehold.it/32x32", "age": 37, "eyeColor": "blue", "name": "Jordan Mcgowan", "gender": "female", "company": "VALPREAL", "email": "jordanmcgowan@valpreal.com", "phone": "+1 (817) 542-3680", "address": "238 Taaffe Place, Clarksburg, Nevada, 6185", "about": "Dolore duis adipisicing commodo incididunt laboris elit in fugiat sint et proident ut deserunt. Nulla laboris laboris magna magna enim consequat adipisicing nisi fugiat nulla. Mollit quis reprehenderit qui nulla incididunt. Lorem eu aliquip consequat elit laboris ea. Adipisicing aliqua aute reprehenderit ex ex ipsum ut quis cupidatat. Pariatur veniam voluptate commodo ea ex ea dolore. Velit quis nisi sit eu incididunt proident fugiat duis dolore ipsum in esse incididunt dolore.\r\n", "registered": "2017-09-16T05:43:31 -02:00", "latitude": -11.044863, "longitude": 90.12262, "tags": ["cupidatat", "minim", "exercitation", "Lorem", "enim", "sunt", "culpa"], "friends": [{"id": 0, "name": "Alfreda Dawson"}, {"id": 1, "name": "Arlene Wyatt"}, {"id": 2, "name": "Silvia Howell"}], "greeting": "Hello, Jordan Mcgowan! You have 10 unread messages.", "favoriteFruit": "apple"} +{"_id": "5aad4666a7f7621eb94274cb", "index": 3, "guid": "182084be-4c18-4d8f-8362-93896df1a9b1", "isActive": false, "balance": "$3,661.29", "picture": "http://placehold.it/32x32", "age": 28, "eyeColor": "blue", "name": "Dennis Randolph", "gender": "male", "company": "GUSHKOOL", "email": "dennisrandolph@gushkool.com", "phone": "+1 (843) 596-3413", "address": "704 Juliana Place, Edinburg, Idaho, 1851", "about": "Quis aliqua commodo ex quis proident ex eu fugiat aliqua enim. Dolore adipisicing id amet qui ut pariatur. Nulla anim consequat et duis culpa. Aute occaecat fugiat mollit excepteur id officia irure incididunt enim amet. Dolore in in eu incididunt labore mollit nisi laborum pariatur occaecat. Ipsum enim ea fugiat sit ipsum id ex cupidatat ut dolor eiusmod.\r\n", "registered": "2017-11-13T08:35:36 -01:00", "latitude": 63.17661, "longitude": 109.150388, "tags": ["id", "laborum", "ullamco", "laboris", "fugiat", "sint", "aliquip"], "friends": [{"id": 0, "name": "Rutledge William"}, {"id": 1, "name": "Terrie Tucker"}, {"id": 2, "name": "Latasha Miranda"}], "greeting": "Hello, Dennis Randolph! You have 4 unread messages.", "favoriteFruit": "banana"} +{"_id": "5aad46661f6b5001b0225a05", "index": 4, "guid": "5ebbe09d-5bb3-4b51-82b3-cea6a01f58f2", "isActive": false, "balance": "$3,480.46", "picture": "http://placehold.it/32x32", "age": 39, "eyeColor": "blue", "name": "Desiree Mcintosh", "gender": "female", "company": "HOMETOWN", "email": "desireemcintosh@hometown.com", "phone": "+1 (967) 571-2881", "address": "535 Ryder Street, Utting, Kentucky, 2105", "about": "Excepteur veniam et consequat tempor tempor consectetur aliqua minim magna nisi commodo laboris aliqua. Anim ex elit ad id aliquip amet officia ad cillum dolor mollit sint. Qui eu irure aute cupidatat sit enim nulla est consectetur dolore est irure duis.\r\n", "registered": "2014-09-22T04:36:59 -02:00", "latitude": -40.113604, "longitude": -175.139057, "tags": ["consectetur", "tempor", "laboris", "cupidatat", "nisi", "laborum", "nulla"], "friends": [{"id": 0, "name": "Susan Heath"}, {"id": 1, "name": "Morse Rosales"}, {"id": 2, "name": "Sanchez Watson"}], "greeting": "Hello, Desiree Mcintosh! You have 2 unread messages.", "favoriteFruit": "strawberry"} \ No newline at end of file diff --git a/tree.go b/tree.go index 2515a11..14d4baa 100644 --- a/tree.go +++ b/tree.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "encoding/json" "fmt" "io" @@ -467,10 +468,33 @@ func fromBytes(b []byte) (treeNode, error) { return newTree(y) } -func fromReader(r io.Reader) (treeNode, error) { - b, err := ioutil.ReadAll(os.Stdin) - if err != nil { - return nil, err +func fromReader(r io.Reader, linejson bool) (treeNode, error) { + var rootNode treeNode = nil + var err error = nil + if linejson { + rd := bufio.NewReader(os.Stdin) + rootList := []treeNode{} + for { + line, err := rd.ReadBytes('\n') + if err != nil { + break + } + lineTree, err := fromBytes(line) + if err != nil { + return nil, err + } + rootList = append(rootList, lineTree) + } + rootNode = &listNode{ + baseTreeNode{true}, + rootList, + } + } else { + b, err := ioutil.ReadAll(os.Stdin) + if err != nil { + return nil, err + } + rootNode, err = fromBytes(b) } - return fromBytes(b) + return rootNode, err }