diff --git a/README.md b/README.md index f020b64..f398bde 100644 --- a/README.md +++ b/README.md @@ -29,32 +29,32 @@ $ tson -url http://gorilla/likes/json ## Keybinding ### JSON tree -| key | description | -|--------|------------------------------------| -| j | move down | -| k | move up | -| g | move to the top | -| G | move to the bottom | -| ctrl-f | page up | -| ctrl-b | page down | -| h | hide current node | -| H | collaspe value nodes | -| l | expand current node | -| L | expand all nodes | -| r | read from file | -| s | save to file | -| a | add new node | -| A | add new value | -| d | clear children nodes | -| e | edit json with $EDITOR(only Linux) | -| q | quit tson | -| Enter | edit node | -| / | search nodes | -| ? | show helps | -| space | expand/collaspe children nodes | -| ctrl-j | move to next parent node | -| ctrk-k | move to next previous node | -| ctrl-c | quit tson | +| key | description | +|--------|--------------------------------| +| j | move down | +| k | move up | +| g | move to the top | +| G | move to the bottom | +| ctrl-f | page up | +| ctrl-b | page down | +| h | hide current node | +| H | collaspe value nodes | +| l | expand current node | +| L | expand all nodes | +| r | read from file | +| s | save to file | +| a | add new node | +| A | add new value | +| d | clear children nodes | +| e | edit json with $EDITOR | +| q | quit tson | +| Enter | edit node | +| / | search nodes | +| ? | show helps | +| space | expand/collaspe children nodes | +| ctrl-j | move to next parent node | +| ctrk-k | move to next previous node | +| ctrl-c | quit tson | ### help | key | description | diff --git a/gui/gui.go b/gui/gui.go index dec7e42..e522d61 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -339,22 +339,22 @@ func (g *Gui) NaviPanel() { } func (g *Gui) EditWithEditor() { - f, err := ioutil.TempFile("", "tson") - if err != nil { - log.Println(fmt.Sprintf("can't create temp file: %s", err)) - g.Message(err.Error(), "main", func() {}) - return - } - - defer os.RemoveAll(f.Name()) + g.App.Suspend(func() { + f, err := ioutil.TempFile("", "tson") + if err != nil { + log.Println(fmt.Sprintf("can't create temp file: %s", err)) + g.Message(err.Error(), "main", func() {}) + return + } + f.Close() + defer os.RemoveAll(f.Name()) - if err := g.SaveJSONToFile(f.Name()); err != nil { - log.Println(fmt.Sprintf("can't write to temp file: %s", err)) - g.Message(err.Error(), "main", func() {}) - return - } + if err := g.SaveJSONToFile(f.Name()); err != nil { + log.Println(fmt.Sprintf("can't write to temp file: %s", err)) + g.Message(err.Error(), "main", func() {}) + return + } - if b := g.App.Suspend(func() { editor := os.Getenv("EDITOR") if editor == "" { log.Println(fmt.Sprintf("$EDITOR is empty: %s", err)) @@ -409,12 +409,16 @@ func (g *Gui) EditWithEditor() { }() // Copy stdin to the pty and the pty to stdout. - go func() { - io.Copy(ptmx, os.Stdin) - }() - + go io.Copy(ptmx, os.Stdin) io.Copy(os.Stdout, ptmx) + f, err = os.Open(f.Name()) + if err != nil { + log.Println(fmt.Sprintf("can't open file: %s", err)) + g.Message(err.Error(), "main", func() {}) + return + } + i, err := UnMarshalJSON(f) if err != nil { log.Println(fmt.Sprintf("can't read from file: %s", err)) @@ -423,11 +427,7 @@ func (g *Gui) EditWithEditor() { } g.Tree.UpdateView(g, i) - }); !b { - log.Println(fmt.Sprintf("can't edit: %s", err)) - g.Message(err.Error(), "main", func() {}) - return - } + }) } func UnMarshalJSON(in io.Reader) (interface{}, error) { diff --git a/gui/navi.go b/gui/navi.go index 1301f6f..d790025 100644 --- a/gui/navi.go +++ b/gui/navi.go @@ -38,7 +38,7 @@ var ( addNewNode = fmt.Sprintf(RedColor, "a", " add new node") addNewValue = fmt.Sprintf(RedColor, "A", " add new value") clearChildrenNodes = fmt.Sprintf(RedColor, "d", " clear children nodes") - editNodes = fmt.Sprintf(RedColor, "e", " edit json with $EDITOR(only linux)") + editNodes = fmt.Sprintf(RedColor, "e", " edit json with $EDITOR") quitTson = fmt.Sprintf(RedColor, "q", " quit tson") editNodeValue = fmt.Sprintf(RedColor, "Enter", "edit current node") searchNodes = fmt.Sprintf(RedColor, "/", " search nodes")