mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 14:18:26 +02:00
icat: Dont open the controlling terminal to query for size if stdout is a terminal, use it instead
This commit is contained in:
@@ -146,11 +146,15 @@ func main(cmd *cli.Command, o *Options, args []string) (rc int, err error) {
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
t, err := tty.OpenControllingTerm()
|
||||
if err != nil {
|
||||
return 1, fmt.Errorf("Failed to open controlling terminal with error: %w", err)
|
||||
if tty.IsTerminal(os.Stdout.Fd()) {
|
||||
screen_size, err = tty.GetSize(int(os.Stdout.Fd()))
|
||||
} else {
|
||||
t, oerr := tty.OpenControllingTerm()
|
||||
if oerr != nil {
|
||||
return 1, fmt.Errorf("Failed to open controlling terminal with error: %w", err)
|
||||
}
|
||||
screen_size, err = t.GetSize()
|
||||
}
|
||||
screen_size, err = t.GetSize()
|
||||
if err != nil {
|
||||
return 1, fmt.Errorf("Failed to query terminal using TIOCGWINSZ with error: %w", err)
|
||||
}
|
||||
|
||||
@@ -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" }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user