找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 7521|回复: 3

[特效代码] VT.bat 批处理控制台虚拟终端序列库:让您的批处理更多彩

[复制链接]
发表于 2025-2-22 22:33:11 | 显示全部楼层 |阅读模式
本帖最后由 HOPE2021 于 2025-2-23 09:43 编辑

早在两年前,我就曾在论坛中推广使用控制台虚拟终端序列(http://www.bathome.net/thread-63749-1-1.htmlhttp://www.bathome.net/thread-65044-1-1.html),奈何其门槛高,可读性差,最终没有被广泛应用,也导致了我放下批处理。最近重回论坛,看到一好帖(http://www.bathome.net/thread-70576-1-1.html),便又想起曾经的愿望,于是花费几个小时,完成了批处理控制台虚拟终端序列库以及示例的编写工作,使得使用控制台虚拟终端序列的编程难度得以降低。希望各位能够喜欢本代码库,并能够应用在自己的批处理中。

代码和示例请见二、三楼。

为什么要使用控制台虚拟终端序列?
  • 对于实用程序,可以使得输出更有层次,方便用户阅读所输出的信息
  • 对于特效和游戏,使用控制台虚拟终端序列可以获得更多色彩,实现复杂的画面效果
  • 相比于早期用 FindStr 输出,速度更快,无临时文件,可输出效果更多


如何使用该库?
导入
  1. Call VT.bat
复制代码
使用函数和常数
方法类似于http://www.bathome.net/thread-5861-1-1.html
变量名以“VT.”起始的,是常数和独立函数。变量名以“VTInline.”起始的,是内联函数。
使用示例:

  1. %= 独立函数 =%
  2. %VT.TextCursor.EnableModeHide%
  3. %= 内联函数 =%
  4. Echo;%VTInline.Cursor.SaveCursorPosition%
  5. %= 带参数的独立函数 =%
  6. %VT.Cursor.Position:#y#;#x#=10;3%
  7. %= 带参数的内联函数 =%
  8. Echo; %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%#
复制代码
示例截图

评分

参与人数 1PB +6 技术 +1 收起 理由
老刘1号 + 6 + 1 感谢分享

查看全部评分

 楼主| 发表于 2025-2-22 22:33:58 | 显示全部楼层
本帖最后由 HOPE2021 于 2025-2-22 22:39 编辑

库代码,请保存为VT.bat
  1. %= VT.bat 批处理控制台虚拟终端序列库 =%
  2. %= 请使用 GB2312 编码保存 =%
  3. %= 参考:learn.microsoft.com/zh-cn/windows/console/console-virtual-terminal-sequences =%

  4. %================================================================%
  5. %= 初始化 ESC 字符和基本引导序列 =%
  6. %================================================================%
  7. @For /F "Delims=#" %%_ in ('Prompt #$E# ^& Echo on ^& For %%$ in ^(1^) Do DosKey') Do @Set "VT.ESC=%%_"

  8. @Set VT.CSI=%VT.ESC%[

  9. %================================================================%
  10. %= 标准颜色 =%
  11. %================================================================%

  12. @Set VT.Colors.Black=0
  13. @Set VT.Colors.Red=1
  14. @Set VT.Colors.Green=2
  15. @Set VT.Colors.Yellow=3
  16. @Set VT.Colors.Blue=4
  17. @Set VT.Colors.Magenta=5
  18. @Set VT.Colors.Cyan=6
  19. @Set VT.Colors.White=7
  20. @Set VT.Colors.Default=9

  21. %================================================================%
  22. %= 简单光标定位 =%
  23. %================================================================%

  24. @Set VTInline.Cursor.ReverseIndex=%VT.ESC%M
  25. @Set VTInline.RI=%VTInline.Cursor.ReverseIndex%

  26. @Set VTInline.Cursor.SaveCursorPosition=%VT.ESC%7
  27. @Set VTInline.DECSC=%VTInline.Cursor.SaveCursorPosition%

  28. @Set VTInline.Cursor.RestoreCursorPosition=%VT.ESC%8
  29. @Set VTInline.DECSR=%VTInline.Cursor.RestoreCursorPosition%

  30. %================================================================%
  31. %= 光标定位 =%
  32. %================================================================%

  33. @Set VTInline.Cursor.Up=%VT.CSI%#n#A
  34. @Set VTInline.CUU=%VTInline.Cursor.Up%

  35. @Set VTInline.Cursor.Down=%VT.CSI%#n#B
  36. @Set VTInline.CUD=%VTInline.Cursor.Down%

  37. @Set VTInline.Cursor.Forward=%VT.CSI%#n#C
  38. @Set VTInline.CUF=%VTInline.Cursor.Forward%

  39. @Set VTInline.Cursor.Backward=%VT.CSI%#n#D
  40. @Set VTInline.CUB=%VTInline.Cursor.Backward%

  41. @Set VTInline.Cursor.NextLine=%VT.CSI%#n#E
  42. @Set VTInline.CNL=%VTInline.Cursor.NextLine%

  43. @Set VTInline.Cursor.PreviousLine=%VT.CSI%#n#F
  44. @Set VTInline.CPL=%VTInline.Cursor.PreviousLine%

  45. @Set VTInline.Cursor.HorizontalAbsolute=%VT.CSI%#n#G
  46. @Set VTInline.CHA=%VTInline.Cursor.HorizontalAbsolute%

  47. @Set VTInline.VerticalLinePositionAbsolute=%VT.CSI%#n#d
  48. @Set VTInline.VPA=%VTInline.VerticalLinePositionAbsolute%

  49. @Set VTInline.Cursor.Position=%VT.CSI%#y#;#x#H
  50. @Set VTInline.CUP=%VTInline.Cursor.Position%

  51. @Set VTInline.Cursor.HorizontalVerticalPosition=%VT.CSI%#y#;#x#f
  52. @Set VTInline.HVP=%VTInline.Cursor.HorizontalVerticalPosition%

  53. @Set VTInline.Cursor.SaveCursorAnsiSysEmulation=%VT.CSI%s
  54. @Set VTInline.ANSISYSSC=%VTInline.Cursor.SaveCursorAnsiSysEmulation%

  55. @Set VTInline.Cursor.RestoreCursorAnsiSysEmulation=%VT.CSI%u
  56. @Set VTInline.ANSISYSRC=%VTInline.Cursor.RestoreCursorAnsiSysEmulation%

  57. %================================================================%
  58. %= 光标可见性 =%
  59. %================================================================%

  60. @Set VTInline.TextCursor.EnableBlinking=%VT.CSI%?12h
  61. @Set VTInline.TextCursor.DisableBlinking=%VT.CSI%?12l
  62. @Set VTInline.TextCursor.EnableModeShow=%VT.CSI%?25h
  63. @Set VTInline.TextCursor.EnableModeHide=%VT.CSI%?25l

  64. %================================================================%
  65. %= 光标形状 =%
  66. %================================================================%

  67. @Set VTInline.TextCursor.UserShape=%VT.CSI%0 q
  68. @Set VTInline.TextCursor.BlinkingBlock=%VT.CSI%1 q
  69. @Set VTInline.TextCursor.SteadyBlock=%VT.CSI%2 q
  70. @Set VTInline.TextCursor.BlinkingUnderline=%VT.CSI%3 q
  71. @Set VTInline.TextCursor.SteadyUnderline=%VT.CSI%4 q
  72. @Set VTInline.TextCursor.BlinkingBar=%VT.CSI%5 q
  73. @Set VTInline.TextCursor.SteadyBar=%VT.CSI%6 q

  74. %================================================================%
  75. %= 视区定位 =%
  76. %================================================================%

  77. @Set VTInline.Viewport.ScrollUp=%VT.CSI%#n#S
  78. @Set VTInline.SU=%VTInline.Viewport.ScrollUp%

  79. @Set VTInline.Viewport.ScrollDown=%VT.CSI%#n#T
  80. @Set VTInline.SD=%VTInline.Viewport.ScrollDown%

  81. %================================================================%
  82. %= 文本修改 =%
  83. %================================================================%

  84. @Set VTInline.Text.InsertCharacter=%VT.CSI%#n#@
  85. @Set VTInline.ICH=%VTInline.Text.InsertCharacter%

  86. @Set VTInline.Text.DeleteCharacter=%VT.CSI%#n#P
  87. @Set VTInline.DCH=%VTInline.Text.DeleteCharacter%

  88. @Set VTInline.Text.EraseCharacter=%VT.CSI%#n#X
  89. @Set VTInline.ECH=%VTInline.Text.EraseCharacter%

  90. @Set VTInline.Text.InsertLine=%VT.CSI%#n#L
  91. @Set VTInline.IL=%VTInline.Text.InsertLine%

  92. @Set VTInline.Text.DeleteLine=%VT.CSI%#n#M
  93. @Set VTInline.DL=%VTInline.Text.DeleteLine%

  94. @Set VTInline.Text.EraseInDisplay=%VT.CSI%#n#J
  95. @Set VTInline.ED=%VTInline.Text.EraseInDisplay%

  96. @Set VTInline.Text.EraseInLine=%VT.CSI%#n#K
  97. @Set VTInline.EL=%VTInline.Text.EraseInLine%

  98. %================================================================%
  99. %= 文本格式 =%
  100. %================================================================%

  101. @Set VTInline.Formatting.SetGraphicsRendition=%VT.CSI%#n#m
  102. @Set VTInline.SGR=%VTInline.Formatting.SetGraphicsRendition%

  103. @Set VTInline.Formatting.Default=%VTInline.SGR:#n#=0%
  104. @Set VTInline.Formatting.BoldOrBright=%VTInline.SGR:#n#=1%
  105. @Set VTInline.Formatting.NoBoldOrBright=%VTInline.SGR:#n#=22%
  106. @Set VTInline.Formatting.Underline=%VTInline.SGR:#n#=4%
  107. @Set VTInline.Formatting.NoUnderline=%VTInline.SGR:#n#=24%
  108. @Set VTInline.Formatting.Negative=%VTInline.SGR:#n#=7%
  109. @Set VTInline.Formatting.NoNegative=%VTInline.SGR:#n#=27%
  110. @Set VTInline.Formatting.Positive=%VTInline.SGR:#n#=7%

  111. @Set VTInline.Formatting.Foreground=%VTInline.SGR:#n#=3#n#%
  112. @Set VTInline.Formatting.Background=%VTInline.SGR:#n#=4#n#%

  113. @Set VTInline.Formatting.BrightForeground=%VTInline.SGR:#n#=9#n#%
  114. @Set VTInline.Formatting.BrightBackground=%VTInline.SGR:#n#=10#n#%

  115. @Set VTInline.Formatting.ForegroundRGB=%VTInline.SGR:#n#=38;2;#r#;#g#;#b#%
  116. @Set VTInline.Formatting.BackgroundRGB=%VTInline.SGR:#n#=48;2;#r#;#g#;#b#%

  117. @Set VTInline.Formatting.Foreground256=%VTInline.SGR:#n#=38;5;#s#%
  118. @Set VTInline.Formatting.Background256=%VTInline.SGR:#n#=48;5;#s#%

  119. @Set VTInline.Formatting.Foreground88=%VTInline.SGR:#n#=38;5;#s#%
  120. @Set VTInline.Formatting.Background88=%VTInline.SGR:#n#=48;5;#s#%

  121. %================================================================%
  122. %= 屏幕颜色(索引):由于行为似乎不能被 CMD 实现,所以不支持 =%
  123. %================================================================%

  124. %================================================================%
  125. %= 模式更改:由于行为似乎不能被 CMD 实现,所以不支持 =%
  126. %================================================================%

  127. %================================================================%
  128. %= 查询状态:由于行为似乎不能被 CMD 完全实现,所以不支持 =%
  129. %================================================================%

  130. %================================================================%
  131. %= 制表符 =%
  132. %================================================================%

  133. @Set VTInline.Tabs.HorizontalTabSet=%VT.ESC%H
  134. @Set VTInline.Tabs.HTS=%VTInline.Tabs.HorizontalTabSet%

  135. @Set VTInline.Tabs.CursorHorizontalForwardTab=%VT.CSI%#n#I
  136. @Set VTInline.CHT=%VTInline.Tabs.CursorHorizontalForwardTab%

  137. @Set VTInline.Tabs.CursorBackwardsTab=%VT.CSI%#n#Z
  138. @Set VTInline.CBT=%VTInline.Tabs.CursorBackwardsTab%

  139. @Set VTInline.Tabs.TabClearCurrentColumn=%VT.CSI%0g
  140. @Set VTInline.Tabs.TabClearAllColumns=%VT.CSI%3g

  141. %================================================================%
  142. %= 指定字符集 =%
  143. %================================================================%

  144. @Set VTInline.CharacterSet.DEC=%VT.ESC%(0
  145. @Set VTInline.CharacterSet.ASCII=%VT.ESC%(B

  146. %================================================================%
  147. %= 滚动边距 =%
  148. %================================================================%

  149. @Set VTInline.SetScrollingRegion=%VT.CSI%#t#;#b#r
  150. @Set VTInline.DECSTBM=%VTInline.SetScrollingRegion%

  151. %================================================================%
  152. %= 窗口标题:由于有 Title 命令,没有必要实现 =%
  153. %================================================================%

  154. %================================================================%
  155. %= 备用屏幕缓冲区 =%
  156. %================================================================%

  157. @Set VTInline.Buffers.UseAlternateScreenBuffer=%VT.CSI%?1049h
  158. @Set VTInline.Buffers.UseMainScreenBuffer=%VT.CSI%?1049l

  159. %================================================================%
  160. %= 窗口宽度:由于行为似乎不能被 CMD 实现,所以不支持 =%
  161. %================================================================%

  162. %================================================================%
  163. %= 软重置 =%
  164. %================================================================%

  165. @Set VTInline.SoftReset=%VT.CSI%!p
  166. @Set VTInline.DECSTR=%VTInline.SoftReset%

  167. %================================================================%
  168. %= 输入序列:由于行为似乎不能被 CMD 实现,所以不支持 =%
  169. %================================================================%

  170. %================================================================%
  171. %= 生成命令版函数 =%
  172. %================================================================%

  173. @For /F "delims=. tokens=1,*" %%I in ('@Set VTInline') Do @(
  174.     @For /F "delims== tokens=1,*" %%i in ('Echo;%%J') Do @(
  175.         @Set "VT.%%i=@Set /P="%%j"< Nul"
  176.     )
  177. )

  178. %================================================================%
  179. %= 软重置 =%
  180. %================================================================%

  181. %VT.SoftReset%
复制代码
 楼主| 发表于 2025-2-22 22:34:22 | 显示全部楼层
示例代码:
  1. @Echo Off & Color 1F & Chcp 936 > Nul & Title 批处理控制台虚拟终端序列库测试 & Mode Con: Cols=80 Lines=25
  2. If "%*"=="" (
  3.         Start ConHost "%~0" CONHOST
  4.         Exit /B 0
  5. )

  6. %= 初始化批处理控制台虚拟终端序列库 =%
  7. Echo;正在初始化批处理控制台虚拟终端序列库……
  8. Call VT.bat
  9. SetLocal EnableExtensions EnableDelayedExpansion

  10. :Main

  11.         %VT.TextCursor.EnableModeHide%

  12.         %VT.Formatting.Background:#n#=!VT.Colors.White!%
  13.         %VT.Cursor.Position:#y#;#x#=1;1%
  14.         %VT.Text.EraseCharacter:#n#=80%
  15.    
  16.         Echo; %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%#^
  17. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!% F%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%文件^
  18. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!% E%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%编辑^
  19. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%   S%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%搜索^
  20. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%   R%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%运行^
  21. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%   C%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%编译^
  22. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%   D%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%调试^
  23. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%   P%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%项目^
  24. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%   O%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%选项^
  25. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%   W%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%窗口^
  26. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%   H%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!%帮助

  27.         %VT.Cursor.Position:#y#;#x#=25;1%
  28.         %VT.Text.EraseCharacter:#n#=80%

  29.         Set /P=%VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!% F1%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!% 帮助^
  30. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%  F2%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!% 保存^
  31. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%  F3%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!% 打开^
  32. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%  Alt-F9%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!% 编译^
  33. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%  F9%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!% 生成^
  34. %VTInline.Formatting.Foreground:#n#=!VT.Colors.Red!%  F10%VTInline.Formatting.Foreground:#n#=!VT.Colors.Black!% 菜单< Nul

  35.         %VT.Formatting.Background:#n#=!VT.Colors.Blue!%
  36.         %VT.Formatting.BrightForeground:#n#=!VT.Colors.White!%
  37.         Call :Rect 2 2 78 16

  38.         %VT.Cursor.Position:#y#;#x#=18;1%
  39.         %VT.CharacterSet.DEC%
  40.         For /L %%i in (0,1,36) Do Set /P=q< Nul
  41.         %VT.Cursor.Forward:#n#=1%
  42.         Set /P=信息< Nul
  43.         %VT.Cursor.Forward:#n#=1%
  44.         For /L %%i in (0,1,36) Do Set /P=q< Nul
  45.         %VT.CharacterSet.ASCII%

  46.         %VT.Cursor.Position:#y#;#x#=3;3%
  47.         Echo;批处理是一门简单的脚本语言,虽然不能独当一面,但是,若作为工作中的辅助工具,
  48.         %VT.Cursor.Position:#y#;#x#=4;3%
  49.         Echo;绝对会让大家有随用随写、称心如意的畅快感。
  50.         %VT.Cursor.Position:#y#;#x#=5;3%
  51.         Echo;和其他语言相比,批处理语言有其先天性的优势:
  52.         %VT.Cursor.Position:#y#;#x#=7;3%
  53.         Echo;1、系统自带,无需另行安装;
  54.         %VT.Cursor.Position:#y#;#x#=8;3%
  55.         Echo;2、命令少,语句简洁,上手非常快;
  56.         %VT.Cursor.Position:#y#;#x#=9;3%
  57.         Echo;3、编写出来的脚本小巧玲珑,随写随用;
  58.         %VT.Cursor.Position:#y#;#x#=10;3%
  59.         Echo;……
  60.        
  61.         %VT.Formatting.BackgroundRGB:#r#;#g#;#b#=250;250;250%

  62.         %VT.Cursor.Position:#y#;#x#=12;3%
  63.         Echo;%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=204;204;204%1%VTInline.CharacterSet.DEC%x%VTInline.CharacterSet.ASCII%^
  64. %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=56;58;66%@%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=197;132;1%echo %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=56;58;66%off^
  65. %VTInline.Text.EraseCharacter:#n#=65%

  66.         %VT.Cursor.Position:#y#;#x#=13;3%
  67.         Echo;%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=204;204;204%2%VTInline.CharacterSet.DEC%x%VTInline.CharacterSet.ASCII%^
  68. %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=197;132;1%set %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=56;58;66%str=c d e f g h i j k l m n o p q r s t u v w x y z^
  69. %VTInline.Text.EraseCharacter:#n#=19%

  70.         %VT.Cursor.Position:#y#;#x#=14;3%
  71.         Echo;%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=204;204;204%3%VTInline.CharacterSet.DEC%x%VTInline.CharacterSet.ASCII%^
  72. %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=197;132;1%echo %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=56;58;66%当前硬盘的分区有:^
  73. %VTInline.Text.EraseCharacter:#n#=51%

  74.         %VT.Cursor.Position:#y#;#x#=15;3%
  75.         Echo;%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=204;204;204%4%VTInline.CharacterSet.DEC%x%VTInline.CharacterSet.ASCII%^
  76. %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=166;38;164%for %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=152;104;1%%%%%i ^
  77. %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=166;38;164%in %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=56;58;66%(%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=152;104;1%%%str%%%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=56;58;66%) ^
  78. %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=166;38;164%do if exist %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=152;104;1%%%%%i%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=56;58;66%: ^
  79. %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=197;132;1%echo %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=152;104;1%%%%%i: ^
  80. %VTInline.Text.EraseCharacter:#n#=28%

  81.         %VT.Cursor.Position:#y#;#x#=16;3%
  82.         Echo;%VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=204;204;204%5%VTInline.CharacterSet.DEC%x%VTInline.CharacterSet.ASCII%^
  83. %VTInline.Formatting.ForegroundRGB:#r#;#g#;#b#=197;132;1%pause^
  84. %VTInline.Text.EraseCharacter:#n#=69%

  85.         %VT.SetScrollingRegion:#t#;#b#=19;24%

  86.         %VT.TextCursor.EnableModeShow%
  87.         %VT.TextCursor.BlinkingBlock%

  88.         %VT.Cursor.Position:#y#;#x#=19;1%
  89.         %VT.Formatting.Background:#n#=!VT.Colors.Blue!%
  90.         %VT.Formatting.BrightForeground:#n#=!VT.Colors.White!%
  91.        
  92.         For /L %%i in (0,0,1) Do (
  93.                 Echo;当Windows为我们打开了五彩缤纷的图形窗口的时候
  94.                 TimeOut /T 1 > Nul
  95.                 Echo;DOS命中注定会陨落
  96.                 TimeOut /T 1 > Nul
  97.                 Echo;CMD毫无悬念将萎缩
  98.                 TimeOut /T 1 > Nul
  99.                 Echo;批处理逐渐趋向无声无息
  100.                 TimeOut /T 1 > Nul
  101.                 Echo;而powershell的到来,无疑会让更多的人忘记批处理
  102.                 TimeOut /T 1 > Nul
  103.                 Echo;这是一门即将失传的技艺
  104.                 TimeOut /T 1 > Nul
  105.                 Echo;这是一块行将就木的领域
  106.                 TimeOut /T 1 > Nul
  107.                 Echo;然而,命令行工具仍然具有批量处理一切的巨大威力
  108.                 TimeOut /T 1 > Nul
  109.                 Echo;字符界面仍然是高效操作的代名词
  110.                 TimeOut /T 1 > Nul
  111.                 Echo;曾为批处理的方便灵活而击节赞赏
  112.                 TimeOut /T 1 > Nul
  113.                 Echo;曾被批处理的简洁快速深深折服
  114.                 TimeOut /T 1 > Nul
  115.                 Echo;一直以来,总想为批处理的推广做些什么
  116.                 TimeOut /T 1 > Nul
  117.                 Echo;……
  118.                 TimeOut /T 1 > Nul
  119.                 Echo;只是,年年岁岁花相似,岁岁年年人不同
  120.                 Echo;…………
  121.                 TimeOut /T 1 > Nul
  122.                 Echo;
  123.                 TimeOut /T 1 > Nul
  124.                 Echo;
  125.                 TimeOut /T 1 > Nul
  126.         )

  127.         Pause > Nul
  128. Goto :Main

  129. :Rect <X> <Y> <Width> <Height>

  130.         SetLocal EnableExtensions EnableDelayedExpansion

  131.                 Set /A"X=%1"
  132.                 Set /A"Y=%2"
  133.                 Set /A"Width=%3"
  134.                 Set /A"Height=%4"
  135.                 Set /A"Right=%X%+%Width%-1"
  136.                 Set /A"Bottom=%Y%+%Height%-1"

  137.                 %VT.CharacterSet.DEC%

  138.                 %VT.Cursor.Position:#y#;#x#=!Y!;!X!%
  139.                 %VT.Cursor.Forward:#n#=1%

  140.                 For /L %%i in (3,1,%Width%) Do (
  141.                         Set /P=q< Nul
  142.                 )

  143.                 %VT.Cursor.Position:#y#;#x#=!Bottom!;!X!%
  144.                 %VT.Cursor.Forward:#n#=1%

  145.                 For /L %%i in (3,1,%Width%) Do (
  146.                         Set /P=q< Nul
  147.                 )

  148.                 %VT.Cursor.Position:#y#;#x#=!Y!;!X!%
  149.                 %VT.Cursor.Down:#n#=1%

  150.                 For /L %%i in (3,1,%Height%) Do (
  151.                         Set /P=x< Nul
  152.                         %VT.Cursor.Backward:#n#=1%
  153.                         %VT.Cursor.Down:#n#=1%
  154.                 )

  155.                 %VT.Cursor.Position:#y#;#x#=!Y!;!Right!%
  156.                 %VT.Cursor.Down:#n#=1%

  157.                 For /L %%i in (3,1,%Height%) Do (
  158.                         Set /P=x< Nul
  159.                         %VT.Cursor.Backward:#n#=1%
  160.                         %VT.Cursor.Down:#n#=1%
  161.                 )

  162.                 %VT.Cursor.Position:#y#;#x#=!Y!;!X!%
  163.                 Set /P=l< Nul

  164.                 %VT.Cursor.Position:#y#;#x#=!Y!;!Right!%
  165.                 Set /P=k< Nul

  166.                 %VT.Cursor.Position:#y#;#x#=!Bottom!;!X!%
  167.                 Set /P=m< Nul

  168.                 %VT.Cursor.Position:#y#;#x#=!Bottom!;!Right!%
  169.                 Set /P=j< Nul

  170.                 %VT.CharacterSet.ASCII%

  171.         EndLocal

  172. Goto :Eof
复制代码
发表于 2025-2-23 08:29:54 | 显示全部楼层
谢谢楼主分享强帖,我要学习一下

我经常在批处理中使用的是 字符颜色,清除指定行的内容,光标移动,过渡色进度条 等等
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 12:19 , Processed in 0.022687 second(s), 9 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表