A facility to easily have child programs print to kitty stdout

Works better than the kitty-print DCS escape code as that tends to get
interleaved with other writes to the tty since the loop infrastructure
writes in a separate I/O thread.
This commit is contained in:
Kovid Goyal
2023-07-21 13:02:14 +05:30
parent eecf24b986
commit 59b47a3a8f
8 changed files with 44 additions and 13 deletions

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"io"
"os"
"strconv"
"time"
"golang.org/x/sys/unix"
@@ -340,6 +341,14 @@ func (self *Term) GetSize() (*unix.Winsize, error) {
func Ctermid() string { return "/dev/tty" }
func DebugPrintln(a ...any) {
if fds := os.Getenv(`KITTY_STDIO_FORWARDED`); fds != "" {
if fd, err := strconv.Atoi(fds); err == nil && fd > -1 {
if f := os.NewFile(uintptr(fd), "<kitty_stdout>"); f != nil {
fmt.Fprintln(f, a...)
return
}
}
}
term, err := OpenControllingTerm()
if err == nil {
defer term.Close()