Search code examples
batch-fileanimationcmdnotepad++flicker

How do I remove flickering from a batch file animation?


So I've been working on a fake GUI in batch for the ending to a YouTube review I'm working on. It's basically a bunch of box-drawing characters and text that kinda simulates an 80's monochrome terminal. Anyway, the program's got some animation in it that flicker a ton and briefly blinks when I move to the next stage of sections that aren't animated. The way I got the frames set up is, well, just the GUI written with box-drawing characters and text forming the entire screen. The animations are set up so that after one frame, 'ping localhost' is used as the timer, followed by 'cls', followed by the next frame and so on. I assume that the 'cls' is what's causing all the flickering. Normally I'd be fine with the flickering as I believe it adds to the feel of something out of the 80's, however as I plan on using this in a YouTube video for all of the world to see, I don't want to possibly be the reason someone has an epileptic episode. Is there another way to eliminate the flicker or another way to animate this so that the flicker doesn't happen? I already have the entire program finished and would hate to have to throw it all away. Other information is that I'm on Windows 10 and used Notepad++ to make this thing.


Solution

  • To elaborate on SomethingDark's comment -

    Virtual terminal codes are supported in windows 10 only

    The Escape Control Character can be defined by parsing over The Prompt $E command. One method is:

     for /F "delims=#" %%a in ('"prompt #$E# & for %%a in (1) do rem"') do set "\E=%%a"
    

    Another, simpler method is:

     for /F %%a in ('Echo prompt $E ^|cmd') do set "\E=%%a"
    

    The vast majority of sequence's described here are supported

    Virtual terminal codes are also supported by the Type command, allowing efficient screen updates by outputting changed cells to a file, then typing the file to screen.
    Note: Issues can occur when using type with UTF-8 Codepage characters, even with the correct codepage set - to avoid those issues, explicity redirect the type file command to Con. IE:

    Type "filename.ext" > Con
    

    After defining the Escape character %\E%, The console cursor can be suppressed using:

    <nul set /P "=%\E%[?25l"
    

    And Enabled with:

    <nul Set /P "=%\E%[?25h"
    

    Individual cells can be cleared using:

    rem /* for current cell location */
    <nul Set /P "=%\E%[1X"
    rem /* for a cell located at substituted y x coordinate value */
    <nul Set /P "=%\E%[y;xH%\E%[1X"
    

    An example script that produce a flicker free animation with a consistent frame rate can be found at this answer