Page 1 of 1

Terminal Escape Sequence and next line position

Posted: 22 Sep 2021 13:21
by atfon
Like many of us, I have used the technique I have scene from Jeb and others to generate a new line using a carrot and two blank lines and this works great in an example like this:

Code: Select all

@echo off
setlocal enabledelayedexpansion
set LF=^


:: The two empty lines are required here
set "usbInfo="
for /f "skip=1 tokens=*" %%i in ('wmic path win32_pnpentity where "Present='True' AND PNPClass='USB'" get Name') do for /f "tokens=*" %%j in ("%%i") do (
set "usbInfo=!usbInfo!!LF!"
set "usbInfo=!usbInfo!%%j"
)
echo !usbInfo!>"%userprofile%\test.txt"
I was testing using the Terminal Escape sequence for the next line with ESC[E (https://docs.microsoft.com/en-us/window ... -sequences). This works great if I were to echo to the console:

Code: Select all

for /f %%g in ('echo prompt $E^| cmd') do set "LF=%%g[E"
echo !usbInfo!
However, this does not work when echoing to a file. I suspect the Terminal Escape Sequence only applies to the output to the cursor position on the console. Is there a workaround or is it best to just continue using the LF=^ method? I have no problem using the tried and true, but it is always interesting to find new methods.

Re: Terminal Escape Sequence and next line position

Posted: 22 Sep 2021 13:50
by aGerman
VT escape sequences require VT processing. That means the target of the stdout must be a terminal emulator which parses the incoming string in order to perform the expected rendering for the terminal window. If the target of stdout is a file the escape sequences are just passed through. The file system must not render it. Otherwise you would never be able to save an escape sequence in a script.

Steffen

Re: Terminal Escape Sequence and next line position

Posted: 22 Sep 2021 13:54
by atfon
aGerman wrote:
22 Sep 2021 13:50
...That means the target of the stdout must be a terminal emulator which parses the incoming string in order to perform the expected rendering for the terminal window.
That's rather what I thought, but I figured I would run it by the experts. Thanks for your speedy response as always, Steffen!