How do I make one particular line of a batch file a different color then the others?

前端 未结 4 829
孤独总比滥情好
孤独总比滥情好 2020-11-30 10:27

I\'m working on a program which generates the day\'s weather for D&D games. I want the program to display a warning in red text when a storm is generated so the DM is aw

4条回答
  •  执念已碎
    2020-11-30 11:01

    Script from here: How to have multiple colors in a Windows batch file? a little modified (simplyfied):

    @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"
    )
    echo next line in another color:
    call :ColorText 0c "There is an Ashstorm!"
    echo this was red.
    call :ColorText 0a "you survived it."
    
    goto :eof
    
    :ColorText
    echo off
    echo %DEL% > "%~2"
    findstr /v /a:%1 /R "^$" "%~2" nul
    del "%~2" > nul 2>&1
    goto :eof
    

    It was a link in the very first answer of "possible duplicate: How to change the text color of comments line in a batch file "

提交回复
热议问题