0

I have this script and I can't manage to get multiple string colors. this is the script:

:Sentence 1
@echo off
setlocal enableextensions enabledelayedexpansion

set lines=1
set "line1=This Line in Blue, please" && set LineCount=26

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
for /L %%a in (1,1,%lines%) do set num=0&set "line=!line%%a!"&call :type1

pause>nul
goto :EOF

:type1
set /a LineCount-=1
if %LineCount% == 0 ping localhost /n 2 >nul && goto Sentence2
set "letter=!line:~%num%,1!"
set "delay=%random%%random%%random%%random%%random%%random%%random%"
set "delay=%delay:~-6%"
if not "%letter%"=="" set /p "=a%bs%%letter%" <nul

for /L %%b in (1,40,%delay%) do rem
if "%letter%"=="" echo.&goto :EOF
set /a num+=1
goto type1

:Sentence2
@echo off
setlocal enableextensions enabledelayedexpansion
echo.
set lines=1
set "line1=This Line in Red, please" && set LineCount=25

for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
for /L %%a in (1,1,%lines%) do set num=0&set "line=!line%%a!"&call :type2

pause>nul
goto :EOF

:type2
set /a LineCount-=1
if %LineCount% == 0 ping localhost /n 2 >nul && goto end
set "letter=!line:~%num%,1!"
set "delay=%random%%random%%random%%random%%random%%random%%random%"
set "delay=%delay:~-6%"
if not "%letter%"=="" set /p "=a%bs%%letter%" <nul

for /L %%b in (1,40,%delay%) do rem
if "%letter%"=="" echo.&goto :EOF
set /a num+=1
goto type2

end
echo.
pause
exit

Now I would like to get these two string in a different color: -This Line in Blue, please -This Line in Red, please

I tried FINDSTR /L and COLOR /n but I can't manage to get it right..... I know that batch doesn't really support multiple colors in a single command window, but it's possible with external files.

Could anyone help me out?

~Czgb

k_Czgb
  • 1
  • 1
  • As you have not posted code showing an attempt to color output, your question is off topic. The idea of the site is that you research and learn yourself posting your code and highlighting your particular area(s) of difficulty. You can start by taking a look at `COLOR /?` and `FINDSTR /?` from the Command prompt because you patently have not yet done so. You can use the site search and/or your search engine of choice to do your research, then you can [edit your question](https://stackoverflow.com/posts/46755447/edit) to update it with the relevant code and information. – Compo Oct 15 '17 at 13:47
  • @Compo I have though, but I can't manage to do it.. I have looked for solutions but nothing I have tried works. That's why I have made this question. – k_Czgb Oct 15 '17 at 14:59
  • The Stack Overflow search [\[batch-file\] colors](https://stackoverflow.com/search?q=%5Bbatch-file%5D+colors) lists 222 results. I don't believe it that none of the solutions work for you. Perhaps you just need to study your code and the posted code more carefully and try out even more by yourself. Or is the posted script not "*your*" script code, and you have no idea how it works and what to modify to get the output lines displayed with varying colors? – Mofi Oct 15 '17 at 16:11
  • @Mofi I found a solution, appears that what i was trying simply is an idiotic idea to execute. I wanted my lines to be colored, but it was a better idea to create colored text above it. – k_Czgb Oct 15 '17 at 20:20

1 Answers1

0

Probably msr.exe's side function can help you to add foreground and background colors to your script's running, see following screenshot. More usages and examples can see the git docs like: msr on Windows or vivid demo.

In fact, msr.exe/msr.gcc* is a cross platform exe about 1.6MB in my open project for file/text processing.

Enhance script

Quanmao
  • 92
  • 5
  • Thanks for your help, I'll look into it. – k_Czgb Oct 16 '17 at 13:29
  • Just download the `msr.exe` (or `msr-Win32.exe` if it's 32-bit Windows) and follow the built-in doc [msr on Windows](https://qualiu.github.io/msr/usage-by-running/msr-Windows.html) to add to `PATH` (just search `SET PATH`), or just run the`msr.exe` see the bottom . If you want to automate the downloading step, just follow example: https://github.com/qualiu/msrTools/blob/master/fix-file-style.bat : `where msr.exe xxx` . Glad to hear your feedback and help any of your questions if has, hope this small tool can help your daily work. – Quanmao Oct 16 '17 at 13:50