Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use OSC queries if we're not in control of the terminal #66

Merged
merged 1 commit into from Feb 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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