批次 - 用户输入的颜色 [英] batch - color input by user

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

问题描述

喜IM做一个程序,从文件夹中启动程序。这里的code:

Hi im making a program that will launch a program from a folder. Here's the code:

@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

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

I really want to know how to color the user's input. For example my prompt goes like

C:\\> ABCD

C:\ > abcd

现在,我怎么颜色只有ABCD的一部分??

Now, how do I color only the "abcd" part??

编辑:我想因为它是被键入它着色。这是我为大家谁不明白原来的问题。

I want it to be colored as it is being typed. This was my original question for everyone who didn't understand.

推荐答案

由于味酸教授评论你需要编写自己的按键输入,然后再输出色彩的每个键。

As Prof Pickle comment you need to write your own key input, and then output each key with a color.

在批量着色可以做到与Findstr工具描述如何有多种颜色在一个批处理文件?结果
得到一个密钥可以用XCOPY来完成。

Coloring in batch can be done with Findstr described how to have multiple colors in a batch file?
Get a single Key can be done with 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

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

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