Skip to content

Commit 902a3d4

Browse files
codesoapFiloSottile
andcommitted
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 <[email protected]>
1 parent 4a5a042 commit 902a3d4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cmd/age/age.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,6 @@ func main() {
176176
defer f.Close()
177177
out = f
178178
} else if terminal.IsTerminal(int(os.Stdout.Fd())) {
179-
if armorFlag {
180-
// If the output will go to a TTY, and it will be armored, buffer it
181-
// up so it doesn't get in the way of typing the input.
182-
buf := &bytes.Buffer{}
183-
defer func() { io.Copy(os.Stdout, buf) }()
184-
out = buf
185-
}
186179
if name != "-" {
187180
if decryptFlag {
188181
// TODO: buffer the output and check it's printable.
@@ -193,6 +186,13 @@ func main() {
193186
`Did you mean to use -a/--armor? Force with "-o -".`)
194187
}
195188
}
189+
if in == os.Stdin && terminal.IsTerminal(int(os.Stdin.Fd())) {
190+
// If the input comes from a TTY and output will go to a TTY,
191+
// buffer it up so it doesn't get in the way of typing the input.
192+
buf := &bytes.Buffer{}
193+
defer func() { io.Copy(os.Stdout, buf) }()
194+
out = buf
195+
}
196196
}
197197

198198
switch {

0 commit comments

Comments
 (0)