From 44cd13922739113c8502a91915075264521687be Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sat, 12 Feb 2022 13:54:00 +0100 Subject: [PATCH] Support foreground detection on Solaris/illumos --- termenv_posix.go | 17 +++++++++++++++++ termenv_solaris.go | 22 ++++++++++++++++++++++ termenv_unix.go | 9 --------- 3 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 termenv_posix.go create mode 100644 termenv_solaris.go diff --git a/termenv_posix.go b/termenv_posix.go new file mode 100644 index 0000000..b2109b7 --- /dev/null +++ b/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() +} diff --git a/termenv_solaris.go b/termenv_solaris.go new file mode 100644 index 0000000..27a95a9 --- /dev/null +++ b/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 +} diff --git a/termenv_unix.go b/termenv_unix.go index 0ec89f2..5ee7c08 100644 --- a/termenv_unix.go +++ b/termenv_unix.go @@ -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")