refreshansi-escapepausexterm

Is there an escape code to pause the terminal screen refresh?


I have an application that displays images using 8-bit ANSI-art. This is handy for viewing images on a remote machine via SSH. When the viewer starts, it replaces all the 8-bit palette values from 16-255 with my standard values. This runs fine on the Mac terminal, but the xterm display flickers because it is trying to refresh while it is still executing these 240 commands.

I get the same thing when the program exits, and I have to reset the colours. Here is the code for resetting the palette when the program exits.

for (int N=16; N<256; ++N) printf("\e]104;%d\a", N);

I can see the colours changing in the terminal as it runs.

I have not found an escape code that resets the whole palette. Sending Ctrl-C resets some things but not the palette. All the examples I have found use a loop like this. It would be nice to find a reset escape sequence if there is one, but I will also need a way to pause the screen refresh until the commands have finished.

I tried running all the escape sequences into one big string and submitting all of them at once with puts(). That did not do the trick.

I hoped to find an escape sequence that pauses the screen refresh, and another that un-pauses it. It seems like something that ought to be there, and I am not seeing it. Or, if we know for sure that no such escape sequences exist, then I can stop looking. There may be other ways of fixing this other than escape codes. However, the application is handiest when working remotely, so I want it to work on whatever terminal is running at the time, not just xterm. I can ignore the flickering if I have to.

PS: I have a workaround. Xterm supports 24-bit Truecolor. I can use that and not change the 8-bit palette.


Solution

  • Not what the title asks for, but enabling the alternative screen buffer is a fix.

    Print "\e[?1049h to enable when the program starts and and "\e[?1049l to disable.

    The Wikipedia entry says little more than that, so it is easy to ignore. Enabling the alternative screen buffer means the application works with a terminal-sized window of characters. This is probably what an interactive terminal program needs rather than add all the screen refreshes to the current scrolling terminal buffer. Disabling restores the terminal to its previous state.