From c8f35019f0478f356807cc07f461fd545f5d3ec1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 24 Jul 2023 15:49:18 +0530 Subject: [PATCH] Fix debugprintln to forwarded stdio implementation --- tools/tty/tty.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/tty/tty.go b/tools/tty/tty.go index 3c691a468..ca0cdd374 100644 --- a/tools/tty/tty.go +++ b/tools/tty/tty.go @@ -340,16 +340,22 @@ func (self *Term) GetSize() (*unix.Winsize, error) { // go doesn't have a wrapper for ctermid() func Ctermid() string { return "/dev/tty" } -func DebugPrintln(a ...any) { +var KittyStdout = utils.Once(func() *os.File { if fds := os.Getenv(`KITTY_STDIO_FORWARDED`); fds != "" { if fd, err := strconv.Atoi(fds); err == nil && fd > -1 { if f := os.NewFile(uintptr(fd), ""); f != nil { - fmt.Fprintln(f, a...) - f.Close() - return + return f } } } + return nil +}) + +func DebugPrintln(a ...any) { + if f := KittyStdout(); f != nil { + fmt.Fprintln(f, a...) + return + } term, err := OpenControllingTerm() if err == nil { defer term.Close()