[0]: https://youtu.be/BCqGjGzWI48?feature=shared&t=839
I'm sure you can find online documentation for the functions and escape sequences of all of the common terminals. For example: https://vt100.net/docs/vt100-ug/chapter3.html
You might also look at the code for open source terminal emulators.
From the documentation you can probably infer how terminal UIs work. I did a lot of terminal UIs in the past. In general the application on the back-end (mainframes and minicomputers in the old days) maintained an 80x24 (or larger) array of characters and metadata, application code made changes to that screen buffer, then a layer in between translated changes to the correct escape codes and sent that to the hardware terminal. I'm simplifying but that's the general idea.
Modern: https://clig.dev/