I'm playing around with the new (limited) support for VT-100 escape sequences within the Windows 10 console. The supported sequences are documented at https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx.
I'm using batch files to test out the features, and I am able to get almost all of the documented features to work. But I am having trouble with the "Viewport Positioning" sequences (scroll up/down) - In my hands they are totally disfunctional (no effect)
ESC[<n>S - Scroll Up <n> lines
ESC[<n>T - Scroll Down <n> lines
Can anyone get them to work under any circumstances, or is the MS documentation simply wrong?
Also, there are standard inquiry sequences that MicroSoft has not documented, but appear to work.
In particular, the following sequence that reports the current cursor position interests me.
ESC[6n - responds with ESC[<n>;<m>R,
where <n> is the row number, and <m> the column number
The response is passed off as keyboard input, and appears on the screen, but I have no idea how to programmatically make use of the information. Ideally I would like to get the <n>
and <m>
values into environment variables from within a batch file.
But if anyone can demonstrate how to capture the variables using any language, then I may be able to use that knowledge to develop an effective batch file strategy.
I can get close with the following simple script called ANSI.BAT
@echo off
setlocal enableDelayedExpansion
for /f "delims=" %%C in (
'forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x1B"'
) do set "esc=%%C"
set "csi=%esc%["
echo(Inquiry:%csi%6n
set /p "pos="
echo response=!pos:%esc%=ESC!
--OUTPUT--
C:\test>ansi
Inquiry:
^[[3;9R
response=ESC[3;9R
C:\test>
I can easily parse out the values using FOR /F, once I have the response in a variable. The problem I am having is I must manually press the <Enter>
key after the response appears on the screen in order to terminate the input for my SET /P statement. I am stumped on where to go from here...
EDIT - One last requirement: I don't want the inquiry response to appear on the screen, as that disrupts the screen, and changes the cursor position. I suspect this may be the toughest nut to crack, perhaps impossible with pure batch.
I have NOT Windows 10, so I can't complete any test. However, if the response of the Ansi
ESC[6n
sequence is fill the keyboard input buffer withESC[<n>;<m>R
characters, then it is just necessary to add an Enter key to such input in order to read it viaSET /P
command, and this can be done via SendKeys JScript method.I also used a simpler method to get an ESC character in a variable.
EDIT: I modified the code accordingly to comments...
Please, post the result...
I can't test it, I don't want W10.
But I suppose, that it works as
SET /P
also works.It collects the characters with the
xcopy /W
trick and stops at the firstR
EDIT: Currently it fails
This seems to be a problem of the
XCOPY
.I suppose, that
XCOPY
read one character from the input buffer and then it clears the input buffer.