在批处理中,我将如何撤消某些事情?

时间:2014-10-09 01:03:01

标签: batch-file syntax colors

我正在玩批处理,我试图做一点有趣的东西。我有几个问题:

当处于:backcol或:textcol时,当我改变文本或背景的颜色做不同的颜色,然后回答n / N到:keepbc或:keeptc,我怎样才能使颜色恢复到原来的样子在我改变颜色之前,回到相应的:backcol /:textcol?例如:

背景 通过以下方式将背景从黑色变为蓝色:backcol - > :keepbc;但后来要把它改成不同的颜色,比如红色,但不是说y / Y in:keepbc,当我说n / N时,它会将背景颜色改回蓝色,然后返回:backcol。

文字 通过以下方式将文本从绿色(默认)更改为蓝色 - textcol - > :keeptc;但后来要把它改成不同的颜色,比如红色,但不是说y / Y in:keeptc,当我说n / N时,它会将文字颜色改回蓝色,然后返回:textcol。

另一个问题是如果我将背景颜色更改为蓝色,然后更改文本颜色,我如何才能将背景颜色更改为黑色?当改变背景的颜色,或只是文本时,我需要有两个字符吗? (02,4F;那样)

任何想法?谢谢!因为我是新的如果你看错了别的什么,请帮助我! :d

并忽略:premade!还没完呢!

:start
@echo off
color 02

:main
@echo off
if color==01 color 01
if color==03 color 03
if color==04 color 04
if color==02 color 02
title Tool Help
echo What would you like to do?
echo 1.Hide/Show
echo 2.Settings
echo 3.Exit
set /p ans=
if %ans%==1 GOTO folderhider
if %ans%==2 GOTO settings
if %ans%==3 EXIT /b

:settings
echo Please select and option.
echo 1.Colors
echo 2.Return to main
set /p opt=
if %opt%==1 GOTO coloro
if %opt%==2 GOTO main

:coloro
@echo off
echo 1.Background
echo 2.Text
echo 3.Nice pre-made schemes
set opt=
set /p opt=
if %opt%==1 GOTO backcol
if %opt%==2 GOTO textcol
if %opt%==3 GOTO premade

:backcol
echo 1.Green
echo 2.Blue
echo 3.Aqua
echo 4.Red
echo 5.Cancel
set input=
set /p input=
if %input%==1 color 20
if %input%==2 color 10
if %input%==3 color 30
if %input%==4 color 40
if %input%==5 GOTO settings
GOTO keepbc


:premade


:textcol
echo Select a color.
echo 1.Green
echo 2.Blue
echo 3.Aqua
echo 4.Red
echo 5.Cancel
set input=
set /p input=
if %input%==1 color 02
if %input%==2 color 01
if %input%==3 color 03
if %input%==4 color 04
if %input%==5 GOTO settings
GOTO keeptc

:keeptc
echo Would you like to keep this setting? (Y/N)
set ans=
set /p ans=
if %ans%==y GOTO settings
if %ans%==Y GOTO settings
if %ans%==n GOTO textcol
if %ans%==N GOTO textcol
GOTO textcol

:keepbc
echo Would you like to keep this setting? (Y/N)
set ans=
set /p ans=
if %ans%==y GOTO settings
if %ans%==Y GOTO settings
if %ans%==n 
if %ans%==N color 02
GOTO backcol

:folderhider
@echo off
echo 1.Show
echo 2.Hide
echo 3.Return
set /p hj=
if %hj%==1 GOTO sh
if %hj%==2 GOTO hi
if %hj%==3 GOTO main
GOTO folderhider

:hi
set/p folderr=Please input the folder you want to hide. If none, type none. 
if "%folderr%"==%folderr% GOTO confirm
if "%folderr%"=="none" GOTO folderhider


:confirm
echo Are you sure you want to hide the folder(Y/N)
set/p "cho=>"
if %cho%==y GOTO hider
if %cho%==n GOTO hi
if %cho%==Y GOTO hider
if %cho%==N GOTO hi
:hider
attrib +r +h +s %folderr%
echo Folder\File Hiden: %folderr% >>Folderandfileshiden.txt
GOTO folderhider


:sh
set /p showern=Please input the folder you want to show 
if "%showern%"==%showern% GOTO unlock

:unlock
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%== Blutackk11 GOTO fail
if %pass%== Blutackk11 GOTO shower

:fail
echo Invalid pasword
GOTO unlock

if "%showern%"=="" GOTO folderhider

:shower
attrib -r -h -s %showern%
GOTO folderhider

1 个答案:

答案 0 :(得分:0)

撤消

要撤消颜色,您需要制作自己的功能,以存储最后使用的颜色。这是一个示例文件,它接收您想要的颜色值。要撤消到最后一种颜色,只需输入/

@echo off
set oldcolor=
set newcolor=

:loop
set /p "var=: "
if "%var%"=="/" ( call :undo ) else ( call :col %var% )
goto :loop

:col
:: Store the last color used incase you want to undo
set oldcolor=%newcolor%
set newcolor=%1
color %1
goto :eof

:undo
:: Use the oldcolor variable to undo
color %oldcolor%
goto :eof

所以要在你的代码中实现它:

:start
@echo off
color 02

:main
@echo off  
......................
:shower
attrib -r -h -s %showern%
GOTO folderhider

:: Below is added at the end of your code
:col
set oldcolor=%newcolor%
set newcolor=%1
color %1
goto :eof
:undo
color %oldcolor%
goto :eof

替换代码中的每个颜色命令
call :col [Color to change to]

简单撤消

call :undo