fix can't work edit json with $EDITOR on MacOS #13

develop
skanehira 5 years ago
parent d79b6e0a9d
commit 7e19c80c78

@ -29,32 +29,32 @@ $ tson -url http://gorilla/likes/json
## Keybinding ## Keybinding
### JSON tree ### JSON tree
| key | description | | key | description |
|--------|------------------------------------| |--------|--------------------------------|
| j | move down | | j | move down |
| k | move up | | k | move up |
| g | move to the top | | g | move to the top |
| G | move to the bottom | | G | move to the bottom |
| ctrl-f | page up | | ctrl-f | page up |
| ctrl-b | page down | | ctrl-b | page down |
| h | hide current node | | h | hide current node |
| H | collaspe value nodes | | H | collaspe value nodes |
| l | expand current node | | l | expand current node |
| L | expand all nodes | | L | expand all nodes |
| r | read from file | | r | read from file |
| s | save to file | | s | save to file |
| a | add new node | | a | add new node |
| A | add new value | | A | add new value |
| d | clear children nodes | | d | clear children nodes |
| e | edit json with $EDITOR(only Linux) | | e | edit json with $EDITOR |
| q | quit tson | | q | quit tson |
| Enter | edit node | | Enter | edit node |
| / | search nodes | | / | search nodes |
| ? | show helps | | ? | show helps |
| space | expand/collaspe children nodes | | space | expand/collaspe children nodes |
| ctrl-j | move to next parent node | | ctrl-j | move to next parent node |
| ctrk-k | move to next previous node | | ctrk-k | move to next previous node |
| ctrl-c | quit tson | | ctrl-c | quit tson |
### help ### help
| key | description | | key | description |

@ -339,22 +339,22 @@ func (g *Gui) NaviPanel() {
} }
func (g *Gui) EditWithEditor() { func (g *Gui) EditWithEditor() {
f, err := ioutil.TempFile("", "tson") g.App.Suspend(func() {
if err != nil { f, err := ioutil.TempFile("", "tson")
log.Println(fmt.Sprintf("can't create temp file: %s", err)) if err != nil {
g.Message(err.Error(), "main", func() {}) log.Println(fmt.Sprintf("can't create temp file: %s", err))
return g.Message(err.Error(), "main", func() {})
} return
}
defer os.RemoveAll(f.Name()) f.Close()
defer os.RemoveAll(f.Name())
if err := g.SaveJSONToFile(f.Name()); err != nil { if err := g.SaveJSONToFile(f.Name()); err != nil {
log.Println(fmt.Sprintf("can't write to temp file: %s", err)) log.Println(fmt.Sprintf("can't write to temp file: %s", err))
g.Message(err.Error(), "main", func() {}) g.Message(err.Error(), "main", func() {})
return return
} }
if b := g.App.Suspend(func() {
editor := os.Getenv("EDITOR") editor := os.Getenv("EDITOR")
if editor == "" { if editor == "" {
log.Println(fmt.Sprintf("$EDITOR is empty: %s", err)) 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. // Copy stdin to the pty and the pty to stdout.
go func() { go io.Copy(ptmx, os.Stdin)
io.Copy(ptmx, os.Stdin)
}()
io.Copy(os.Stdout, ptmx) 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) i, err := UnMarshalJSON(f)
if err != nil { if err != nil {
log.Println(fmt.Sprintf("can't read from file: %s", err)) log.Println(fmt.Sprintf("can't read from file: %s", err))
@ -423,11 +427,7 @@ func (g *Gui) EditWithEditor() {
} }
g.Tree.UpdateView(g, i) 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) { func UnMarshalJSON(in io.Reader) (interface{}, error) {

@ -38,7 +38,7 @@ var (
addNewNode = fmt.Sprintf(RedColor, "a", " add new node") addNewNode = fmt.Sprintf(RedColor, "a", " add new node")
addNewValue = fmt.Sprintf(RedColor, "A", " add new value") addNewValue = fmt.Sprintf(RedColor, "A", " add new value")
clearChildrenNodes = fmt.Sprintf(RedColor, "d", " clear children nodes") 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") quitTson = fmt.Sprintf(RedColor, "q", " quit tson")
editNodeValue = fmt.Sprintf(RedColor, "Enter", "edit current node") editNodeValue = fmt.Sprintf(RedColor, "Enter", "edit current node")
searchNodes = fmt.Sprintf(RedColor, "/", " search nodes") searchNodes = fmt.Sprintf(RedColor, "/", " search nodes")

Loading…
Cancel
Save