这是我的一些批处理加载脚本
\n\nEcho Loading\nEcho \xc3\x89\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc2\xbb\nEcho \xc2\xba\xc3\x9b \xc2\xba\nEcho \xc3\x88\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc2\xbc\nping localhost -n 2 > nul\ncls\nEcho Loading\nEcho \xc3\x89\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc2\xbb\nEcho \xc2\xba\xc3\x9b\xc3\x9b \xc2\xba\nEcho \xc3\x88\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc2\xbc\nping localhost -n 2 > nul\ncls\nEcho Loading\nEcho \xc3\x89\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc2\xbb\nEcho \xc2\xba\xc3\x9b\xc3\x9b\xc3\x9b \xc2\xba\nEcho \xc3\x88\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc3\x8d\xc2\xbc\nexit\nRun Code Online (Sandbox Code Playgroud)\n\n使用cls代码擦除屏幕使屏幕看起来像“闪烁”。有没有更好的方法来清除该批处理文件的屏幕?TIA
远非完美的少故障选项:不是重新绘制全屏,而是仅重新绘制加载线(但这必须是屏幕中最后绘制的线)。
基本思想是输出以回车符结尾但没有换行符的行,因此光标移动到行的开头以在同一行上再次写入。
@echo off
setlocal enableextensions enabledelayedexpansion
Rem Get a carriage return character
set "CR=" & for /f %%a in ('copy /Z "%~f0" nul') do if not defined CR set "CR=%%a"
rem The progress bar
set "fill=[##########]"
cls
echo(:: computers were created to give humans time to think while waiting ....
rem For each character in the fill
for /l %%a in (2 1 11) do (
rem Calculate the right part of the bar
set "spaces=!fill:~%%a!"
rem Output the left and right parts of the bar and carriage return
<nul set/p ".=:: Loading something big !fill:~0,%%a!!spaces:#= !!CR!"
rem Pause for a second
ping -n 2 "" > nul
)
echo(
echo(:: Done
Run Code Online (Sandbox Code Playgroud)
如果您无法更改代码/设计,因此最后一行是唯一重新绘制的行,至少尝试将绘制操作包含在一个块内(括号中的代码),以便在每个绘制操作命令中仅解析一次,并准备好所有内容在开始绘画之前。它不会避免故障,但会不太明显
@echo off
setlocal enableextensions enabledelayedexpansion
for /l %%a in (0 10 100) do (
call :loadingScreen %%a
>nul ping -n 2 ""
)
echo(:: Done
goto :eof
:loadingScreen percent
setlocal enableextensions enabledelayedexpansion
rem Prepare everything
set "sb=+----------+"
set "fill=^|##########^|"
set "eb=+----------+"
set /a "chars=2+%~1/10"
set "spaces=!fill:~%chars%!"
set "loadBar=!fill:~0,%chars%!!spaces:#= !"
rem Time to paint
( cls
echo(:: computers were created to give humans time to think while waiting .... %time%
echo(
echo( %sb%
echo( Loading something big %loadBar%
echo( %eb%
echo(
)
goto :eof
Run Code Online (Sandbox Code Playgroud)