我想制作一个以彩虹风格输出艺术品的批处理文件。
我使用此代码作为基础:https://gist.github.com/ChanSec/10519942
我在某个地方读到了我可以通过输入.txt文件输出艺术品(但我不想要更多文件),所以我来到这里:
:::Something
:::art stuff
:::More
for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do @echo(%%A
这是我的代码:http://pastebin.com/ZHw2QAXM
每次我启动时,它都会使整个屏幕变为垃圾,只显示红色(只有艺术品红色应该是红色,HELLO艺术应该换成颜色)
如何让它停止发送垃圾邮件(艺术应该只能看一次并切换颜色)并修复颜色?除此之外,还有一种简单的方法可以更改此行中的2:ping -n 2 127.0.0.1 > nul
我可以改变一个整数,所以我不必在每一行都改变它?我不熟悉批量编码。
答案 0 :(得分:1)
您可以尝试这样的事情:
@echo off
setlocal EnableDelayedExpansion
set "timeout=2"
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
:loop
FOR %%G IN (9,a,b,c,d,e) DO (
::[HELLO
::[WORLD
::]RED
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :ColorText 0%%G "%%A"
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :ColorText 0c "%%A"
ping -n !timeout! 127.0.0.1 > nul
)
goto loop
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
echo.
goto :eof
向NiklasJ致函this post,了解批次中每行的着色情况。 但请注意,您无法使用以下特殊字符
。 | ! %; :[])/ \&lt; &GT; %^ *? &#34;
在要显示的文字中。
这回显了:: [改变颜色后,以及::]之后的所有行都是红色。
修改强>
所以我再次尝试使用the code used by Jeb in this post,这次是更新版本。它仍然无法处理所有字符,但似乎这个仅限于无法处理
:/ \
@echo off
set "timeout=2"
setlocal EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
rem Prepare a file "X" with only one dot
:loop
FOR %%G IN (9,a,b,c,d,e) DO (
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :color 0%%G "%%A"
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :color 0c "%%A"
ping -n !timeout! 127.0.0.1 > nul
)
goto loop
exit /b
:color
<nul > X set /p ".=."
set "param=^%~2" !
set "param=!param:"=\"!"
findstr /p /A:%1 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
echo.
del /f /q X >nul 2>nul
exit /b
::[ _ _ _ _
::[ | | | | | | |
::[ | |__| |____| | | ___
::[ | __ | _ | | || _ |
::[ | | | | __| | | (_) |
::[ |_| |_|____|_|_||___|
::[
::] _____ _
::] | __ | | |
::] | |__) |___ __| |
::] | _ || _ || _` |
::] | | | | __| (_| |
::] |_| |_|___||__,_|
编辑#2 最后,在dbenham在this answer中尝试了一些其他代码后,似乎这是唯一真正支持你所有角色的版本,虽然它不像空行并且速度慢得多:
@echo off
setlocal EnableDelayedExpansion
set "timeout=2"
set q=^"
:loop
FOR %%G IN (9,a,b,c,d,e) DO (
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :c 0%%G "%%A" /n
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :c 0c "%%A" /n
ping -n !timeout! 127.0.0.1 > nul
)
goto loop
exit /b
:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:colorPrint Color Str [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b
:colorPrintVar Color StrVar [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^
^") do (
set "s=!s:\=%%~n\%%~n!"
set "s=!s:/=%%~n/%%~n!"
set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
if "!" equ "" setlocal disableDelayedExpansion
if %%s==\ (
findstr /a:%~1 "." "\'" nul
<nul set /p "=%DEL%%DEL%%DEL%"
) else if %%s==/ (
findstr /a:%~1 "." "/.\'" nul
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
) else (
>colorPrint.txt (echo %%s\..\')
findstr /a:%~1 /f:colorPrint.txt "."
<nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
)
)
if /i "%~3"=="/n" echo(
popd
exit /b
:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%temp%\'" set /p "=."
subst ': "%temp%" >nul
exit /b
:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b
::[ _ _ _ _
::[ | | | | | | |
::[ | |__| | ___| | | ___
::[ | __ |/ _ \ | |/ _ \
::[ | | | | __/ | | (_) |
::[ |_| |_|\___|_|_|\___/
::] _____ _
::] | __ \ | |
::] | |__) |___ __| |
::] | _ // _ \/ _` |
::] | | \ \ __/ (_| |
::] |_| \_\___|\__,_|