From f46a45af36e0c80f067d3f92d71b1c1c8c5ecf6c Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 2 May 2024 11:49:41 -0300 Subject: [PATCH] fix: allow to termStatusReport on a PTY A pty is not in foreground, but it can do the IOCTL ops we need. My understanding might be wrong, but I think that if the term cannot do the TCGETS it will fail the same way it would when checking if its in foreground, so maybe that check is even needed? refs https://github.com/charmbracelet/wish/issues/262 --- output.go | 6 ++---- termenv_posix.go | 13 ------------- termenv_solaris.go | 18 ------------------ termenv_unix.go | 5 ----- 4 files changed, 2 insertions(+), 40 deletions(-) diff --git a/output.go b/output.go index ebe48fe..fc3470e 100644 --- a/output.go +++ b/output.go @@ -6,10 +6,8 @@ import ( "sync" ) -var ( - // output is the default global output. - output = NewOutput(os.Stdout) -) +// output is the default global output. +var output = NewOutput(os.Stdout) // File represents a file descriptor. // diff --git a/termenv_posix.go b/termenv_posix.go index c971dd9..ec879b0 100644 --- a/termenv_posix.go +++ b/termenv_posix.go @@ -2,16 +2,3 @@ // +build darwin dragonfly freebsd linux netbsd openbsd zos 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 index 27a95a9..84dcea6 100644 --- a/termenv_solaris.go +++ b/termenv_solaris.go @@ -2,21 +2,3 @@ // +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 d38cb27..40c3cda 100644 --- a/termenv_unix.go +++ b/termenv_unix.go @@ -238,11 +238,6 @@ func (o Output) termStatusReport(sequence int) (string, error) { if !o.unsafe { fd := int(tty.Fd()) - // if in background, we can't control the terminal - if !isForeground(fd) { - return "", ErrStatusReport - } - t, err := unix.IoctlGetTermios(fd, tcgetattr) if err != nil { return "", fmt.Errorf("%s: %s", ErrStatusReport, err)