Skip to content

Commit

Permalink
Support foreground detection on Solaris/illumos
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Feb 12, 2022
1 parent 662a4e4 commit 44cd139
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
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

0 comments on commit 44cd139

Please sign in to comment.