icat: Dont open the controlling terminal to query for size if stdout is a terminal, use it instead

This commit is contained in:
Kovid Goyal
2023-09-22 12:10:21 +05:30
parent fc1331cfdc
commit c650bd0aac
2 changed files with 14 additions and 6 deletions

View File

@@ -334,15 +334,19 @@ func (self *Term) DebugPrintln(a ...any) {
}
}
func (self *Term) GetSize() (*unix.Winsize, error) {
func GetSize(fd int) (*unix.Winsize, error) {
for {
sz, err := unix.IoctlGetWinsize(self.Fd(), unix.TIOCGWINSZ)
sz, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
if err != unix.EINTR {
return sz, err
}
}
}
func (self *Term) GetSize() (*unix.Winsize, error) {
return GetSize(self.Fd())
}
// go doesn't have a wrapper for ctermid()
func Ctermid() string { return "/dev/tty" }