From ee6b990792f0c0ea14aa18c4208ca2ab77146968 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 5 Jul 2019 14:39:27 +0200 Subject: [PATCH] Applied changes from @dawidd6 to check on terminal space at start --- pkg/app/app.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 4f845439..3be17f4b 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -4,7 +4,9 @@ import ( "fmt" "io" "os" + "os/signal" "strings" + "syscall" "time" "golang.org/x/crypto/ssh/terminal" @@ -66,21 +68,20 @@ func (app *App) Run() error { func waitForTerminalSpace() error { // before we do anything, we need to check that we have some window space available - tStart := time.Now() - count := 0 - for { - width, _, err := terminal.GetSize(int(os.Stdin.Fd())) - if err != nil { - return err - } - if width != 0 { - return nil - } - count++ - time.Sleep(time.Millisecond * 50 * time.Duration(count)) - if count > 1 { - fmt.Fprintf(os.Stderr, "waited %s for available terminal space\n", time.Since(tStart)) - } + width, height, err := terminal.GetSize(int(os.Stdin.Fd())) + if err != nil { + return err + } + if width > 0 && height > 0 { + return nil + } + winch := make(chan os.Signal) + signal.Notify(winch, syscall.SIGWINCH) + select { + case <-winch: + return nil + case <-time.After(time.Second): + return fmt.Errorf("there is no available terminal space") } }