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
@echo off
if "%~1"=="intern" (
call %2
exit
)
start /b "" "%~f0" intern :thread2
:thread1
cls
echo Line1
call :wait
call :wait
call :Send 27
echo Line2
echo Line3
echo Line4
call :wait
call :Send 27
for /L %%n in ( 1 1 10) DO (
<nul set /p "=."
call :wait
)
call :Send 13
exit /b
:thread2
call :wait
set /p var=
rem Thread2 ends now
exit /b
:Send
cscript //E:JScript //nologo "%~f0" %1
exit /b
:wait
ping localhost -n 2 > nul
exit /b 0
//
***jscript part****/
var WshShell = WScript.CreateObject("WScript.Shell");
var args=WScript.Arguments;
WshShell.SendKeys(String.fromCharCode(args.Item(0)));
jeb