每行批次颜色 [英] Batch Color per line

查看:24
本文介绍了每行批次颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

批量处理时,每行可以有不同的颜色吗?例如,如果你有一个批处理文件说你好"你好吗?"

In batch, can you have different colors per line. For example if you had a batch file say "Hello" "How are you?"

你能不能用蓝色的你好"和绿色的你好吗"?

Could you have "Hello" in blue and "How are you" in green?

(我知道颜色命令,以及它为背景和文本着色的方式)

(I know about the color command, and the way it colors both the background and the text)

推荐答案

无需任何外部程序即可完成.这是我几天前过来的东西.效果很好.

You can do it without any external program. Here is something that I came over a couple of days ago. Works very good.

@echo off
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"
)
echo say the name of the colors, don't read

call :ColorText 0a "blue"
call :ColorText 0C "green"
call :ColorText 0b "red"
echo(
call :ColorText 19 "yellow"
call :ColorText 2F "black"
call :ColorText 4e "white"

goto :eof

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

Credits to jeb
His post can be found here

这篇关于每行批次颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