Skip to content

Change how Truncation works#6142

Open
Trenly wants to merge 15 commits intomicrosoft:masterfrom
Trenly:Truncate
Open

Change how Truncation works#6142
Trenly wants to merge 15 commits intomicrosoft:masterfrom
Trenly:Truncate

Conversation

@Trenly
Copy link
Copy Markdown
Contributor

@Trenly Trenly commented Apr 14, 2026

Problem

When winget list output is redirected to a file or variable:

  • Output was truncated at 120 characters (hardcoded fallback width)
  • Rows beyond the first 50 were truncated to widths locked by earlier rows
  • Spinner and progress bar characters appeared in the redirected output

Changes

ChannelStreams.h / ChannelStreams.cpp

  • GetConsoleWidth() now returns std::optional<size_t> — nullopt when no console is attached (stdout redirected), actual width otherwise. Eliminates the hardcoded 120-column fallback.

TableOutput.h

  • All rows are now buffered before any output is written. Column widths are computed from the full dataset in EvaluateAndFlushBuffer(), eliminating truncation and misalignment for both console and
    non-console output.
  • Column shrinking to fit console width is skipped when no console is present.
  • Removed the 50-row "sizing buffer" optimization that was the root cause of truncation even if the console was wide enough for all columns.

Note

I assumed the 50-row sizing buffer was for performance reasons and to ensure the CLI would not take too much memory. A test on my machine showed a terminal width of 220 and roughly 200 packages. Assuming a terminal width of 500 characters on an ultrawide monitor, UTF-16 encoded, with 10k rows, that would be roughly 10 MB of buffered content. Given that 10k rows and 500 characters would be a statistical anomaly, I assumed that it would be safe to remove this sizing buffer even if it comes at a minor performance cost.

ExecutionReporter.cpp

  • Spinner and progress bar are only created when a console is present (GetConsoleWidth().has_value()). When stdout is redirected they remain nullptr, suppressing all progress noise from redirected output.

ExecutionProgress.cpp, WorkflowBase.cpp, ConfigurationFlow.cpp

  • Updated call sites to handle std::optional<size_t> from GetConsoleWidth().

AppInstallerCLITests

  • Added new test cases to ensure console width creates appropriate truncation behavior
  • Added new test to ensure that buffering all lines at once does not cause issues

Microsoft Reviewers: Open in CodeFlow

@Trenly Trenly requested a review from a team as a code owner April 14, 2026 04:20
@github-actions

This comment has been minimized.

Comment thread src/AppInstallerCLICore/ChannelStreams.h Outdated
Comment thread src/AppInstallerCLICore/ExecutionProgress.cpp Outdated
Comment thread src/AppInstallerCLITests/TableOutput.cpp
@Trenly Trenly requested a review from JohnMcPMS April 16, 2026 13:26
Comment thread src/AppInstallerCLICore/ExecutionProgress.cpp Outdated
@JohnMcPMS
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

* This should be acceptable as there is a message when the text is truncated
@JohnMcPMS
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants