我想制作一个cmd,显示一些事情的过程:
这就是窗口的样子:
-----------
| TESTING | <-- This text is in green, but background of this part is in black
-----------
Process ... 1% <-- This text is in white
我希望我可以让Process ... 1%
行每0.1秒更新一次Process ... (%percentage%+1)%
。
我知道我可以这样做:
@echo off
:loop
echo -----------
echo | TESTING |
echo -----------
echo.
echo Process ... %percentage%^%
echo.
if %percentage%<100% (
timeout /t 0.1 /nobreak >nul
goto loop
) else (
goto end
)
:end
echo -----------
echo | TESTING |
echo -----------
echo.
echo END!
SO ,问题是:
1. timeout /t 0.1 /nobreak
不起作用,因为timeout /t
必须是整数;
2.我想要的颜色无法改变
我可以用其他编程语言吗? 任何帮助将不胜感激。谢谢!
答案 0 :(得分:1)
关于着色部分 - 您可以尝试使用cmdcolor。在您的情况下,它将如下:
echo \033[92m
echo -----------
echo | TESTING |
echo -----------
echo \033[0m
答案 1 :(得分:0)
试试这个延迟。调整1000以调整延迟以适合您,但在更快或更慢的机器上它会有所改变。
for /L %%a in (1,1,1000) do rem
除color
关键字外,cmd的颜色相当有限,但此批处理文件演示了一些颜色的使用。
第三方工具还可以让您为屏幕着色。
@Echo Off
Call :Color A "######" \n E "" C " 21 " E "!" \n B "######" \n
Pause >Nul
Exit /B
:Color
:: v21
:: Arguments: hexColor text [\n] ...
:: \n -> newline ... -> repeat
:: Supported in windows XP, 7, 8.
:: In XP extended ascii characters are printed as dots.
:: For print quotes, use empty text.
SetLocal EnableExtensions EnableDelayedExpansion
Subst `: "!Temp!" >Nul &`: &Cd \
SetLocal DisableDelayedExpansion
If Not Exist `.7 (
Echo(|(Pause >Nul &Findstr "^" >`)
Set /P "=." >>` <Nul
For /F "delims=;" %%# In (
'"Prompt $H;&For %%_ In (_) Do Rem"') Do (
Set /P "=%%#%%#%%#" <Nul >`.3
Set /P "=%%#%%#%%#%%#%%#" <Nul >`.5
Set /P "=%%#%%#%%#%%#%%#%%#%%#" <Nul >`.7))
:__Color
Set "Text=%~2"
If Not Defined Text (Set Text=^")
SetLocal EnableDelayedExpansion
Set /P "LF=" <` &Set "LF=!LF:~0,1!"
For %%# in ("!LF!") Do For %%_ In (
\ / :) Do Set "Text=!Text:%%_=%%~#%%_%%~#!"
For /F delims^=^ eol^= %%# in ("!Text!") Do (
If #==#! EndLocal
If \==%%# (Findstr /A:%~1 . \` Nul
Type `.3) Else If /==%%# (Findstr /A:%~1 . /.\` Nul
Type `.5) Else (Echo %%#\..\`>`.dat
Findstr /F:`.dat /A:%~1 .
Type `.7))
If "\n"=="%~3" (Shift
Echo()
Shift
Shift
If ""=="%~1" Goto :Eof
Goto :__Color