Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/04/2024 in all areas

  1. I appreciate the sample code -- many thanks. In the meantime, I found a workaround that supports writing ANSI colorful text to the console in both Windows Terminal and Windows Console Host. The trick is to save the text to a temp file and then type the file. #include <File.au3> #include <FileConstants.au3> #include <Process.au3> Func _ConsoleWriteANSI($sTxt, $iFg1 = 33, $iBg1 = 1, $iFg0 = 22, $iBg0 = 0) ; Write colorful text to the console ("TYPE tmp_file" method) ; Default color - Bright Yellow on Black background Local $h, $sTmpFn = _TempFile(@ScriptDir) $h = FileOpen($sTmpFn, $FO_BINARY + $FO_OVERWRITE) If $h < 0 Then Return ConsoleWrite($sTxt) If Not FileWrite($h, Chr(27) & "[" & $iFg1 & "m" & Chr(27) & _ "[" & $iBg1 & "m" & $sTxt & Chr(27) & "[" & $iFg0 & "m" & _ Chr(27) & "[" & $iBg0 & "m") Then FileClose($h) Return ConsoleWrite($sTxt) EndIf FileClose($h) _RunDos("type " & $sTmpFn) FileDelete($sTmpFn) EndFunc ;==>_ConsoleWriteANSI
    1 point
  2. #include <WinAPIProc.au3> _ConsoleWriteANSI("Hello there !." & @CRLF) ; as is, will need compilation for testing Func _ConsoleWriteANSI($sTxt, $iFg1 = 33, $iBg1 = 1, $iFg0 = 22, $iBg0 = 0) ; Write colorful text to the cmd.exe window (default = Bright Yellow on Black) ; Compile AutoIt script as a console app! ; Colors work in Windows Terminal (WT), not in Windows Console Host ; So: Set Global $bANSI = 1 if script is running in WT Local Static $bANSI = Am_I_in_WT() ; only used here ?, keep it here ? If Not $bANSI Then ConsoleWrite($sTxt) Else ConsoleWrite(Chr(27) & "[" & $iFg1 & "m" & Chr(27) & "[" & $iBg1 & _ "m" & $sTxt & Chr(27) & "[" & $iFg0 & "m" & Chr(27) & _ "[" & $iBg0 & "m") EndIf Return EndFunc ;==>_ConsoleWriteANSI Func Am_I_in_WT() ; WindowsTerminal.exe Local $n, $iParentPID = @AutoItPID For $n = 1 To 99 $iParentPID = _WinAPI_GetParentProcess($iParentPID) If $iParentPID = 0 Then ExitLoop If _WinAPI_GetProcessName($iParentPID) = "WindowsTerminal.exe" Then Return 1 Next EndFunc
    1 point
×
×
  • Create New...