From dc4573c319b48a62154a35413a0fee36c283bc3d Mon Sep 17 00:00:00 2001 From: Wei Lim Date: Mon, 9 Mar 2026 17:03:25 -0700 Subject: [PATCH] Update progress log previewer to respect no-tty mode and avoid output written --- cli/azd/pkg/input/console.go | 13 ++++++++++++- cli/azd/pkg/input/progress_log.go | 9 +++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cli/azd/pkg/input/console.go b/cli/azd/pkg/input/console.go index 6d1e224637e..3ed32176008 100644 --- a/cli/azd/pkg/input/console.go +++ b/cli/azd/pkg/input/console.go @@ -336,7 +336,18 @@ func (c *AskerConsole) ShowPreviewer(ctx context.Context, options *ShowPreviewer options = defaultShowPreviewerOptions() } - c.previewer = NewProgressLog(options.MaxLineCount, options.Prefix, options.Title, c.currentIndent.Load()+currentMsg) + c.previewer = newProgressLogWithWidthFn( + options.MaxLineCount, + options.Prefix, + options.Title, + c.currentIndent.Load()+currentMsg, + func() int { + if c.consoleWidth == nil { + return 0 + } + + return int(c.consoleWidth.Load()) + }) c.previewer.Start() c.writer = c.previewer return &consolePreviewerWriter{ diff --git a/cli/azd/pkg/input/progress_log.go b/cli/azd/pkg/input/progress_log.go index 1d9dc6eb741..013916f6a08 100644 --- a/cli/azd/pkg/input/progress_log.go +++ b/cli/azd/pkg/input/progress_log.go @@ -55,8 +55,8 @@ type progressLog struct { output []string // The mutex is used to coordinate updating the header, stopping the component and printing logs. outputMutex sync.Mutex - // This function is used to find out what's the terminal width. The log progress is disabled if this function - // returns a number <= 0. + // This function is used to find out what's the terminal width. The log progress is disabled, i.e. writes are no-opt, + // if this function returns a number <= 0. terminalWidthFn TerminalWidthFn } @@ -98,6 +98,11 @@ func (p *progressLog) Start() { return } + consoleLen := p.terminalWidthFn() + if consoleLen <= 0 { + return + } + lineCount := p.lines if lineCount == 0 { lineCount = 1