I have only the most basic experience digging into that stuff -- from quite a while ago -- but the keywords I think you need to search for to find out more info about this are: escape codes, TUI (i.e. Text User Interface), and curses.
The last is an old library for implementing TUIs. There's successors like ncurses as well. I don't know what people actually use currently though.


!