[英]Deleting output with termcaps
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.我正在尝试将字符从 cursor 删除到行尾,问题是当我打印一个新行('\n')之后,删除的字符重新出现,我还尝试在新字符之前打印一个 null 字符行,它也一样。 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
Output:
Hello World
And without the last write(1, "\n", 1)
并且没有最后一次
write(1, "\n", 1)
Output: Hello
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.而且我还尝试了
write(1, "\0\n", 2)
并且它也是如此。
Any clues of how to avoid that?关于如何避免这种情况的任何线索?
Look at the ce termcap entry, that means clear from cursor to end of line.查看 ce termcap 条目,这意味着从 cursor 到行尾清除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.