2019-10-29 14:01:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2019-10-29 17:28:25 +00:00
|
|
|
"github.com/skanehira/tson/gui"
|
2019-10-29 14:01:24 +00:00
|
|
|
"golang.org/x/crypto/ssh/terminal"
|
|
|
|
)
|
|
|
|
|
|
|
|
func run() int {
|
|
|
|
if !terminal.IsTerminal(0) {
|
|
|
|
b, err := ioutil.ReadAll(os.Stdin)
|
|
|
|
if err != nil {
|
2019-10-29 17:28:25 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2019-10-29 14:01:24 +00:00
|
|
|
return 1
|
|
|
|
}
|
2019-10-29 17:28:25 +00:00
|
|
|
if len(b) == 0 {
|
|
|
|
fmt.Println("json is empty")
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-10-29 14:01:24 +00:00
|
|
|
var t interface{}
|
|
|
|
if err := json.Unmarshal(b, &t); err != nil {
|
2019-10-29 17:28:25 +00:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2019-10-29 14:01:24 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2019-10-29 17:28:25 +00:00
|
|
|
if err := gui.New().Run(t); err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
return 1
|
|
|
|
}
|
2019-10-29 14:01:24 +00:00
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
os.Exit(run())
|
|
|
|
}
|