From 902a3d4e6b9a6d94942150fdb4bc1fb156cbfa27 Mon Sep 17 00:00:00 2001 From: codesoap Date: Wed, 6 Jan 2021 17:28:14 +0100 Subject: [PATCH] cmd/age: decide to buffer output based on stdin source Buffering only when the armorFlag is set disregards use cases where data from a tty stdin is decrypted or where binary data goes to a tty stdout. Buffering is only necessary if stdin is a tty and stdout is a tty. Co-authored-by: Filippo Valsorda --- cmd/age/age.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/age/age.go b/cmd/age/age.go index cf9593d0..1577cc79 100644 --- a/cmd/age/age.go +++ b/cmd/age/age.go @@ -176,13 +176,6 @@ func main() { defer f.Close() out = f } else if terminal.IsTerminal(int(os.Stdout.Fd())) { - if armorFlag { - // If the output will go to a TTY, and it will be armored, buffer it - // up so it doesn't get in the way of typing the input. - buf := &bytes.Buffer{} - defer func() { io.Copy(os.Stdout, buf) }() - out = buf - } if name != "-" { if decryptFlag { // TODO: buffer the output and check it's printable. @@ -193,6 +186,13 @@ func main() { `Did you mean to use -a/--armor? Force with "-o -".`) } } + if in == os.Stdin && terminal.IsTerminal(int(os.Stdin.Fd())) { + // If the input comes from a TTY and output will go to a TTY, + // buffer it up so it doesn't get in the way of typing the input. + buf := &bytes.Buffer{} + defer func() { io.Copy(os.Stdout, buf) }() + out = buf + } } switch {