How to place the cursor
Posted: 11 Dec 2010 16:03
Hi,
OK, I know the standard answer: It is not possible with pure batch.
But some minor things are possible and well known.
Like echoing into the same line with the set /p trick
Then there is the possiblity to delete the text with the <DEL> character,
or to jump with the <CR> to the beginning of the line.
And you can create them with pure batch, without editor-tricks.
<DEL>
or
<CR>
But all these solutions have one problem, you can not move up the cursor even a single line.
Now I found a way to solve this, I tested it with XP and Vista
How it works:
I start a second cmd.exe-task in the same window (start /b), you can exit one of them, the other will stay open.
In my batch the second cmd.exe-task shows directly the prompt.
I suppose, that the ESC triggers the doskey functionality of the second cmd-task, and it place the cursor and mark the position internally.
To retrieve this internally mark you have to press the ESC-Key again.
And that's the obvious problem of the solution.
The user has to press the ESC-Key, I want to controll it by the batch file itself.
I hope one of the experts (like aGerman, amel, k!, avery_larry, DosItHelp etc .... ) have a good idea.
jeb
OK, I know the standard answer: It is not possible with pure batch.
But some minor things are possible and well known.
Like echoing into the same line with the set /p trick
Code: Select all
<nul set /p ".=This echos without CR-LF at the end
<nul set /p ".=...This text is appended in the same line
Then there is the possiblity to delete the text with the <DEL> character,
or to jump with the <CR> to the beginning of the line.
And you can create them with pure batch, without editor-tricks.
<DEL>
Code: Select all
<nul set /p ".=The progress is 50%%"
<nul set /p ".=#!DEL!!DEL!!DEL!!DEL!60%%"
or
<CR>
Code: Select all
<nul set /p ".=The progress is 50%%"
<nul set /p ".=#!CR!The progress is 60%%"
But all these solutions have one problem, you can not move up the cursor even a single line.
Now I found a way to solve this, I tested it with XP and Vista
Code: Select all
@echo off
cls
prompt Main$G
< nul set /p =Press ESC if you see the text "sec"
start /b cmd /k prompt sec$G
ping -n 4 localhost > nul
echo line1
echo line2
echo line3
echo line4
echo line5
echo Press ESC again
exit
How it works:
I start a second cmd.exe-task in the same window (start /b), you can exit one of them, the other will stay open.
In my batch the second cmd.exe-task shows directly the prompt.
I suppose, that the ESC triggers the doskey functionality of the second cmd-task, and it place the cursor and mark the position internally.
To retrieve this internally mark you have to press the ESC-Key again.
And that's the obvious problem of the solution.
The user has to press the ESC-Key, I want to controll it by the batch file itself.
I hope one of the experts (like aGerman, amel, k!, avery_larry, DosItHelp etc .... ) have a good idea.
jeb