From 5a6ea12f29f7a35cfd89afcf8c80cffa25386f02 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 Nov 2026 12:00:40 +0530 Subject: [PATCH] remote_file: Only reset the terminal when stdout is a tty Avoids writing escape codes into piped output and test logs. --- kittens/remote_file/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kittens/remote_file/main.go b/kittens/remote_file/main.go index 4c943da80..693f55d48 100644 --- a/kittens/remote_file/main.go +++ b/kittens/remote_file/main.go @@ -12,6 +12,7 @@ import ( "github.com/kovidgoyal/kitty/kittens/choose_files" "github.com/kovidgoyal/kitty/tools/cli" "github.com/kovidgoyal/kitty/tools/cli/markup" + "github.com/kovidgoyal/kitty/tools/tty" "github.com/kovidgoyal/kitty/tools/tui" "github.com/kovidgoyal/kitty/tools/tui/loop" "github.com/kovidgoyal/kitty/tools/tui/readline" @@ -27,8 +28,12 @@ var _ = fmt.Print // overwrite-prompt, and around the $EDITOR invocation) to clear whatever was // drawn by the previous phase/loop before drawing the next; we mirror those // call sites exactly so the two implementations look the same on screen. +// It is a no-op when stdout is not a terminal, for example when output is +// piped or captured by tests. func reset_terminal() { - fmt.Print("\x1b]\x1b\\\x1bc") + if tty.IsTerminal(os.Stdout.Fd()) { + fmt.Print("\x1b]\x1b\\\x1bc") + } } // get_key_press shows `draw` and waits for one of the runes in allowed.