Search code examples
textinputbatch-filesetvisible

Batch Show a text or a line under a set


This is something that i searched for very long and never even found another that asked the same ! Is it possible to have a variable input with text under it ! Because, in the code, the text beneath is shown only on ending of the input. Basicly, i'd like to make a thing like this :
######################
INPUT (the set /p cmd)
######################

The thing i want is to make the line under the set command visible


Solution

  • No!

    It's not possible with pure batch.

    There is a simple reason,
    as there is no way to go up with the cursor, it's only possible to go back in the same line (with the CR or BACKSPACE characters).

    Only CLS can bring the cursor up, but then the screen is empty again.

    I know two commands with the possibility to go lines up, but I don't know a way to use them from a batch file.
    set and cmd in a double threaded command window.

    @echo off
    if "%~1"=="intern" (
        prompt %2$G
        call %2
        exit
    )
    start /b "" "%~f0" intern :thread2
    
    :thread1
    prompt :thread1$G
    call :cls
    echo Use ESC to go up lines
    for /L %%n in (1 1 10) DO (
      ping localhost -n 2 > nul
      echo( %%n
    )
    exit /b
    
    :thread2
    set /p var=Press ESC ... NOW!
    exit /b
    

    But there exists many external tools to set the cursor position (CursorPos.exe from Aacini)