color compatibility with Windows 10 and Windows 7

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kim974
Posts: 2
Joined: 19 Aug 2018 23:11

color compatibility with Windows 10 and Windows 7

#1 Post by kim974 » 19 Aug 2018 23:17

Hello,

I have the following code :

Code: Select all

@echo off
mode 80, 22
cls
echo.
echo  Test
echo  ____
echo.
echo.
echo   [101;104m [1] coffee           [0m
echo   [101;46m [2] Water            [0m
echo   [101;41m [3] A bed            [0m
echo   [101;93m [4] A car            [0m
echo.
set CHOICE=goaway
set /P CHOICE=What do you wish ? 
The result :
https://pasteboard.co/HzZYBnn.png

Unfortunately this code work only with Windows 10.
Can you help me to get working on both (Windows 10 & 7) ?

Thank you very much


kim974
Posts: 2
Joined: 19 Aug 2018 23:11

Re: color compatibility with Windows 10 and Windows 7

#3 Post by kim974 » 21 Aug 2018 00:29

I tried some of these code, but not able to get color for space;..

If someone can help me to get the same result as on Windows 10.

Thank you very much !

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: color compatibility with Windows 10 and Windows 7

#4 Post by aGerman » 21 Aug 2018 12:33

viewtopic.php?p=41155#p41155

Code: Select all

@echo off
call :Color 07 "  " 97 " [1] coffee           " \n 07 "  " 37 " [2] Water            " \n 07 "  " 47 " [3] A bed            " \n 07 "  " CE " [4] A car            " \n
pause

goto :eof
:Color
:: v23c
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: This version works using Cmd /U
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
Echo(|(Pause >Nul &Findstr "^" >`)
Cmd /A /D /C Set /P "=." >>` <Nul
For /F %%# In (
'"Prompt $H &For %%_ In (_) Do Rem"') Do (
Cmd /A /D /C Set /P "=%%# %%#" <Nul >`.1
Copy /Y `.1 /B + `.1 /B + `.1 /B `.3 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.3 /B `.5 /B >Nul
Copy /Y `.1 /B + `.1 /B + `.5 /B `.7 /B >Nul
)
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
For %%_ In ("&" "|" ">" "<"
) Do Set "Text=!Text:%%~_=^%%~_!"
Set /P "LF=" <` &Set "LF=!LF:~0,1!"
For %%# in ("!LF!") Do For %%_ In (
\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
For /F delims^=^ eol^= %%# in ("!Text!") Do (
If #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Cmd /A /D /C Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Del ` `.1 `.3 `.5 `.7 `.dat &Goto :Eof
Goto :__Color
... just to bring another function in the game. Although (without following the StackOververflow link) I'm sure the already offered solutions are also able to handle spaces properly...

Steffen

Post Reply