The smcup this uses is the one for st and kitty, and it's not valid for xterm, iterm, konsole, vte (e.g. gnome-terminal),....
That means it's not just "obscure dumb terminals from 1983". It's the majority of your userbase!
Which means you _need_ some kind of authoritative database of escape sequences, and you need to query that instead of building the strings yourself. Whether that database is terminfo or something new to replace it is up for debate - there's room for improvement over both it and ncurses - but that makes most of this irrelevant.