VT100 escape sequences not working in Windows 10?
Posted: 25 Aug 2019 11:02
I have an issue where I'm processing a bunch of files in a directory with the command line program ffprobe (part of ffmpeg). The directories will have video clips and ffprobe is run on each to see if certain conditions are met and then carry out ffmpeg modifications depending on those conditions. I've been using a batch file for several years to accomplish this, but I've always wanted to spruce it up a bit so I could share it with others.
Part of what I want to do is go through the list of files in a directory and show those file names on one line (not consecutive lines flowing down the screen) to show the user that they are being processed. I also don't mean file names written one after the other across the screen. I mean, for example, everything stays on the top line, starts writing from the far left and never moves down the screen. Each file name occupies the spot where the previous file name was output. I started out using the following to do that:
The problem with this is that the file names on the screen aren't deleted when the next file name is written to the screen, it is actually written over the character space that the previous file name occupied and if the first file name has more characters than the next then those "extra" characters remain on the screen when the next file name outputs. An example would be if a long file name, let's say longfilename.txt appears first on the screen and the next file is short.txt then what you see on the screen is:
short.txtame.txt
since the 9 charters in the file name short.txt overwrite only the first 9 characters of the file name longfilename.txt. I don't know if this is because of changes made to batch file behavior in Windows 10, but I suspect this to be the case.
I posted this question on reddit and someone suggested the following code using VT100 escape sequences:
but the output of that on my cmd screen is:
1G2KΓÇ£longfilename.txtΓÇ¥
1G2KΓÇ£short.txtΓÇ¥
1G2KΓÇ£mediumfile.txtΓÇ¥
I suspect there's something I need to have set in order for these codes to work, possibly in the registry, that isn't actually set. I've Googled this issue and found a note on Stack Overflow that says that I can test if VT100 sequences are enabled by issuing this to Powershell: "?[1;31mele ?[32mct ?[33mroni ?[35mX ?[36mtar ?[m".Replace('?', [char]27);
That line does output properly assigning colors to: "ele ct roni X tar" as intended, however I was worried that making changes to the registry that they suggested only applied to Powershell and not the cmd window.
But, as I describe above this stuff isn't working in the plain old cmd window. I am not an expert in batch writing and manage to get most things to work only by Googling them and finding where someone else has tried to do what I want to do so PLEASE don't suggest I try to do this in a Powershell script or C. I know a few languages, but those two aren't part of my repertoire. This is just a pet project of mine.
Part of what I want to do is go through the list of files in a directory and show those file names on one line (not consecutive lines flowing down the screen) to show the user that they are being processed. I also don't mean file names written one after the other across the screen. I mean, for example, everything stays on the top line, starts writing from the far left and never moves down the screen. Each file name occupies the spot where the previous file name was output. I started out using the following to do that:
Code: Select all
for %%a in ("*.*") do set filename=%%a
for /f %%h in ('copy "%~f0" nul /z') do set "CR=%%h"
set /p ".=!filename! !CR!" < nul
short.txtame.txt
since the 9 charters in the file name short.txt overwrite only the first 9 characters of the file name longfilename.txt. I don't know if this is because of changes made to batch file behavior in Windows 10, but I suspect this to be the case.
I posted this question on reddit and someone suggested the following code using VT100 escape sequences:
Code: Select all
ECHO OFF
FOR /F %%A in ('ECHO prompt $E^| cmd') DO SET "ESC=%%A”
FOR %%E in (“longfilename.txt” “short.txt” “mediumfile.txt”) DO (
ECHO %ESC%[1G%ESC%[2K%%~E
PAUSE>NUL
)
1G2KΓÇ£longfilename.txtΓÇ¥
1G2KΓÇ£short.txtΓÇ¥
1G2KΓÇ£mediumfile.txtΓÇ¥
I suspect there's something I need to have set in order for these codes to work, possibly in the registry, that isn't actually set. I've Googled this issue and found a note on Stack Overflow that says that I can test if VT100 sequences are enabled by issuing this to Powershell: "?[1;31mele ?[32mct ?[33mroni ?[35mX ?[36mtar ?[m".Replace('?', [char]27);
That line does output properly assigning colors to: "ele ct roni X tar" as intended, however I was worried that making changes to the registry that they suggested only applied to Powershell and not the cmd window.
But, as I describe above this stuff isn't working in the plain old cmd window. I am not an expert in batch writing and manage to get most things to work only by Googling them and finding where someone else has tried to do what I want to do so PLEASE don't suggest I try to do this in a Powershell script or C. I know a few languages, but those two aren't part of my repertoire. This is just a pet project of mine.