From 71c1159aef674c34267565843539535786cb3eb3 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 4 Feb 2022 04:46:36 +0100 Subject: [PATCH] Don't use OSC queries if we're not in control of the terminal --- termenv_unix.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/termenv_unix.go b/termenv_unix.go index 2aebdfa..35211da 100644 --- a/termenv_unix.go +++ b/termenv_unix.go @@ -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") @@ -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