-
-
Notifications
You must be signed in to change notification settings - Fork 902
Expand file tree
/
Copy pathcecho.cmd
More file actions
44 lines (35 loc) · 1.4 KB
/
cecho.cmd
File metadata and controls
44 lines (35 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
:: Don't check for `ECHO_ON` or it will get too verbose without any benefit.
@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 <bg> <fg> "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.
if defined ECHO_ON ( echo on )
endlocal
exit /b 0