- Aug
- 2,799
- 144
Further to Expanded ANSI for Subscript and Superscript Not Working
Learned some new things today about ANSI Escape codes and PowerShell under Windows Terminal.
PSStyle handles ANSI Escape codes,
but is only built-into PowerShell 7.x
PSStyle does not exist in Windows PowerShell 5.1,
because it was introduced in PowerShell 7.2 as part of the PSAnsiRendering feature.
To use PSStyle in PowerShell 5.1,
you must install a compatibility module or import a script that creates the variable manually.
I chose the Install-Module route;
$PSStyle is an automatic variable that provides ANSI escape sequences for colors, text styles, and formatting.
It allows you to write things like:
"$($PSStyle.Foreground.Green)H₂O$($PSStyle.Reset)"
Even with the PSStyle installed in PowerShell 5.1,
some $PSStyle features (like RGB rendering) won’t work because they require PowerShell 7.2+.
Thus, subscript and superscript cannot be implemented in PowerShell 5.1 using ANSI escape codes.
It must be done similar to the TCC method;
Joe
Learned some new things today about ANSI Escape codes and PowerShell under Windows Terminal.
PSStyle handles ANSI Escape codes,
but is only built-into PowerShell 7.x
PSStyle Class (System.Management.Automation)
Contains configuration for how PowerShell renders text.
learn.microsoft.com
PSStyle does not exist in Windows PowerShell 5.1,
because it was introduced in PowerShell 7.2 as part of the PSAnsiRendering feature.
To use PSStyle in PowerShell 5.1,
you must install a compatibility module or import a script that creates the variable manually.
I chose the Install-Module route;
Code:
Install-Module PSStyle
$PSStyle is an automatic variable that provides ANSI escape sequences for colors, text styles, and formatting.
It allows you to write things like:
"$($PSStyle.Foreground.Green)H₂O$($PSStyle.Reset)"
Even with the PSStyle installed in PowerShell 5.1,
some $PSStyle features (like RGB rendering) won’t work because they require PowerShell 7.2+.
Code:
$super2 = [char]0x00B2
$sub2 = [char]0x2082
$PSStyle.Foreground.Green + "X$super2 + H$sub2" + "O" + $PSStyle.Reset
X² + H₂O
Thus, subscript and superscript cannot be implemented in PowerShell 5.1 using ANSI escape codes.
It must be done similar to the TCC method;
Code:
echo X%@char[0x00B2] + H%@char[0x2082]O
Joe