gpt4 book ai didi

batch-file - 批处理 - 用户输入的颜色

转载 作者:行者123 更新时间:2023-12-03 16:43:24 26 4
gpt4 key购买 nike

您好,我正在制作一个可以从文件夹启动程序的程序。代码如下:

@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"
)
title Launcher
call :ColorText 0a "Launcher"
echo.
:CMD
set /p cmd=">>> "
if not defined cmd goto CMD
call "%CD%"\bin\%cmd%
echo %cmd%>"%CD%\Commands_Log\%cmd%
goto CMD
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

我真的很想知道如何为用户的输入着色。例如我的提示是这样的

C:\ > abcd

现在,我如何只为“abcd”部分着色??

编辑:我希望它在输入时被着色。这是我对所有不理解的人的原始问题。

最佳答案

作为 Pickle 教授的评论,您需要编写自己的键输入,然后用颜色输出每个键。

可以使用 Findstr 进行批量着色 how to have multiple colors in a batch file?
获取单个 Key 可以通过 xcopy 完成。

@echo off
call :color_init
setlocal EnableDelayedExpansion

:keyLoop
call :GetKey
if not defined key exit /b
call :color 1a key
goto :keyLoop


:GetKey
set "key="
for /F "usebackq delims=" %%L in (`xcopy /L /w "%~f0" "%~f0" 2^>NUL`) do (
if not defined key set "key=%%L"
)
set "key=%key:~-1%"
exit /b

:color_init
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
<nul > X set /p ".=."
exit /b

:color
setlocal EnableDelayedExpansion
set "param=!%~2!"
set "param=!param:"=\"!"
findstr /p /A:%1 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
endlocal
exit /b

for /f "delims=" %%A in ('echo hello') do set "var=%%A"
echo %var%
exit /b

关于batch-file - 批处理 - 用户输入的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15140980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com