The more serious issue is that this library apparently does not enforce a length limit on escape sequences.
I've always wanted a virtual terminal that had a terminal state stack, when you run a command or open a program, all the changes to the terminal are pushed on the top of terminal stack. When I quit the program or the command stops, the state is popped. It seems like it would be very difficult to implement such a thing in the current terminal framework because as far as I can tell, they do not understand when a command starts or stops. Then again the effectiveness of virtual terminals over the last 5 or so decades is likely because of this simplicity and its corresponding flexibility.
You could probably have a push/pop escape sequence requiring a matching unique token that intermediate output can't guess.
OSC 57473 ; 1 ; <token> ST
⋮
OSC 57473 ; 0 ; <token> ST