3

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

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

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

chetasmr
  • 68
  • 5
  • 1
    possible duplicate of [How to echo with different colors in the Windows command line](http://stackoverflow.com/questions/2048509/how-to-echo-with-different-colors-in-the-windows-command-line) – Vicky Feb 28 '13 at 17:14
  • There is no conventional method to do this, but you could put a choice command in that adds the letter they put in to a variable that is then displayed in a different color. I wouldn't recommend it though. – BDM Feb 28 '13 at 21:36
  • @Vicky It ain't a duplicate...here i want the input to be colored....ONLY the input.... – chetasmr Mar 01 '13 at 06:18

3 Answers3

7

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

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
Community
  • 1
  • 1
jeb
  • 78,592
  • 17
  • 171
  • 225
1

Yes, it is possible with cmdcolor. Just echo \033[93m right before the input, and then echo \033[0m afterwards. Everything typed in between those echoes will be in yellow.

Alec Mev
  • 4,663
  • 4
  • 30
  • 44
0

you can use a program called cecho.bat http://www.codeproject.com/Articles/17033/Add-Colors-to-Batch-Files

Panikosagros
  • 97
  • 1
  • 6