Skip to content

Commit

Permalink
fix: remove CI exception
Browse files Browse the repository at this point in the history
Instead of making an exception to the CI environment variable, make
Termenv aware of TERMENV_TTY and assume tty using environment variables.

Users who use the CI environment variable should export TERMENV_TTY
instead using something like `export TERMENV_TTY=$CI`

Fixes: 1111971 ("Don't run OSC queries on CI")
  • Loading branch information
aymanbagabas committed Apr 14, 2023
1 parent efeeaef commit cb48c33
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion termenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package termenv
import (
"errors"
"os"
"strings"

"github.com/mattn/go-isatty"
)
Expand All @@ -29,9 +30,14 @@ func (o *Output) isTTY() bool {
if o.assumeTTY || o.unsafe {
return true
}
if len(o.environ.Getenv("CI")) > 0 {
env := o.environ.Getenv("TERMENV_TTY")
switch strings.ToLower(env) {
case "1", "true", "yes", "on":

Check failure on line 35 in termenv.go

View workflow job for this annotation

GitHub Actions / lint-soft

string `true` has 3 occurrences, make it a constant (goconst)

Check failure on line 35 in termenv.go

View workflow job for this annotation

GitHub Actions / lint-soft

string `true` has 3 occurrences, make it a constant (goconst)
return true
case "0", "false", "no", "off":
return false
}

if f, ok := o.Writer().(*os.File); ok {
return isatty.IsTerminal(f.Fd())
}
Expand Down

0 comments on commit cb48c33

Please sign in to comment.