I played long time with cursor movement, I'm able to use the backspace or also the CR character to move the cursor back in a line.
I can also move the cursor up without clearing the screen, but until now I haven't found a good solution with pure batch.
Currently the solution needs an embedded jscript to use SendKeys, but it has many drawbacks, like that it uses a SET/P (or cmd/k is also possible) for key input.
That's a bit nasty for games like snake, as it blocks the user input.
Also it can be disturbed by the user with keypresses.
The key idea is to use the ability of SET/p (or cmd), that you can jump back the cursor to the beginning with pressing the ESC key.
Unfortunately I can't get it working with pipes or something else.
SET/P seems to disable any output, if the input comes from a stream or redirection.
CMD would work here, but I can't send any ESC over a pipe or redirection.
But perhaps somebody have a good idea to solve this old problem.
Here is a simple proof on concept
Code: Select all
@if (@X)==(@Y) @end /* Harmless hybrid line that begins a JScript comment
if "%~1"=="intern" (
start /b "" "%~f0" intern :thread2
call :Send 27
call :Send 27
for /L %%n in ( 1 1 10) DO (
<nul set /p "=."
call :Send 13
set /p var=
rem Thread2 ends now
cscript //E:JScript //nologo "%~f0" %1
ping localhost -n 2 > nul
exit /b 0
var WshShell = WScript.CreateObject("WScript.Shell");