At times, with the Alacritty + Zellij stack, I’ll get strange escape codes in the terminal.
Example below:
I noticed that any time I scrolled the mouse wheel, I would see more codes.
Perplexity thinks this is due to mouse and other escape codes leaking in:
The “random non-ASCII characters” appearing in your terminal are almost certainly raw ANSI escape sequences—specifically mouse reporting or focus event sequences—that are leaking into the standard input of your shell instead of being intercepted by Zellij or the running application.
This typically happens when there is a mismatch between the terminal emulator (Alacritty) and the multiplexer (Zellij) regarding who handles these events, or when a sequence is fragmented (common over SSH).
It seems to happen more when running sessions over SSH:
If you are running Zellij over SSH, network packet fragmentation can split an escape sequence into two parts. The first part might be consumed, but the second part arrives purely as text, appearing as random characters.
A reset command will often fix things.
One thing that puzzles me is that once it starts, the terminal seems to get into a mode where the problem continues, and the system needs to be reset.
After that, subsequent escape sequences are still being parsed , but under the new charset/mode or from a misaligned parser state, so they look wrong on screen and keypresses produce garbage until you run
resetorstty saneto reinitialize the tty and the emulator state.
I’ve also seen cases where a terminal starts showing a different charset.
I guess this is the problem with terminals and escape codes - there is no framing, just a stream of bytes. It looks like there are efforts to improve this, but it is very difficult, so most current efforts are on making things more robust.
We could get frustrated and throw terminals with this problem under the bus, but we need to apply BCR thinking - terminals and terminal applications are very flexible and fast, even over remote connections. They work most of the time. The benefits are huge. The cost of typing reset occasionally is probably worth the occasional hiccup caused by a glitch in the stream of bytes. The key is to understand what is going on and how to recover.
