I'm trying to delete the characters from the cursor to the end of line, the problem is when I print a new line ('\n') after, the deleted characters reappear, I also tried to print a null character before the new line and it does the same. Minimal code:
#include <ncurses.h>
#include <term.h>
#include <unistd.h>
#include <stdlib.h>
int ft_putchar(int ch)
{
char c = (char)ch;
return (write(1, &c, 1));
}
int main(void)
{
tgetent(getenv("TERM"), NULL);
char * LE = tgetstr("LE", NULL); // termcap for cursor left
char * kL = tgetstr("kL", NULL); // termcap for cursor right
write(1, "Hello World", 11);
tputs(tparm(LE, 5), 1, ft_putchar); // move the cursor 5 cases left
tputs(kL, 1, ft_putchar); // delete to end of line
write(1, "\n", 1);
return (0);
}
Output: Hello World
And without the last write(1, "\n", 1)
Output: Hello
I spent hours to discover that the new line was causing that, now I can't figure out how to do it.
And I also tried write(1, "\0\n", 2)
and it does the same.
Any clues of how to avoid that?