I need to create a interface
in terminal using the termios.h
in C. To keep it short I have to create a executable like ./exec
and after I run, it has to stop displaying the PS1
variable.
If I have a program which displays the following text Hello World
that uses printf
it will look like:
$:> ./exec
Hello World!
But instead of printing that, I need only the Hello World!
to be in the terminal, like when you clear the screen while the program is displaying.
Hello World!
To say it in other way, the purpose is to clean the terminal, and when the ./exec
is runned, it should clear this line as well, $:> ./exec
.
So far I managed to make this function
void clear_screen()
{
char buf[1024];
char *str;
tgetent(buf, getenv("TERM"));
str = tgetstr("cl", NULL);
fputs(str, stdout);
}
Which clears the screen but it keeps the line with the command itself $:> ./exec
. I am not allowed to use ncurses.h
library.
Here is a main:
int main(void)
{
clear_screen();
printf("Hello World!\n");
return (0);
}