linux – Graphics in terminals how does it work?

I know about SDL and other libraries that you can use to draw graphics on windows. But I was wondering if I wanted to make a terminal application like htop On Linux, how would this work? Normally, when I print text on the terminal, it only prints it on a new line. But htop It seems to draw real graphics on the terminal and updates its screen every second.

Can anyone point me more information? I have searched but could not find the information.