如何在批处理文件中获取棕色文本?

时间:2015-07-14 11:54:55

标签: batch-file

我想知道是否有人知道如何将批处理文件中的文本颜色更改为棕色,这样我就可以用它在我的批处理游戏中制作污垢。

3 个答案:

答案 0 :(得分:3)

您可以使用命令 color ,然后使用屏幕截图中显示的值之一:

screenshot of console window

布朗在命令提示符中不可用作颜色,因此您必须为灰色选择 8 之类的替代颜色。

要仅为文本的特定部分着色,您需要使用API​​函数,这在批处理脚本中是不可能的。但是,看看this tool将提供一种解决此限制的方法

答案 1 :(得分:2)

虽然我在三年前发布了my method以显示批处理文件中的颜色字符,但我必须承认下载.exe辅助程序并不容易。下面的批处理文件创建了ColorShow.exe辅助程序,并显示其使用的简要说明,因此您不需要搞乱hex-to-bin转换:

@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();

这是关于ColorShow.exe用法的一个小示例程序:

@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
)

输出:

Color table in text mode

答案 2 :(得分:1)

Windows控制台没有棕色,但您可以尝试使用ascii符号176177(在这种情况下似乎是最佳选项)和178进行组合来模拟它前景色和背景色。尽管你可以使用the color function by carlos它会太慢。我会推荐coloroutput.bat实用程序,它在初始编译后会比较快:

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

或(接近褐色)

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

输出就像!

output

enter image description here

您可以尝试不同的组合(查看所有颜色尝试使用colorout.bat -help

请记住,代码页(可以使用CHCP命令查看)可能会破坏结果.Mine是437