Skip to content

Text formatting is not reset at exit #665

Closed

Description

Brief description of your issue

winget may emit coloured text, for instance when installing a package:

src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
36:            context.Reporter.Info() << Resource::String::ReportIdentityFound << ' ' << Execution::NameEmphasis << name << " [" << Execution::IdEmphasis << id << ']' << std::endl;

However, even if the destructor of Reporter should reset the text formatting

    Reporter::~Reporter()
    {
        // The goal of this is to return output to its previous state.
        // For now, we assume this means "default".
        GetBasicOutputStream() << TextFormat::Default;
    }

I’ve reach a case where the text format isn't reset and spills into the next commands.
It may also spill between logs of winget-cli. I believe the error lies in the Reporter class that doesn't reset the text format properly a the end of the stream.

Steps to reproduce

Install a package with winget.

Expected behavior

The text format should be reset. I have to reset it by an explicit ANSI code.

winget install --silent git & echo �[0m

Actual behavior

The reset ANSI code is not emitted.

Environment

I use v0.2.3162-preview.

Activity

  1. ghost added
    Needs-TriageIssue needs to be triaged
    on Dec 10, 2020
  2. added
    Issue-BugIt either shouldn't be doing this or needs an investigation.
    and removed
    Needs-TriageIssue needs to be triaged
    on Dec 10, 2020
  3. JohnMcPMS commented on Dec 10, 2020

    @JohnMcPMS
    Member

    I'm not aware of any way to get back to "just before we started" in terms of the console colors, so we reset to whatever the console considers the default state. I don't get the sense that this is what you are describing since your example of a fix does exactly that, but wanting to set expectations.

    I'm not seeing this behavior locally. I'm using Windows Terminal (1.4.3243.0) and PowerShell (7.1.0.0), maybe it is related to your console/shell? Which are you using?

  4. ghost added
    In-PRIssue related to a PR
    on Dec 16, 2020
  5. dra27 commented on Dec 16, 2020

    @dra27
    Contributor

    This was actually seen in docker build, for example:

    # escape=`
    
    FROM mcr.microsoft.com/windows:20H2
    
    ADD https://aka.ms/vs/16/release/vc_redist.x64.exe C:\winget-cli\
    ADD https://github.com/microsoft/winget-cli/releases/download/v0.2.3162-preview/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle C:\winget-cli\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.zip
    
    RUN C:\winget-cli\vc_redist.x64.exe /install /passive /norestart /log C:\winget-cli\vc_redist.log
    
    RUN powershell -Command "Expand-Archive -LiteralPath C:\winget-cli\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.zip -DestinationPath C:\winget-cli\ -Force"
    RUN ren C:\winget-cli\AppInstaller_x64.appx AppInstaller_x64.zip
    RUN powershell -Command "Expand-Archive -LiteralPath C:\winget-cli\AppInstaller_x64.zip -DestinationPath C:\winget-cli\ -Force"
    
    RUN md "C:\\Program Files\\winget-cli"
    RUN copy "C:\\winget-cli\\AppInstallerCLI.exe" "C:\\Program Files\\winget-cli\\winget.exe"
    RUN copy "C:\\winget-cli\\resources.pri" "C:\\Program Files\\winget-cli\\"
    
    RUN for /f "tokens=1,2,*" %a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /V Path ^| findstr /r "^[^H]"') do `
          reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /V Path /t REG_EXPAND_SZ /f /d "%c;C:\Program Files\winget-cli;C:\Program Files\Vim\vim82"
    
    RUN winget install --silent git
    
    ENTRYPOINT ["cmd.exe"]
    

    gives

    image

    but you can see it trivially by running winget normally and simply piping the output to a file - the progress and spinner widgets don't check whether VT is enabled when they set their styles.

  6. ghost removed
    In-PRIssue related to a PR
    on Dec 17, 2020
  7. jantari commented on Jul 16, 2025

    @jantari

    Could this also be the cause of #5175 ?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions