Created
October 16, 2025 06:06
-
-
Save QZLin/bbe31fcf6dbfd380981b7a9da0776686 to your computer and use it in GitHub Desktop.
powershell pofile include virtual terminal check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function IsVirtualTerminalProcessingEnabled { | |
| $MethodDefinitions = @' | |
| [DllImport("kernel32.dll", SetLastError = true)] | |
| public static extern IntPtr GetStdHandle(int nStdHandle); | |
| [DllImport("kernel32.dll", SetLastError = true)] | |
| public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode); | |
| '@ | |
| $Kernel32 = Add-Type -MemberDefinition $MethodDefinitions -Name 'Kernel32' -Namespace 'Win32' -PassThru | |
| $hConsoleHandle = $Kernel32::GetStdHandle(-11) # STD_OUTPUT_HANDLE | |
| $mode = 0 | |
| $Kernel32::GetConsoleMode($hConsoleHandle, [ref]$mode) >$null | |
| if ($mode -band 0x0004) { | |
| # 0x0004 ENABLE_VIRTUAL_TERMINAL_PROCESSING | |
| return $true | |
| } | |
| return $false | |
| } | |
| $CanUsePredictionSource = (! [System.Console]::IsOutputRedirected) -and (IsVirtualTerminalProcessingEnabled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment