diff --git a/win/build-deps.cmd b/win/build-deps.cmd index 2adb330333..1ecef21138 100644 --- a/win/build-deps.cmd +++ b/win/build-deps.cmd @@ -35,7 +35,7 @@ if NOT "%CD%" == "%batpath%" ( set PROJECT_NAME=IfcOpenShell -call utils\cecho.cmd 15 0 "This script fetches and builds all %PROJECT_NAME% dependencies" +call utils\cecho.cmd 0 15 "This script fetches and builds all %PROJECT_NAME% dependencies" echo. :: Enable the delayed environment variable expansion needed in vs-cfg.cmd. diff --git a/win/utils/cecho.cmd b/win/utils/cecho.cmd index 2923fcb986..f0eb1b3749 100644 --- a/win/utils/cecho.cmd +++ b/win/utils/cecho.cmd @@ -1,4 +1,42 @@ -:: Usage: call cecho.cmd background foreground "message here" -:: NOTES/TODOS 1) This is super slow 2) leading spaces are omitted 3) printing string with quotes doesn't work (quotes must be escaped awkwardly) -@powershell -command write-host -background %~1 -foreground "%~2" "%3" -@exit /b +@echo off +setlocal ENABLEDELAYEDEXPANSION + +rem ========================================================== +rem cecho.cmd - Fast ANSI color echo for Windows 10+ +rem Emulates PowerShell escape codes like `t and `n +rem Usage: call cecho.cmd "Message" +rem ========================================================== + +for /F %%A in ('echo prompt $E ^| cmd') do set "ESC=%%A" + +set "BG=%~1" +set "FG=%~2" +set "TEXT=%~3" + +rem Replace PowerShell-style escapes with real characters +set "TEXT=%TEXT:`t= %" +set "TEXT=%TEXT:`"="%" + +rem Foreground color table (0–15) +set "FGCOLOR[0]=30" & set "FGCOLOR[1]=34" & set "FGCOLOR[2]=32" & set "FGCOLOR[3]=36" +set "FGCOLOR[4]=31" & set "FGCOLOR[5]=35" & set "FGCOLOR[6]=33" & set "FGCOLOR[7]=37" +set "FGCOLOR[8]=90" & set "FGCOLOR[9]=94" & set "FGCOLOR[10]=92" & set "FGCOLOR[11]=96" +set "FGCOLOR[12]=91" & set "FGCOLOR[13]=95" & set "FGCOLOR[14]=93" & set "FGCOLOR[15]=97" + +rem Background color table (0–7) +set "BGCOLOR[0]=40" & set "BGCOLOR[1]=44" & set "BGCOLOR[2]=42" & set "BGCOLOR[3]=46" +set "BGCOLOR[4]=41" & set "BGCOLOR[5]=45" & set "BGCOLOR[6]=43" & set "BGCOLOR[7]=47" + +set "FGC=!FGCOLOR[%FG%]!" +set "BGC=!BGCOLOR[%BG%]!" + +if defined BGC ( + set "STYLE=!ESC![!BGC!;!FGC!m" +) else ( + set "STYLE=!ESC![!FGC!m" +) + +echo|set /p="!STYLE!!TEXT!!ESC![0m" +echo. +endlocal +exit /b 0