T3RRYT3RR0R

Virtual terminal support test

Jan 21st, 2022 (edited)
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.89 KB | None | 0 0
  1. @Echo off
  2.  
  3.  REM demo of function for verifying Vt sequences supported \\ Note: Output of function must not be redirected.
  4.  
  5.   Call:TestVT && (
  6.    Cmd /V:On /C "Echo(!\E![38;5;0m!\E![48;5;120mVirtual terminal sequences supported!\E![K!\E![0m"
  7.   ) || (
  8.    Echo(Virtual terminal sequences NOT supported
  9.   )
  10.  
  11.   Pause
  12.  Goto:Eof
  13.  
  14.  :TestVT Author:  T3RRY ; Released: 21/01/2022 ==========================================================================
  15. REM     PURPOSE: For use with scripts that utilise Vertual terminal sequences.
  16. REM See:         https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
  17. REM     METHOD:  Utilizes powershell to Identify if the terminal running the batch script is succesfully executing virual terminal sequences,
  18. REM              by assessing which character occupies the buffer cell the cursor is currently positioned at.
  19. REM              As this method is slow, an ADS of this file or a temporary file is used to remember if virtual terminal supported
  20.  Cls
  21.  
  22.   For /f "delims=" %%e in ('Echo(Prompt $E^|cmd')Do set "\E=%%e"
  23.  
  24.   2> nul (
  25.    Set "NTFSdrive=true"
  26.    (Echo(verify) >"%~f0:ntfs.test" && (
  27.     Set "SupportINFO=%~f0:VTSupport.dat"
  28.    ) || (
  29.     Set "NTFSdrive="
  30.     For /f delims^= %%G in ("%~f0")Do Set "SupportINFO=%TEMP%\%%~nG_VTSupport.dat"
  31.   ))
  32.  
  33.   2> nul (
  34.    More < "%SupportINFO%" > nul && (
  35.      Exit /b 0
  36.    ) || (
  37.     <Nul Set /P "=Verifying Compatability %\E%[2D" 1> CON
  38.     for /F "delims=" %%a in ('"PowerShell.exe $console=$Host.UI.RawUI; $curPos=$console.CursorPosition; $rect=new-object System.Management.Automation.Host.Rectangle $curPos.X,$curPos.Y,$curPos.X,$curPos.Y; $BufCellArray=$console.GetBufferContents($rect); Write-Host $BufCellArray[0,0].Character;"') do (
  39.      Cls
  40.      If "%%a" == "y" (
  41.       (Echo(true) >"%SupportINFO%"
  42.        Exit /b 0
  43.      )else (
  44.       Exit /b 1
  45.   ))))
  46.  Exit /b 2
  47.  
Add Comment
Please, Sign In to add comment