Home > Mobile >  How can i set the color of a batch/cmd to 00?
How can i set the color of a batch/cmd to 00?

Time:06-18

I'm currently writing a batch program where I am trying to preserve the spaces of a "/p" but it wont accept them for some reason. the work around I thought would help was setting a variable "buffer" to " " and then putting as many as I needed, ex: %buffer%%buffer%. but that didn't work either. so then I set the buffer=- and tried to make the "-" color 00 (or black text on black background) but it doesn't accept this as a valid color code. is there any way to have black text on black background or otherwise preserve those spaces? thank you in advance, btw sorry if this post isn't properly set up, this is my first post. thank you again.

CodePudding user response:

Always best to state clearly what you want to do, then show how you've attempted to do that thing.

I gather that what you want to do is have the cursor indented when set /p accepts a user-input, since

set /p "fred=    "
set /p "fred=    ^>"

or any other such prompt suppresses the leading spaces.

Provided you are using a decent text editor (I use editplus) then you can insert a backspace character (control-h) as the first character after the =. Your "leading" spaces will then appear.

CodePudding user response:

Assuming windows 10, which supports VT-100 escape sequences:

@echo off
for /F %%a in ('echo prompt $E ^| cmd') do set "cl=%%a" & cls
set "need=Question%cl%[08m.         %cl%[0m>"
set /p "request=%need%"
echo %request%

Note, the trailing > is purely to show you where the cursor starts, you can remove or replace it if you want.

  • Related