From af301bfff1ab4669e95f79067bb4aae1460f17c0 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 10 Sep 2021 17:36:20 -0400 Subject: [PATCH] stdin/stdout fds are not 0/1 on windows --- cmd/ghcs/common.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/ghcs/common.go b/cmd/ghcs/common.go index 229e04c78..b77d4a041 100644 --- a/cmd/ghcs/common.go +++ b/cmd/ghcs/common.go @@ -93,7 +93,9 @@ func getOrChooseCodespace(ctx context.Context, apiClient *api.API, user *api.Use return codespace, token, nil } -var hasTTY = term.IsTerminal(0) && term.IsTerminal(1) // is process connected to a terminal? +// hasTTY indicates whether the process connected to a terminal. +// It is not portable to assume stdin/stdout are fds 0 and 1. +var hasTTY = term.IsTerminal(os.Stdin.Fd()) && term.IsTerminal(os.Stdout.Fd()) // ask asks survey questions on the terminal, using standard options. // It fails unless hasTTY, but ideally callers should avoid calling it in that case.