#1 06 Jan 2019 13:17

sjf2
Member
Registered: 06 Jan 2019
Posts: 2

Tailoring the "CHOICE" command's message with indents

I am using Windows 10 and trying to create a .cmd script that has screen output that is indented.  I use "echo" commands with leading TABs to accomplish the indented layout but I am having trouble trying to get my "prompts" to indent.  I am using the "CHOICE" command and no matter what I do, I cannot get the "message" string (using the "/m" option) to indent.  I have tried leading spaces, leading tabs, starting the message string with special characters such as NUL (octal 255) and every other character starting at octal 001.  With the exception of the BEL character (octal 007) which produces, what else, a bell sound.  In the cases of all of the non-displayable control characters (except the BEL), the choice command displays a special character which can be seen.  I have tried to quote the string, quote a character and also trying to escape whitespace characters using "^".  I have put the string and/or a leading character in variables with no luck.  I have tried using ASCII escape character strings to preface the string with ANSI color control character and that doesn't work either.  BTW: I hope that there is a way to get those to work too.  The ONLY way it seems to work is if there is a visible character in the beginning of the message string which leaves that character on the prompt line in column 1.  I believe that I have tried everything but I am hoping that someone here has figured out some way to do this.  Thank you for any help!

Offline

#2 06 Jan 2019 20:45

Aacini
Member
Registered: 05 Dec 2012
Posts: 144

Re: Tailoring the "CHOICE" command's message with indents

@echo off
setlocal

for /F %%a in ('echo prompt $H ^| cmd') do set "BS=%%a"
choice /M ".%BS%              Your selection"

Tested on Windows 8.1

Last edited by Aacini (06 Jan 2019 20:49)

Offline

#3 08 Jan 2019 13:30

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,084

Re: Tailoring the "CHOICE" command's message with indents

"set /p" has been similarly afflicted since, I think, around about the time of Win7/2008 (maybe even Vista, but I never used that in anger).  I'm guessing that they are using the same underlying call.

Aacini's backspace workaround was the best I could muster as well.  I say "workaround", for it has a caveat: if you are capturing the output for some reason, the backspace will be present in the capture.


cmd | *sh | Ruby | Chef

Offline

Board footer

Powered by FluxBB