X Tutup
Skip to content

Commit fae66a6

Browse files
committed
Fix measuring terminal width for output
1 parent 9109b68 commit fae66a6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/iostreams/iostreams.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type IOStreams struct {
2020
Out io.Writer
2121
ErrOut io.Writer
2222

23+
// the original (non-colorable) output stream
24+
originalOut io.Writer
2325
colorEnabled bool
2426

2527
stdinTTYOverride bool
@@ -81,15 +83,16 @@ func (s *IOStreams) IsStderrTTY() bool {
8183

8284
func (s *IOStreams) TerminalWidth() int {
8385
defaultWidth := 80
84-
if s.stdoutTTYOverride {
85-
return defaultWidth
86+
out := s.Out
87+
if s.originalOut != nil {
88+
out = s.originalOut
8689
}
8790

88-
if w, _, err := terminalSize(s.Out); err == nil {
91+
if w, _, err := terminalSize(out); err == nil {
8992
return w
9093
}
9194

92-
if isCygwinTerminal(s.Out) {
95+
if isCygwinTerminal(out) {
9396
tputCmd := exec.Command("tput", "cols")
9497
tputCmd.Stdin = os.Stdin
9598
if out, err := tputCmd.Output(); err == nil {
@@ -108,6 +111,7 @@ func System() *IOStreams {
108111

109112
io := &IOStreams{
110113
In: os.Stdin,
114+
originalOut: os.Stdout,
111115
Out: colorable.NewColorable(os.Stdout),
112116
ErrOut: colorable.NewColorable(os.Stderr),
113117
colorEnabled: os.Getenv("NO_COLOR") == "" && stdoutIsTTY,

0 commit comments

Comments
 (0)
X Tutup