Terminal Escape Sequence and next line position

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Terminal Escape Sequence and next line position

#1 Post by atfon » 22 Sep 2021 13:21

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Terminal Escape Sequence and next line position

#2 Post by aGerman » 22 Sep 2021 13:50

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

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Terminal Escape Sequence and next line position

#3 Post by atfon » 22 Sep 2021 13:54

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!

Post Reply