我正在尝试删除从光标到行尾的字符,问题是当我打印一个新行('\n')之后,删除的字符重新出现,我还尝试在新行之前打印一个空字符行,它也一样。最小代码:
#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);
}
输出:Hello World
没有最后一个write(1, "\n", 1)
输出:Hello
我花了几个小时才发现是新线路造成的,现在我不知道该怎么做。
我也尝试过write(1, "\0\n", 2)
,它也是如此。
关于如何避免这种情况的任何线索?