Skip to content

Commit 472d718

Browse files
authored
fix: Avoid background color query hang (#636)
Which seems to happen if stdin/stdout are somehow accidentally not TTYs. Signed-off-by: Justin Chadwell <[email protected]>
1 parent 89fafba commit 472d718

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

query.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ func BackgroundColor(in term.File, out term.File) (bg color.Color, err error) {
5454
}
5555

5656
// NOTE: On Unix, one of the given files must be a tty.
57+
if !term.IsTerminal(in.Fd()) || !term.IsTerminal(out.Fd()) {
58+
return nil, fmt.Errorf("input/output is not a terminal")
59+
}
5760
for _, f := range []term.File{in, out} {
5861
if bg, err = backgroundColor(f, f); err == nil {
5962
return bg, nil
6063
}
6164
}
6265

63-
return
66+
return bg, err
6467
}
6568

6669
// HasDarkBackground detects whether the terminal has a light or dark

0 commit comments

Comments
 (0)