2

I am wondering if anyone knows how to change the color of text in a batch file to brown so I can use it to make dirt in my batch games.

Jordan M. Baron
  • 231
  • 1
  • 3
  • 14
  • Is there a third party exe that I can use because I've seen people use the color brown in their batch files such as honguito98 – Jordan M. Baron Jul 14 '15 at 12:28
  • Color "4" (referred to as red in the table of my answer) could be interpreted as brown with a bit phantasy. – Stefan Wanitzek Jul 14 '15 at 13:10
  • also "6" (dark yellow) looks quite dirty (and was referenced as "brown" in the old days, if I remember correctly) – Stephan Jul 14 '15 at 13:25
  • You may use my `ColorShow.exe` auxiliary program to show text in color in a very fast way. See [this post](http://stackoverflow.com/questions/4339649/how-to-have-multiple-colors-in-a-windows-batch-file/23956113#23956113) – Aacini Jul 14 '15 at 15:05

3 Answers3

3

You can use the command color followed by one of the values shown in the screenshot:

screenshot of console window

Brown is not available as a color in the command-prompt so you have to chose an alternative color like 8 for gray.

To only color specific parts of your text you need to use API-function, which is not possible within batch-scripts. However, have a look a this tool which will provide a way to work around this limitation

Stefan Wanitzek
  • 2,009
  • 1
  • 13
  • 26
  • This will change the colour for the whole window ... I _suspect_ (but could be wrong) that OP wants to change some bits but not others. You used to be able to do things like that with ANSI.SYS in DOS days. Perhaps see [this question](http://stackoverflow.com/q/16755142/2096401) for a discussion of ANSI. – TripeHound Jul 14 '15 at 12:53
  • Good one. Added some information to archive this with the help of a little command line tool which can be called by a batch-file. – Stefan Wanitzek Jul 14 '15 at 13:08
2

Although I published my method to show color characters in Batch files three years ago, I must admit that is not easy to download the .exe auxiliary programs. The Batch file below create ColorShow.exe auxiliary program and show a brief description of its use, so you don't need to mess with the hex-to-bin conversion:

@if (@CodeSection == @Batch) @then


@echo off 

rem Create ColorShow.exe auxiliary program and show its usage
rem Antonio Perez Ayala

echo Show characters in color from Ascii codes, string literals and Batch variables.
echo/
echo ColorShow  /bf  code[*times] ^| "literal" ^| variable[:[+^|-]wide] ...
echo/
echo    /bf          Specify a color attribute (see COLOR /? for more info)
echo    ^<code^>, ^<times^> and ^<wide^> must be decimal numbers up to 255 each
echo/
echo ^<times^> repeat the previous Ascii ^<code^> character that number of times;
echo an X-letter may be used instead of the asterisk: codeXtimes
echo/
echo ^<wide^> define a field to show the variable value: justified at left, or
echo justified at rigth if wide have minus sign, or centered if wide have plus sign.
echo/
echo Color attributes may be inserted at any place in the show parameters, setting
echo the color of following parameters. If the first show parameter has not a 
echo previous attribute, the color of initial cursor position is used.
echo/
echo Use / alone to indicate the color of initial cursor position, use // to
echo indicate the initial color attribute in reverse video.
echo/
echo At end, the original attribute of initial cursor position is returned in
echo ERRORLEVEL as a *decimal* value.

if not exist ColorShow.exe call :ExtractBinaryFile ColorShow.exe
goto :EOF


rem Extract Binary File from hexadecimal digits placed in a "resource" in this .bat file

:ExtractBinaryFile filename.ext
setlocal EnableDelayedExpansion
set "start="
set "end="
for /F "tokens=1,3 delims=:=>" %%a in ('findstr /N /B "</*resource" "%~F0"') do (
   if not defined start (
      if "%%~b" equ "%~1" set start=%%a
   ) else if not defined end set end=%%a
)
(for /F "skip=%start% tokens=1* delims=:" %%a in ('findstr /N "^" "%~F0"') do (
   if "%%a" == "%end%" goto decodeHexFile
   echo %%b
)) > "%~1.hex"
:decodeHexFile
Cscript //nologo //E:JScript "%~F0" "%~1" < "%~1.hex"
del "%~1.hex"
exit /B

<resource id="ColorShow.exe">
4D5A900003[3]04[3]FFFF[2]B8[7]40[35]B8[3]0E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F74
2062652072756E20696E20444F53206D6F64652E0D0D0A24[7]5549FA721128942111289421112894219F3787211A289421ED
088621132894215269636811289421[16]5045[2]4C0103001DDBEB50[8]E0000F010B01050C0006[3]04[7]10[3]10[3]20[4]40[2]10
[3]02[2]04[7]04[8]40[3]04[6]03[5]10[2]10[4]10[2]10[6]10[11]2420[2]28[84]20[2]24[27]2E74657874[3]DE04[3]10[3]06[3]04[14]20[2]60
2E7264617461[2]3201[3]20[3]02[3]0A[14]40[2]402E64617461[3]20[4]30[3]02[3]0C[14]40[2]C0[472]E806[3]50E8A304[2]558BEC81C4
E8DFFFFFFC6AF5E8A404[2]8945FC6800304000FF75FCE88804[2]8B1D043040008D85E8DFFFFF50536A018D45FA50FF75FCE8
7E04[2]668B45FA66A316304000D41086C4D510668945F88DBDF8DFFFFF89BDF4DFFFFFE81304[2]E83204[2]8A064684C00F84
4803[2]3C2F0F858C[3]2BBDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE85F03[2]8BBDF4DFFFFF8A064684
C00F840F03[2]3C20750C668B45FA66A316304000EBA73C2F750C668B45F866A316304000EB972C303C0976082C073C0F7602
2C208A264684E40F84D602[2]80FC20741286C42C303C0976082C073C0F76022C20D51066A316304000E95CFFFFFF3C227520
8A064684C00F84A502[2]3C227405880747EBEC8A06463C2274F4E938FFFFFF3C300F82C6[3]3C390F87BE[3]E8A102[2]3C2A74
083C5874043C7875278ADC468A06463C300F826102[2]3C390F875902[2]E87A02[2]0FB6CC8AC3F3AAE9F0FEFFFF80FC207379
80FC09751F8B0D0430400003CF2B8DF4DFFFFF83E10783E908F7D9B020F3AAE9C7FEFFFF2BBDF4DFFFFF741A506A008D85E8
DFFFFF5057FFB5F4DFFFFFFF75FCE83D02[2]588BBDF4DFFFFF88276A008D85E8DFFFFF506A01FFB5F4DFFFFFFF75FCE8E302
[2]6800304000FF75FCE8BE02[2]E972FEFFFF882747E96AFEFFFF2BBDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFF
FF75FCE8E101[2]8BFE4F33DB889DF2DFFFFF8A063C3A74118885F3DFFFFF3C20746084C0745C46EBE9889DF2DFFFFFC6060046
8A06463C2D7509C685F2DFFFFF02EB0B3C2B750AC685F2DFFFFF018A06463C300F827001[2]3C390F876801[2]E86901[2]8885
F3DFFFFF3C20740884C00F855101[2]84E40F841001[2]8ADCC60600680020[2]8D85F8DFFFFF5057E80702[2]85C00F84F1[3]85
DB0F84CF[3]3BC30F84C7[3]7C2D80BDF2DFFFFF00741DF685F2DFFFFF01750A2BC30185F4DFFFFFEB0A2BC3D1E80185F4DFFF
FF8BC3E998[3]2BD88BBDF4DFFFFF03F889BDECDFFFFF50B0208BCBF3AA80BDF2DFFFFF007443F685F2DFFFFF02741C6A018D
85E8DFFFFF5053FFB5ECDFFFFFFF75FCE8C9[3]33DBEB1E8BFBD1EF2BDF6A018D85E8DFFFFF5057FFB5ECDFFFFFFF75FCE8A7
[3]588BF86A018D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE88C[3]6A028D85E8DFFFFF5053FFB5ECDFFFFFFF75FCE874[3]EB1A
8BF86A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE858[3]8A85F3DFFFFF88068DBDF8DFFFFF89BDF4DFFFFFE9A8FCFFFF2B
BDF4DFFFFF74186A008D85E8DFFFFF5057FFB5F4DFFFFFFF75FCE81F[3]0FB745FAC9C3240F8AE08A06463C30720C3C397708
2C30D50A8AE0EBED4EC3558BEC6A00FF7514FF7510FF750CFF7508E8B2[3]8B4D1066837D180172137708010D18304000EB46
030D18304000894D10578B7D0C66A116304000F366AB8B0D04304000FF751451FF7510FF750CFF7508E876[3]5F6800304000FF
7508E84A[3]C705183040[5]C9C21400CCCCCCCCCCCCCCCCE853[3]8BF08A06463C2275098A06463C2275F9EB0C8A06463C2074
0484C075F54EC38A06463C2074F94EC3CCFF2500204000FF2504204000FF2508204000FF250C204000FF2510204000FF2514
204000FF2518204000FF251C2040[291]7020[2]7E20[2]9C20[2]B620[2]C620[2]E420[2]F420[2]1221[6]4C20[10]2421[3]20[22]7020[2]7E
20[2]9C20[2]B620[2]C620[2]E420[2]F420[2]1221[6]9B004578697450726F6365737300F500476574436F6E736F6C6553637265
656E427566666572496E666F[2]1301476574456E7669726F6E6D656E745661726961626C6541006A0147657453746448616E
646C65[2]370252656164436F6E736F6C654F7574707574417474726962757465[2]EE025772697465436F6E736F6C654100F2
025772697465436F6E736F6C654F757470757441747472696275746500E600476574436F6D6D616E644C696E6541006B6572
6E656C33322E646C6C[720]
</resource>


@end


// Convert Ascii hexadecimal digits from Stdin to a binary string
var count, output = "";
while ( !WScript.Stdin.AtEndOfStream ) {
   var input = WScript.Stdin.ReadLine();
   for ( var index = 0; index < input.length; ) {
      if ( input.charAt(index) == '[' ) {
         for ( count = ++index; input.charAt(index) != ']' ; index++ ) ;
         count = parseInt(input.slice(count,index++));
         for ( var i = 1; i <= count; i++ ) output += String.fromCharCode(0);
      } else {
         output += String.fromCharCode(parseInt(input.substr(index,2),16));
         index += 2;
      }
   }
}

// Write the binary string to the output file
var ado = WScript.CreateObject("ADODB.Stream");
ado.Type = 2;  // adTypeText = 2
ado.CharSet = "iso-8859-1";  // right code page for output (no adjustments)
ado.Open();
ado.WriteText(output);
ado.SaveToFile(WScript.Arguments(0),2); // adSaveCreateOverWrite = 2
ado.Close();

This is a small example program on ColorShow.exe usage:

@echo off
setlocal EnableDelayedExpansion

set colors=0 1 2 3 4 5 6 7 8 9 A B C D E F
for %%i in (%colors%) do (
   set "line="
   for %%j in (%colors%) do set line=!line! /%%i%%j " %%i%%j "
   ColorShow !line! 13 10
)

The output:

Color table in text mode

Aacini
  • 59,374
  • 12
  • 63
  • 94
1

Windows console does not have brown color but you can try to emulate it with ascii symbols 176,177(seems to be the best option in this case) and 178 for combining foreground and background colors.Though you can use the color function by carlos it will be too slow.I would recommend the coloroutput.bat utility which after the initial compilation will be comparatively fast:

colorout.bat -s ▓▒░ -f 4 -b 14

or (closer to brown)

 colorout.bat -s ▓▒░ -f 2 -b 12

the output will be something like!

output

or

enter image description here

You can try different combinations (to see all colors try with colorout.bat -help )

Have on mind that code page (can be seen with CHCP command) could corrupt the results.Mine is 437

npocmaka
  • 51,748
  • 17
  • 123
  • 166