set tview tty to stdin when read json from stdin

develop 1.2.1
skanehira 5 years ago
parent 763423109a
commit f170037d81

@ -9,7 +9,6 @@ import (
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/gofrs/uuid" "github.com/gofrs/uuid"
"github.com/rivo/tview" "github.com/rivo/tview"
"golang.org/x/crypto/ssh/terminal"
) )
const ( const (
@ -157,9 +156,7 @@ func (t *Tree) SetKeybindings(g *Gui) {
case '?': case '?':
g.NaviPanel() g.NaviPanel()
case 'e': case 'e':
if terminal.IsTerminal(0) { g.EditWithEditor()
g.EditWithEditor()
}
case ' ': case ' ':
current := t.GetCurrentNode() current := t.GetCurrentNode()
current.SetExpanded(!current.IsExpanded()) current.SetExpanded(!current.IsExpanded())

@ -8,6 +8,7 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"syscall"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"github.com/skanehira/tson/gui" "github.com/skanehira/tson/gui"
@ -43,6 +44,7 @@ func init() {
} else { } else {
log.SetOutput(ioutil.Discard) log.SetOutput(ioutil.Discard)
} }
} }
func run() int { func run() int {
@ -57,13 +59,16 @@ func run() int {
if err != nil { if err != nil {
return printError(err) return printError(err)
} }
} } else {
if !terminal.IsTerminal(0) {
var err error
i, err = gui.UnMarshalJSON(os.Stdin)
if err != nil {
return printError(err)
}
if !terminal.IsTerminal(0) { // set tview tty to stdin
var err error os.Stdin = os.NewFile(uintptr(syscall.Stderr), "/dev/tty")
i, err = gui.UnMarshalJSON(os.Stdin)
if err != nil {
return printError(err)
} }
} }

Loading…
Cancel
Save