中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-07-05 13:07
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » ColorDemo.cmd 查看 1,470 回复 5
楼 主 ColorDemo.cmd 发表于 2007-11-23 15:54 ·  中国 四川 成都 教育网
铂金会员
★★★★
积分 7,493
发帖 2,672
注册 2005-09-02 00:00
20年会员
UID 42173
性别 男
状态 离线

:: COLORDEMO.CMD ::::::::::::::::
@Echo OFF
SetLocal
If NOT DEFINED %0 (
Set "%0=1"
Start CMD /k%0
Goto :EOF
)
MODE CON: COLS=80 LINES=59
::CLS
Title. Coloring The Console
Set "Color.A="
Set "Color.B= Coloring The Console"
Set "Color.C="
Call :ColorPrint 0F


Echo. A Demonstration


Set "Color.B= Frank P. Westlake, 2007"
Call :ColorPrint 06
Echo.
Echo.


Set "Color.B=GENERAL"
Call :ColorPrint 0B


Set "Wrap=FINDSTR and SET/P can be used to print text in a selected"
Set "Wrap=%Wrap% color and in the default color both on the same line."
Set "Wrap=%Wrap% For example:"
Call :Wrap
Set "Wrap="
Echo.


Set "Color.A= Optional text, "
Set "Color.B=color text"
Set "Color.C=, optional text."
Call :ColorPrint 0D
Echo.


Set "Wrap=But because of the nasty colon this technique is probably"
Set "Wrap=%Wrap% only useful when a colon is useful, such as the"
Set "Wrap=%Wrap% following:"
Call :Wrap
Set "Wrap="


Echo.
Set "Color.A="
Set "Color.B= Enabled"
Set "Color.C= Wireless network interface."
Call :ColorPrint 0A


Set "Color.B= Disabled"
Set "Color.C= LAN interface."
Call :ColorPrint 0C
Echo.


Set "Color.A="
Set "Color.B=PROCEDURE"
Set "Color.C="
Call :ColorPrint 0B


Set "Wrap=The programmer sets text into one, two, or three variables
as"
Set "Wrap=%Wrap% follows:"
Call :Wrap
Echo.
Set "Color.B= VARIABLE CONTENTS"
Call :ColorPrint 0B
Set "Wrap.Hang= "
Set "Wrap= Color.A Optional text to be printed in the default
color"
Set "Wrap=%Wrap% preceding the color text."
Call :Wrap
Set "Wrap= Color.B Text to be printed in a selected color."
Call :Wrap
Set "Wrap= Color.C Optional text to be printed in the default
color"
Set "Wrap=%Wrap% following the color text."
Call :Wrap
Set "Wrap.Hang="
Echo.
Set "Wrap=The programmer then calls the :ColorPrint routine with a"
Set "Wrap=%Wrap% color value. For example:"
Call :Wrap
Set "Wrap="
Echo.
Set Wrap= Set "Color.A= Optional text, "
Call :Wrap
Set Wrap= Set "Color.B=color text"
Call :Wrap
Set Wrap= Set "Color.C=, optional text."
Call :Wrap
Set "Wrap= Call :ColorPrint 0D"
Call :Wrap
Echo.
Echo.The output:
Echo.
Set "Color.A= Optional text, "
Set "Color.B=color text"
Set "Color.C=, optional text."
Call :ColorPrint 0D
Echo.


Set "Wrap=The :ColorPrint routine creates a subdirectory in %%TEMP%%"
Set "Wrap=%Wrap% with the name of this script. This is so that there"
Set "Wrap=%Wrap% will be only one file in the directory. Then a file"
Set "Wrap=%Wrap% is created in that directory with it's name being
the"
Set "Wrap=%Wrap% string in the variable Color.B. The file is written"
Set "Wrap=%Wrap% with the contents of the variable Color.C, or only a"
Set "Wrap=%Wrap% newline if that variable is undefined. SET/P is used"
Set "Wrap=%Wrap% to print Color.A without a newline, then FINDSTR is"
Set "Wrap=%Wrap% called to search the file for a line. FINDSTR prints"
Set "Wrap=%Wrap% the filename in the color specified in the CALL"
Set "Wrap=%Wrap% statement, then the contents of the file in the"
Set "Wrap=%Wrap% default color. The file and subdirectory are then
both"
Set "Wrap=%Wrap% deleted."
Call :Wrap
Set "Wrap="
Echo.


Set "Wrap=One undesirable attribute of this technique is that it"
Set "Wrap=%Wrap% writes a file each time the print routine is called."
Call :Wrap
Set "Wrap="
Echo.
Call :Wrap The following characters may not be used in color strings:
Set Invalid="\|*/?:"
Set Invalid
Echo.
Set "Wrap=Experienced CMD script programmers might prefer to call"
Set "Wrap=%Wrap% SET/P and FINDSTR directly as needed."
Call :Wrap
Set "Wrap="
Set "Color.A="
Set "Color.B=Press any key to continue"
Set "Color.C="
Call :ColorPrint CF
PAUSE>NUL:
Exit
Goto :EOF


