中国DOS联盟论坛

中国DOS联盟

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

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

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
作者:
标题: ColorDemo.cmd 上一主题 | 下一主题
electronixtar
铂金会员





积分 7493
发帖 2672
注册 2005-9-2
状态 离线
『楼 主』:  ColorDemo.cmd


:: 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/a ... d/f819acd4582d5de3/

[ Last edited by electronixtar on 2007-11-23 at 03:56 PM ]

   此帖被 +8 点积分     点击查看详情   
评分人:【 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'>"
2007-11-23 15:54
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
lxmxn
版主




积分 11386
发帖 4938
注册 2006-7-23
状态 离线
『第 2 楼』:  

牛X啊,收藏学习了~~

2007-11-23 17:44
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
everest79
金牌会员

一叶枝头,万树皆春



积分 2564
发帖 1127
注册 2006-12-25
状态 离线
『第 3 楼』:  

warp需要汉化呀

2007-11-23 17:45
查看资料  发短消息 网志   编辑帖子  回复  引用回复
everest79
金牌会员

一叶枝头,万树皆春



积分 2564
发帖 1127
注册 2006-12-25
状态 离线
『第 4 楼』:  

Columns换成列在中文系统下

2007-11-23 18:12
查看资料  发短消息 网志   编辑帖子  回复  引用回复
gool123456
初级用户




积分 89
发帖 76
注册 2009-12-13
状态 离线
『第 5 楼』:  

代码作用是?

2010-3-9 02:02
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
sl543001
中级用户




积分 499
发帖 225
注册 2008-12-30
状态 离线
『第 6 楼』:  

@_@!好复杂,啥玩意?



SYBNQQ:354324773
2010-3-9 09:31
查看资料  发送邮件  发短消息 网志  OICQ (354324773)  编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: