How does a program like vi or man or any other program replace the terminal content with the program\'s own contents then after quitting those programs they bring back the o
By sending control sequences to the terminal (xterm, vt-220) or using ncurses (like mc).
A ANSI Escape Sequence starts with ESC (\033 octal) [. ; separates Numbers.
C Example that clears the Screen and moves the cursor to 1,1.
#include
int main()
{
// clear the terminal
printf("\033[2J\033[1;1H");
printf("hello");
}
Example of switchting to alternate Buffer and back (xterm).
#include
#include
int main()
{
printf("\033[?1049h\033[H");
printf("hello\n");
sleep(1);
printf("bye");
sleep(1);
printf("\033[?1049l");
}