我如何做一个批处理的一个特定行提交不同势色那么其他人呢? [英] How do I make one particular line of a batch file a diffrent color then the others?

查看:684
本文介绍了我如何做一个批处理的一个特定行提交不同势色那么其他人呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成当天的天气为D&放大器方案;三维游戏。我想,当产生风暴让DM知道,这种天气不典型程序在红色文字显示警告。为了减少击键次数,就必须这样做,在同一屏幕上的文字详细介绍了天气本身。

I'm working on a program which generates the day's weather for D&D games. I want the program to display a warning in red text when a storm is generated so the DM is aware that this weather is not typical. To reduce the number of keystrokes, it must do this on the same screen as the text detailing the weather itself.

目前的风暴进入我有这样的:

Currently for a storm's entry I have this:

:des4a
cls
type c:\AutoDM\WeatherGen\data\forcast1.txt
color 0c
echo     There is an Ashstorm!
color 0a
echo.
echo     It is %temp% degrees and the sky is invisible threw the thick 
echo     billowing clouds of ash.
echo.
echo         # Survival checks to light a fire are at +15. 
echo         # Small unprotected flames will be snuffed out.
echo         # Non-firearm ranged attacks are at a -8 to hit.
echo         # Preception checks take a -10 for every 10 feet of distance.
echo         # Survival checks to get along in the wild are at +15.
echo         # Stealth checks are at a +5.
echo.
echo     SPECIAL!
echo.
set /a die=6
set /a inches=%random%%%die+1
echo         # The ashstorm will deposit %inches% inches of ash durring its
echo           durration.
echo         # Tracking a target after an ashstorm is at a +15.
type c:\AutoDM\WeatherGen\data\forcast2.txt
echo.
echo.
pause
goto menu

类型命令调用包含页眉和页脚每个条目,以帮助该方案看上去很专业,并提供一个边界,以协助自动换行的文本文档。你无法删除。不建议什么令我无法为当前状态,请使用该类型的命令。请理解这红色的文本行会被添加到了很多程序的不同部分,每次有每个风暴,并在发电机的每个生物群落。我想preFER它不是更多的则只有2或3 code线(但如果只有一个办法把它做好...)

The type commands are calling text documents which contain a header and footer for each entry to help the program look professional and provide a border to assist with word wrap. Thy cannot be removed. DO not suggest something which would make me unable to use the type commands as they currently exist please. Please understand that this red text line will be added to a lot of different parts of the program, each time there is a storm for each and every biome in the generator. I would prefer it to not be more then just 2 or 3 lines of code (But if there is only one way to do it well...)

我可以有红色一行,并在绿色的休息吗?或者我应该有计划蜂鸣提醒人们注意这个事实?你有一个更好更简单的主意吗?我该怎么做呢?

Can I have the one line in red and the rest in green? Or should I have the program beep to call attention to the fact? Do you have a better and simpler idea? How do I do this?

推荐答案

昨天我有同样的问题,我做了一些研究和的这个的为我工作。
编辑:这是不会在同一code作为另一个

I was having the same problem yesterday, I did some research and this worked for me. This is NOT the same code as the other one.

@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"
)
call :colorEcho 0a "This is colored green with a black background!"
echo.
call :colorEcho a0 "This is colored black with a green background!"
echo.
pause
exit
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i

它这样做:

it does this:

所有你需要做的,以适应这把部分从 SETLOCAL EnableDel ...到来您code的开始(如果你的code。与@echo开始了,然后把它放在了),并把部分来自:colorEcho 德尔%〜2 在你的脚本的确切底部(的 NOTHING UNDERNEATH!的)

All you need to do to fit this is put the part from SETLOCAL EnableDel... to ) to the beginning of your code (If your code starts with @echo off then put it under that) and also put the part from :colorEcho to del %~2 at the exact bottom of your script (NOTHING UNDERNEATH!)

现在的你注意到

call :colorEcho 0a "This is colored green with a black background!"
echo.
call :colorEcho a0 "This is colored black with a green background!"
echo.
pause
exit

一行行的解释:
第一行(电话:colorEcho 0A!这是绿色与黑色背景):这是一个有色回声,它令人惊讶说这是绿色与黑色背景! 0A (黑BG,绿色文本)
第二行(回声。)打印一个换行符,因为我们的色回声不打印之一。

Explained line by line: First line (call :colorEcho 0a "This is colored green with a black background!"): This is a colored echo, it suprisingly says This is colored green with a black background! in 0a (Black Bg, Green Text) Second line (echo.) prints a newline, since our colored echo doesn't print one.

SO

让我们说你想说的Hello World,在您好是黄色和全球是绿色。
实例!

Let's say you wanted to say "Hello World" in Hello being yellow and World being green. Example!

@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"
)
call :colorEcho 0e "Hello "
call :colorEcho 0a " World"
pause
exit
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i

这是它做什么:

我希望这是可以理解的!

This is what it does: I hope this is understandable!

编辑:确保程序退出的IT能达到之前:colorEcho

Make sure the program exits before it could reach :colorEcho

这篇关于我如何做一个批处理的一个特定行提交不同势色那么其他人呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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