Skip to content

Commit

Permalink
Don't use OSC queries if we're not in control of the terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Feb 4, 2022
1 parent afdc360 commit 5ac8409
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions termenv_unix.go
Expand Up @@ -18,6 +18,15 @@ const (
OSCTimeout = 5 * time.Second
)

func isForeground(fd int) bool {
pgrp, err := unix.IoctlGetInt(fd, unix.TIOCGPGRP)
if err != nil {
return false
}

return pgrp == unix.Getpgrp()
}

func colorProfile() Profile {
term := os.Getenv("TERM")
colorTerm := os.Getenv("COLORTERM")
Expand Down Expand Up @@ -215,6 +224,11 @@ func termStatusReport(sequence int) (string, error) {
return "", ErrStatusReport
}

// if in background, we can't control the terminal
if !isForeground(unix.Stdout) {
return "", ErrStatusReport
}

t, err := unix.IoctlGetTermios(unix.Stdout, tcgetattr)
if err != nil {
return "", ErrStatusReport
Expand Down

0 comments on commit 5ac8409

Please sign in to comment.