Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm making a domain resolver, and I don't like the way the text is at the window border. The line is set /p domainname=Enter Domain Name^> %ESC%[92m

I would like to add a space before where it says Enter Domain Name>

This is what it looks like

This is what it looks like

so it's not stuck right against the window border, which would make it look a bit nicer. How would I go about this? I haven't been able to find anything on how to solve this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
740 views
Welcome To Ask or Share your Answers For Others

1 Answer

As an alternative, you can use the prompt technique to display any text message (up to 511 characters long) without worrying about the leading white space characters.

It works as follows:

set "prompt=Your text message"
cmd /d /k <nul
set /p "myVar="

putting it in to a reusable function:

@echo off
setlocal EnableExtensions

call :getInput domainname " Enter Domain Name > %ESC%[92m"

echo domainname is [%domainname%]
pause
exit /b

:getInput <inputVar> ["Message String"]
setlocal DisableDelayedExpansion
set "Msg=%~2"
if defined Msg (
    REM For prompt strings, $ is an escape character so it should be escaped with another one.
    set "prompt=%Msg:$=$$%"
    "%COMSPEC%" /d /k <nul
)
endlocal
set /p "%~1="
exit /b

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...