How to determine if the current host can display emoji characters programmically #12451

Open
opened 2026-01-31 03:16:00 +00:00 by claunia · 0 comments
Owner

Originally created by @plastikfan on GitHub (Feb 7, 2021).

Is there a way to find out if the current host is Windows Terminal, Console, PowerShell ISE or any other host? I am asking this question from a PowerShell perspective (or any .Net Core api would suffice). I need to determine the characterstics of the currently running host and act accordingly. To be more specific, I have PowerShell functionality this displays emjoi's and as I am currently using Windows Terminal I have inadvertantly created functionality that will not work as I expected in the standard windows console.

In a powershell environment, we have access to a global variable $Host:

In Windows Terminal:

λ $host

Name             : ConsoleHost
Version          : 7.1.1
InstanceId       : ed19c947-594b-472c-abb5-d0d00306f1dd
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-GB
CurrentUICulture : en-GB
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

and in WIndows Console:

λ $host

Name             : ConsoleHost
Version          : 7.1.1
InstanceId       : ed19c947-594b-472c-abb5-d0d00306f1dd
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-GB
CurrentUICulture : en-GB
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

which are both exactly the same. I was hoping there would have been a property identifying it as the Windows Terminal or Console or any other such host type.

$host is of type: [System.Management.Automation.Host.PSHost.InternalHost], but looking through that documentation, I couldn't find anything that could help in this regard.

Alternatively, is there a way to determine if the host can render emojis? If the host is not capable of rendering unicode emojis then I need to take alternative action, (ie display alternative ascii characters). The current behaviour of Windows Console.

To illustrate my problem here is the result of some powershell functionality:

  • Windows terminal:

help display-emojis win-term

  • Windows Console:

help display-emojis win-cons

As you can see, in Windows Terminal, the Mandatory and PipeValue fields contain ✔️ and ✖️ , but in WIndows Console we simply see an ugly un-identofyable placeholder characters. I need to be able to take evasive action and display an alternative ascii sequence instead.

Thanks.

Originally created by @plastikfan on GitHub (Feb 7, 2021). Is there a way to find out if the current host is Windows Terminal, Console, PowerShell ISE or any other host? I am asking this question from a PowerShell perspective (or any .Net Core api would suffice). I need to determine the characterstics of the currently running host and act accordingly. To be more specific, I have PowerShell functionality this displays emjoi's and as I am currently using Windows Terminal I have inadvertantly created functionality that will not work as I expected in the standard windows console. In a powershell environment, we have access to a global variable $Host: In Windows Terminal: ``` λ $host Name : ConsoleHost Version : 7.1.1 InstanceId : ed19c947-594b-472c-abb5-d0d00306f1dd UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : en-GB CurrentUICulture : en-GB PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy DebuggerEnabled : True IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace ``` and in WIndows Console: ``` λ $host Name : ConsoleHost Version : 7.1.1 InstanceId : ed19c947-594b-472c-abb5-d0d00306f1dd UI : System.Management.Automation.Internal.Host.InternalHostUserInterface CurrentCulture : en-GB CurrentUICulture : en-GB PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy DebuggerEnabled : True IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace ``` which are both exactly the same. I was hoping there would have been a property identifying it as the Windows Terminal or Console or any other such host type. $host is of type: [System.Management.Automation.Host.PSHost.InternalHost], but looking through that documentation, I couldn't find anything that could help in this regard. Alternatively, is there a way to determine if the host can render emojis? If the host is not capable of rendering unicode emojis then I need to take alternative action, (ie display alternative ascii characters). The current behaviour of Windows Console. To illustrate my problem here is the result of some powershell functionality: * Windows terminal: ![help display-emojis win-term](https://user-images.githubusercontent.com/49785914/107159531-9028e500-6988-11eb-9019-b787bdf6659c.jpg) * Windows Console: ![help display-emojis win-cons](https://user-images.githubusercontent.com/49785914/107159535-9d45d400-6988-11eb-9b51-0369f2ef12eb.jpg) As you can see, in Windows Terminal, the Mandatory and PipeValue fields contain ✔️ and ✖️ , but in WIndows Console we simply see an ugly un-identofyable placeholder characters. I need to be able to take evasive action and display an alternative ascii sequence instead. Thanks.
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 03:16:00 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12451