::::::::::::::::::::::::::::::::::::::::::::::::::ColorPrint
::ColorPrint ColorValue
Prints lines in the color specified on the command line with a nasty
colon.


INPUT VARIABLES:
Color.A First portion of line printed without color.
May be undefined.
Color.A Middle portion of line printed with the color specified
on the command line. Must be defined.
Color.C Final portion of line printed without color.
May be undefined.
CHARACTERS:
Valid: 0-9 A-Z a-z `~!@#^$%&()-_+={};',
Invalid: \|*/?:


EXAMPLE:
Set "Color.A="
Set "Color.B=Enabled"
Set "Color.C= Wireless network interface."
Call :ColorPrint 0A


:ColorPrint
MD %Temp%\%~n0
Pushd %Temp%\%~n0
Echo.%Color.C%>"%Color.B%"
Set /P =%Color.A%<NUL:
FindStr /A:%1 /R "^" "%Color.B%*"
Popd
RD /S /Q %Temp%\%~n0
Goto :EOF


::::::::::::::::::::::::::::::::::::::::::::::::::Wrap
::Wrap
Reads text on the command line and performs word wrap printing to
STDOUT.


Do NOT use tab characters. A tab is a single character when
determining
line length but it could be up to eight columns when printing; which
might destroy the wordwrap feature for that line.


INPUT VARIABLES:
Wrap Read if there is no text on the command line. Use this
variable instead of the command line when leading spaces
or special characters need to be preserved. Escape
special characters with '^'. For example:


Call :Wrap Pipe COMMAND1 to COMMAND2 using the
syntax:
SET "Wrap= COMMAND1 ^| COMMAND2"
Call :Wrap


Wrap.Indent Set this variable with the amount of spaces necessary
to indent each paragraph. Indent is first line only. For
example:


Set "Wrap.Indent= "
Call :Wrap Two leading spaces.


Wrap.Hang Set this variable with amount of spaces necessary to
indent the paragraph after the first line. For Example:


Set "Wrap.Hang= "
Call :Wrap Paragraph hang indented two spaces.


:Wrap
SetLocal
For /F "tokens=2" %%a in ('MODE^|Find "Columns"') Do (
Set /A Cols=%%a -2)
If "%*" NEQ "" Set "Wrap=%*"
If NOT DEFINED Wrap (
For /F "delims=" %%W in ('MORE') Do Call :Wrap %%W
Goto :EOF
)
Set "Wrap=%Wrap.Indent%%Wrap%"
:Wrap.Loop
CALL Set "prt=%%Wrap:~0,%cols%%%"
CALL Set "Test=%%Wrap:~%cols%%%"
Set /A i=cols
:Adjust
Set /A i=i-1
If NOT DEFINED TEST Goto :Print
If "%prt:~-1,1%" NEQ " " (
Set "prt=%prt:~0,-1%"
Goto :Adjust
)
Set /A i=i+1
:Print
CALL Set "Wrap=%%Wrap:~%i%%%"
Echo.%prt%
If DEFINED Wrap (
Set "Wrap=%Wrap.Hang%%Wrap%"
Goto :Wrap.Loop
)
EndLocal
Goto :EOF
:: END OF COLORDEMO.CMD :::::::::::::::::::::




via http://groups.google.com/group/alt.msdos.batch.nt/browse_thread/thread/f819acd4582d5de3/

[ Last edited by electronixtar on 2007-11-23 at 03:56 PM ]
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
lxmxn +8 2007-11-23 17:45

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
2 发表于 2007-11-23 17:44 ·  中国 湖北 武汉 电信
版主
★★★★★
积分 11,386
发帖 4,938
注册 2006-07-23 17:10
19年会员
UID 59080
状态 离线
牛X啊,收藏学习了~~
3 发表于 2007-11-23 17:45 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
积分 2,564
发帖 1,127
注册 2006-12-25 22:57
19年会员
UID 74552
性别 男
状态 离线
warp需要汉化呀
4 发表于 2007-11-23 18:12 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
积分 2,564
发帖 1,127
注册 2006-12-25 22:57
19年会员
UID 74552
性别 男
状态 离线
Columns换成列在中文系统下
5 发表于 2010-03-09 02:02 ·  中国 广东 广州 电信
初级用户
★★
积分 89
发帖 76
注册 2009-12-13 13:41
16年会员
UID 156499
性别 男
状态 离线
代码作用是?
6 发表于 2010-03-09 09:31 ·  中国 北京 联通
中级用户
★★
积分 499
发帖 225
注册 2008-12-30 22:09
17年会员
UID 135392
性别 男
状态 离线
@_@!好复杂,啥玩意?
SYBNQQ:354324773
论坛跳转: