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

Support foreground detection on Solaris/illumos #73

Merged
merged 1 commit into from Feb 12, 2022
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions termenv_posix.go
@@ -0,0 +1,17 @@
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
// +build darwin dragonfly freebsd linux netbsd openbsd

package termenv

import (
"golang.org/x/sys/unix"
)

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

return pgrp == unix.Getpgrp()
}
22 changes: 22 additions & 0 deletions termenv_solaris.go
@@ -0,0 +1,22 @@
//go:build solaris || illumos
// +build solaris illumos

package termenv

import (
"golang.org/x/sys/unix"
)

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

g, err := unix.Getpgrp()
if err != nil {
return false
}

return pgrp == g
}
9 changes: 0 additions & 9 deletions termenv_unix.go
Expand Up @@ -18,15 +18,6 @@ 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