aboutsummaryrefslogtreecommitdiffstats
path: root/commands/execenv/env.go
diff options
context:
space:
mode:
authorSteve Moyer <smoyer1@selesy.com>2023-01-17 06:38:00 -0500
committerSteve Moyer <smoyer1@selesy.com>2023-01-17 06:38:00 -0500
commita73640150d8f5c8492140f9d81e7b84542b95763 (patch)
tree34c235d01500421401e1234a73ae569137e36755 /commands/execenv/env.go
parent146037733472eb74429d6c053ccbb8087fe70bca (diff)
downloadgit-bug-a73640150d8f5c8492140f9d81e7b84542b95763.tar.gz
feat: use isatty to detect a Termios instead
Diffstat (limited to 'commands/execenv/env.go')
-rw-r--r--commands/execenv/env.go48
1 files changed, 16 insertions, 32 deletions
diff --git a/commands/execenv/env.go b/commands/execenv/env.go
index 990bd726..01c00a4a 100644
--- a/commands/execenv/env.go
+++ b/commands/execenv/env.go
@@ -6,6 +6,7 @@ import (
"io"
"os"
+ "github.com/mattn/go-isatty"
"github.com/spf13/cobra"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
@@ -20,46 +21,29 @@ const RootCommandName = "git-bug"
const gitBugNamespace = "git-bug"
-type IOMode int
-
-const (
- UnknownIOMode IOMode = iota
- TerminalIOMode
- PipedOrRedirectedIOMode
-)
-
-func getIOMode(io *os.File) IOMode {
- info, err := io.Stat()
- if err != nil {
- panic("only os.StdIn or os.Stdout should be passed to this method")
- }
-
- if (info.Mode() & os.ModeCharDevice) == os.ModeCharDevice {
- return TerminalIOMode
- }
-
- return PipedOrRedirectedIOMode
+func getIOMode(io *os.File) bool {
+ return !isatty.IsTerminal(io.Fd()) && !isatty.IsCygwinTerminal(io.Fd())
}
// Env is the environment of a command
type Env struct {
- Repo repository.ClockedRepo
- Backend *cache.RepoCache
- In io.Reader
- InMode IOMode
- Out Out
- OutMode IOMode
- Err Out
+ Repo repository.ClockedRepo
+ Backend *cache.RepoCache
+ In io.Reader
+ InRedirection bool
+ Out Out
+ OutRedirection bool
+ Err Out
}
func NewEnv() *Env {
return &Env{
- Repo: nil,
- In: os.Stdin,
- InMode: getIOMode(os.Stdin),
- Out: out{Writer: os.Stdout},
- OutMode: getIOMode(os.Stdout),
- Err: out{Writer: os.Stderr},
+ Repo: nil,
+ In: os.Stdin,
+ InRedirection: getIOMode(os.Stdin),
+ Out: out{Writer: os.Stdout},
+ OutRedirection: getIOMode(os.Stdout),
+ Err: out{Writer: os.Stderr},
}
}