Reputation: 825
With the following code I am erasing the prompt but not clearing the screen. What chould be the reason?
printf("\033[7mHello how are you doing? press 'q' to quit\033[0m");
fflush(stdout);
----
doing some other stuff
----
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\
\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\033[0m");
fflush(stdout);
I am erasing the prompt but the traces of it appear until I type something that long.
Upvotes: 1
Views: 125
Reputation: 5533
printf("\033[2J");
This would clear the terminal screen.
I see you're using skip character \b
, are you trying to reset the terminal cursor to the beginning? because that can also be done with this:
printf("\033[1;1H");
Upvotes: 1
Reputation:
\b
only moves the cursor position, it doesn't erase the prompt.
To erase write a space for every backspace.
char * hello = "\033[7mHello how are you doing? press 'q' to quit\033[0m" ;
int len = strlen( hello ) ;
for( int i = 0 ; i < len ; i++ )
{
printf("\b \b");
}
Upvotes: 1