How to echo with different colors in the Windows command line

前端 未结 23 1508
野性不改
野性不改 2020-11-22 08:55

I know that the color bf command sets the colors of the whole command line window but I wanted to to print one single line in a different color.

23条回答
  •  误落风尘
    2020-11-22 09:51

    You can just creates files with the name of the word to print, uses findstr which can print in color, and then erases the file. Try this example:

    @echo off
    SETLOCAL EnableDelayedExpansion
    for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
      set "DEL=%%a"
    )
    
    call :ColorText 0a "green"
    call :ColorText 0C "red"
    call :ColorText 0b "cyan"
    echo(
    call :ColorText 19 "blue"
    call :ColorText 2F "white"
    call :ColorText 4e "yellow"
    
    goto :eof
    
    :ColorText
    echo off
     "%~2"
    findstr /v /a:%1 /R "^$" "%~2" nul
    del "%~2" > nul 2>&1
    goto :eof
    

    Run color /? to get a list of colors.

提交回复
热议问题