From a26de0ed4550c5cec208b544c9ef3b457d2c8556 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Thu, 21 Nov 2019 20:45:35 -0800 Subject: [PATCH] gracefully exit when no tty is present; partially addresses #253 --- runtime/ui/app.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime/ui/app.go b/runtime/ui/app.go index 0d77116..ec4c1d6 100644 --- a/runtime/ui/app.go +++ b/runtime/ui/app.go @@ -1,8 +1,11 @@ package ui import ( + "fmt" "github.com/wagoodman/dive/dive/image" "github.com/wagoodman/dive/runtime/ui/key" + "golang.org/x/crypto/ssh/terminal" + "os" "sync" "github.com/jroimartin/gocui" @@ -121,6 +124,10 @@ func (a *app) quit() error { func Run(analysis *image.AnalysisResult, treeStack filetree.Comparer) error { var err error + if !terminal.IsTerminal(int(os.Stdout.Fd())) { + return fmt.Errorf("no tty present, refusing show ui (if running in docker, use -it args)") + } + g, err := gocui.NewGui(gocui.OutputNormal) if err != nil { return err