Hello,
Sorry I made you wait. I tried the patch (see attachments) and everything worked perfectly. No flickering.
I tried to implement the second spec, but it didn't work (at least in Alacritty). But, I can try to add support for both.
BTW, tmux uses the sync update for their own TUI and they check "Sync" terminal capability. Do we need to do the same or we can just send the escapes and hope the unsupported terminal would just recover?
Side note: I still have the issue when I run emacs inside of tmux, but it is due to lack of support from tmux side. I created a bug and will try to implement the functionality in tmux sooner or later. See
https://github.com/tmux/tmux/issues/3325 foe details. I assume, in the case of tmux, the multiplexer just consumes the escape codes and doesn't send them to the parent terminal.