Skip to content

Commit

Permalink
cli: Use glint to determine if os.Stdout is tty
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed Jul 22, 2021
1 parent 1efebbe commit 8771741
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions command/deployment_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,28 @@ func (c *DeploymentStatusCommand) Run(args []string) int {
}

func (c *DeploymentStatusCommand) monitor(client *api.Client, deployID string, index uint64, verbose bool) {
_, isStdoutTerminal := term.GetFdInfo(os.Stdout)
// TODO if/when glint offers full Windows support take out the runtime check
if isStdoutTerminal && runtime.GOOS != "windows" {
if isStdoutTerminal() {
c.ttyMonitor(client, deployID, index, verbose)
} else {
c.defaultMonitor(client, deployID, index, verbose)
}
}

func isStdoutTerminal() bool {
// TODO if/when glint offers full Windows support take out the runtime check
if runtime.GOOS == "windows" {
return false
}

// glint checks if the writer is a tty with additional
// checks (e.g. terminal has non-0 size)
r := &glint.TerminalRenderer{
Output: os.Stdout,
}

return r.LayoutRoot() != nil
}

// Uses glint for printing in place. Same logic as the defaultMonitor function
// but only used for tty and non-Windows machines since glint doesn't work with
// cmd/PowerShell and non-interactive interfaces
Expand All @@ -214,9 +227,10 @@ func (c *DeploymentStatusCommand) ttyMonitor(client *api.Client, deployID string
d.Set(spinner)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

d.RenderFrame()
go d.Render(ctx)
defer cancel()

q := api.QueryOptions{
AllowStale: true,
Expand Down

0 comments on commit 8771741

Please sign in to comment.