Skip to content

WSL: Use of the script utility for capturing colored output (with ANSI/VT escape sequences) breaks display formatting #20524

Open
@mklement0

Description

Prerequisites

Steps to reproduce

Note:

  • The symptom is reminiscent of the problem described in Select-String doesn't render VT (ANSI) escape sequences in its for-display output with input from external programs on Windows #18294, which was inappropriately closed.
  • However, unlike the latter, the symptom described here also affects running in Windows Terminal, not just conhost.exe console windows.
  • As in the latter issue, this is merely a display problem: it doesn't affect capturing or redirecting the output.
  • Write-Output is used below for simplicity; a real-world use case would be Tee-Object -Variable out, where you want both to-display output and to capture the (unconditionally colored) output in a variable.
# From WSL (using a WSL-installed PowerShell version)

# Dummy command that is seemingly necessary to provoke the symptom *right away*.
# Without it, the code below must be run *twice* to surface the symptom.
/bin/echo | Write-Output 

# !!  Broken display output
script -qc 'ls --color=auto /mnt/c/windows' /dev/null | Write-Output

'----------------'

# OK, due to (...) enclosure
(script -qc 'ls --color=auto /mnt/c/windows' /dev/null) | Write-Output

Expected behavior

Both script commands should properly relay the colored, columnnar ls output.

Actual behavior

The first script command's layout is broken.

Error details

No response

Environment data

PowerShell 7.3.8 on WSL (Ubuntu 20.04) on Windows 11 22H3

Visuals

Broken display output from the first command:

image

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productKeepOpenThe bot will ignore these and not auto-closeNeeds-InvestigationThe behavior reported in the issue is unexpected and needs further investigation.OS-WSLWG-Interactive-Consolethe console experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions