remote_file: Only reset the terminal when stdout is a tty
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run

Avoids writing escape codes into piped output and test logs.
This commit is contained in:
Kovid Goyal 2026-11-01 12:00:40 +05:30
parent a65a01e099
commit 5a6ea12f29
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -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.