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);
}
If you want to do anything with the screen, this is one way. You can look up other codes from 'some programmer dude's comment. You can also google vt100 codes.
There are libraries that abstract this like Ncurses but since you can't use that (why?) that's out - I'll let others elaborate on that though, maybe there are others that are allowed..
edit
try this:
See my comment.
the VT100 codes don't help either
If you want to do anything with the screen vt100 codes are like a hacker's dream come true. Run, if you see the DEA coming, they are that good.