Home > database >  How to make PowerShell look the same as in Windows Terminal?
How to make PowerShell look the same as in Windows Terminal?

Time:09-21

If I launch Windows Terminal, which, in turn, launches an instance of PowerShell 7.2.6 it looks different than if I simply launch PowerShell 7.2.6.

The top image is Windows Terminal with a PowerShell tab. Bottom image is PowerShell by itself.

Not only is the Windows Terminal version far more legible, it also renders ANSI escape codes correctly (color, cursor positioning, etc.). The stand-alone PowerShell does not.

I have confirmed, through Task Manager, that both instances are running C:\Program Files\PowerShell\7\pwsh.exe

How do I make them look the same (like under Windows Terminal) and render escape sequences in the stand-alone case?

PowerShell under Windows Terminal

PowerShell launched stand-alone

A bit more madness...

If I take the approach of manually editing the properties of the stand-alone PowerShell to match the settings I see under Windows Terminal it makes an absolute mess. For example, if I set the font to Cascadia Mono 12, which is the setting under Windows Terminal, I get microscopic text that is unusuable:

PowerShell settings gone wrong

I have to set the font size to 20 in order to approximate the look of what comes up under Windows Terminal. Also, any changes made to stand-alone PowerShell do not seem to affect PowerShell under Windows Terminal.

EDIT:

This is what Task Manager shows for these two instances. One is PowerShell launched by itself. The other is in the context of Windows Terminal. The latter does not seem to use Console Window Host.

Task Manager

Also, this isn't about legacy Windows PowerShell, which generally lives here:

C:\WINDOWS\system32\WindowsPowerShell\v1.0

This is about modern PowerShell, in this case version 7.2.6, which is installed here:

C:\Program Files\PowerShell\7

CodePudding user response:

Note:

  • If you launch a console application (such as PowerShell (Core)'s pwsh.exe CLI) directly (either directly by its executable path or via a shortcut file targeting that executable path), you'll invariably (up to Windows 10) / by default (from Windows 11) get a regular (legacy) console window, backed by conhost.exe, the Windows Console Host.

    • Such windows have their own appearance settings, distinct from Windows Terminal's; the best you can do is to manually match them, as described in the next section.

    • On Windows 11, you can now configure your system to open console applications with Windows Terminal instead: in the Settings application, search for terminal and select Choose a terminal host app for interactive command-line tools

  • Alternatively, launch PowerShell via the Windows Terminal CLI, wt.exe, which by definition gives you the desired look and unconditional support for ANSI / VT escape-sequence rendering; e.g.:

      wt.exe "C:\Program Files\PowerShell\7\pwsh.exe"
    
    • You may alternatively launch with a predefined profile, using the -p option - see this answer for more information.

    • Note that this invocation method isn't suitable for programmatic use of the PowerShell CLI (in case you want to execute commands unattended and receive their output).


  • Regular (legacy) console windows (provided by conhost.exe, the Windows Console Host) have their own font and appearance settings, distinct from Windows Terminal's; you can control them via their system menu (click on the icon in the top-left corner of the title bar and select Properties):

    • You can manually try to emulate the Windows Terminal look, such as by choosing the Cascadia Mono font, and it seems that size 20(!) is required to get the same on-screen size as the size 12 reported via Windows Terminal's settings. However, even then it looks like the font rendering differs slightly. You may also have to tweak the colors to match.

    • Note that for conhost.exe windows launched via a shortcut file (*.lnk), such as via the Start Menu and the taskbar, any modifications are saved in that shortcut file only.

      • Thus, to change the settings for an executable launched by direct invocation of the executable path, be sure to launch a session that way before making modifications, e.g. via the Run dialog (WinKey-R).

      • The modified settings are stored in the registry at
        [HKEY_CURRENT_USER\Console\<transformed-exe-path>], where <transformed-exe-path> is the full path of the executable with \ characters replaced with _, e.g.
        HKEY_CURRENT_USER\Console\C:_Program Files_PowerShell_7_pwsh.exe

  • As for unconditionally rendering VT / ANSI escape sequences in conhost.exe windows: you can activate support for them in all future conhost.exe windows via the registry, by submitting
    Set-ItemProperty HKCU:\Console VirtualTerminalLevel -Type DWORD 1, as discussed in more detail in this answer.

  • Related