1

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
mklement0
  • 382,024
  • 64
  • 607
  • 775
martin's
  • 3,853
  • 6
  • 32
  • 58

1 Answers1

2

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • BTW, this is not about enabling ANSI escape sequences. This is about having a uniform UI regardless of how PowerShell is launched. At the core, I am sending an application to customers. The application is a console app. Think of it as a specialized text editor. They will get an MSI to install and have an icon to double-click to launch it. They are not developers, so no installing Python or running scripts. It has to be a double-click-and-launch experience. Pyinstaller generates an exe that launches PowerShell by itself (not Windows Terminal) and everything is broken because it is different. – martin's Sep 20 '22 at 15:22
  • As for your question, @martin's: It is _also_ about VT sequences, as evidenced by "and render escape sequences in the stand-alone case?" I understand the desire for a uniform look, but there's no out-of-the-box solution - please see my update. – mklement0 Sep 20 '22 at 15:53
  • 1
    @martin's `uniform UI regardless of how PowerShell is launched` this is impossible. PowerShell is a **shell**, just like how cmd, bash, ksh, zsh, command.com... are all shells and need to attach to a **terminal** like xterm, conhost, Windows terminal, VS code terminal... to run. The interface depends on the terminal and if you run PowerShell in a terminal like cmder or git bash terminal then it obviously won't look the same. There's no "standalone" PowerShell, if you run any apps in the console subsystem like pwsh.exe then Windows automatically open the default terminal which is conhost or WT – phuclv Sep 20 '22 at 15:58
  • Good points, @phuclv - I've updated the answer to make that clearer. I also didn't realize that Windows 11 can now be configured to use Windows Terminal by default. If you're up for it, please review the new top section for accuracy. (I'm assuming you cannot do it in Windows 10, at least not via the Settings app). – mklement0 Sep 20 '22 at 16:38
  • @martin's, please see my latest update, which hopefully covers all angles. For your specific use case - assuming Windows Terminal can be assumed to be present, and assuming Pyinstaller supports it - make the icon (shortcut file) launch PowerShell via `wt.exe` as described in the updated answer. – mklement0 Sep 20 '22 at 16:41
  • 1
    @mklement0 I see you deleted all your comments from the prior discussion so I did the same. Not relevant given your (excellent) update. – martin's Sep 20 '22 at 17:13
  • @mklement0 I think I am going to have to give-up on this. Prior to seeing your update I experimented with manually configuring `pwsh.exe` settings (both directly and invoked through a link). It's a mess. You end-up playing whack-a-mole. Getting escape sequences to work is the easy part. The font? Sure, but it doesn't look the same. Colors? Different. For example, my application uses bright red as a highlight for certain indicators, they display close to dark brown. Then there's the code page issue. MS really needs to get their act together on this front. – martin's Sep 20 '22 at 17:17
  • I think my ultimate solution will have to be to come up with a way to have Pyinstaller launch Terminal instead of PowerShell. I don't think it can do it directly. My current experimentation path will be to see if I can manually create a batch file to take the executable file produced by Pyinstaller and have that run on a PowerShell under Windows Terminal. – martin's Sep 20 '22 at 17:19
  • I can think of a few ugly hacks, however, I can't send this kind of thing to users who are not software engineers and have no interest whatsoever in dealing with running shell scripts or any such thing. All they want to do is double-click an icon. I'll mark your answer as the accepted because it has enough detail on it to understand the various issues. It doesn't solve this particular issue, but it might help others. Thanks. – martin's Sep 20 '22 at 17:22
  • Thanks, @martin's. Sounds like a tricky problem, and I agree that your best bet is to get the icon to launch `wt.exe` explicitly. If the installer supports bundling a `.reg` file, you could in theory package the tweaks for `conhost.exe` - if you ever get them to look right. The problem with a batch file is that it would invariably create its own console window on invocation, and even if you close it right away (after launching `wt.exe`), you'll see it flash on the screen. – mklement0 Sep 20 '22 at 17:35
  • 1
    I just tried it. I think my users can deal with the flash. Not a big deal. We are going to re-write this next year as a proper GUI app anyhow (and likely get away from Python in the process). – martin's Sep 20 '22 at 17:51