【问题标题】:Deleting output with termcaps使用 termcaps 删除输出
【发布时间】:2021-04-01 04:33:09
【问题描述】:

我正在尝试删除从光标到行尾的字符,问题是当我打印一个新行('\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),它也是如此。

关于如何避免这种情况的任何线索?

【问题讨论】:

  • termcap 功能不正确(它们记录在 terminfo(5) 手册页中)。

标签: c termcap


【解决方案1】:

查看 ce termcap 条目,这意味着从光标到行尾清除。

【讨论】:

  • 是的,我知道,我想做的是删除当前行中的字符,然后打印一个新的换行符并打印其他内容而不重新出现文本,我尝试使用dm(进入删除模式) 然后移动光标ed(退出删除模式),当我打印新行时,字符仍然会重新出现
  • 所以你需要输出ce字符串以清除当前行的其余部分,然后输出换行符转到下一行,然后在下一行输出你想要的任何内容。
  • 您的示例代码仅使用 LE 和 kL 条目。您必须执行 tgetstr("ce") 才能从 termcap 获取 ce 条目。这是要删除到行尾的控制序列。然后你写换行符。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-02-02
  • 1970-01-01
  • 2015-05-03
  • 2013-02-04
  • 2012-02-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多