To reset your terminal, you can call reset
from your shell, which is generally included with the target operating systems.
If you want to reset when you are not at a shell prompt (i.e., inside some other application), we can send an escape sequence in another way.
As an example, we can send a special escape sequence to the Nth tty:
echo -e "\ec" > /dev/pts/$N