Skip to content

fix: suppress ANSI escape sequences in PowerShell output via NO_COLOR#117

Merged
Jeomon merged 1 commit intoCursorTouch:mainfrom
JezaChen:fix/suppress-ansi-in-powershell-output
Mar 20, 2026
Merged

fix: suppress ANSI escape sequences in PowerShell output via NO_COLOR#117
Jeomon merged 1 commit intoCursorTouch:mainfrom
JezaChen:fix/suppress-ansi-in-powershell-output

Conversation

@JezaChen
Copy link
Copy Markdown
Collaborator

Summary

PowerShell 7.2+ (pwsh) can emit ANSI color escape sequences in its output (\x1b[0m, \x1b[32;1m, \x1b[44;1m, ...), which makes the captured text harder to read and increase token consumption. This PR sets NO_COLOR=1 in the subprocess environment so that pwsh 7.2+ disables ANSI formatting automatically, without touching the command string itself.

image

Changes

  • src/windows_mcp/desktop/service.py
    • Set env["NO_COLOR"] = "1" on the subprocess environment immediately after os.environ.copy(), before the PowerShell process is spawned.

Why NO_COLOR

  • Honoured natively by pwsh 7.2+ to disable all ANSI formatting.
  • Silently ignored by older Windows PowerShell, which never emits ANSI sequences anyway.
  • Also respected by many other CLI tools that may be invoked inside the PowerShell session.

Set NO_COLOR=1 in the subprocess environment so that pwsh 7.2+ disables
ANSI formatting automatically. The variable is silently ignored by
Windows PowerShell 5.1, which never emits ANSI sequences anyway, and is
also respected by other CLI tools invoked inside the PowerShell session.
Copilot AI review requested due to automatic review settings March 20, 2026 16:07
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces noisy ANSI escape sequences in captured PowerShell output by setting NO_COLOR=1 in the subprocess environment when spawning PowerShell, improving readability and reducing token usage in downstream consumption.

Changes:

  • Set NO_COLOR=1 on the environment passed to the PowerShell subprocess in execute_command.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Jeomon Jeomon merged commit 80a9807 into CursorTouch:main Mar 20, 2026
3 of 4 checks passed
@Jeomon
Copy link
Copy Markdown
Member

Jeomon commented Mar 20, 2026

For certain window like vscode some of the ui elements name i usually get was [?]
Hope this can be solved

@JezaChen
Copy link
Copy Markdown
Collaborator Author

I've also noticed this issue with VS Code. I used Accessibility Insights for Windows to investigate and found that these UI elements contain an unidentified Unicode character \uEAB6. This is likely what's causing the [?] to appear. Perhaps we could remove this specific character from the output.

PixPin_2026-03-21_22-06-02

@Jeomon
Copy link
Copy Markdown
Member

Jeomon commented Mar 21, 2026

yes may be regex filter works

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants