我似乎不能让termcap的"cl“命令工作,但是终端转义代码可以。
例如:
#include <termcap.h>
#include <stdio.h>
int main()
{
tputs(tgetstr("cl", NULL), 1, putchar);
}这不会改变终端。但是当我运行的时候:
#include <stdio.h>
int main()
{
printf("\e[2J");
}或者,如果我调用echo `tput cl`,终端就会被清除。
这一切为什么要发生?termcap不应该给出同样的转义代码吗?
编辑:固定书写字符
EDIT2:这是因为我在调用tgetstr()之前没有调用tgetent()。谢谢你们!
发布于 2018-08-10 22:11:56
在使用tgetstr()进行询问之前,您需要使用tgetent()找到用户终端的描述
#include <stdio.h>
#include <stdlib.h> // getenv
#include <termcap.h> // tgetent tgetstr
int main(void)
{
char buf[1024];
char *str;
tgetent(buf, getenv("TERM"));
str = tgetstr("cl", NULL);
fputs(str, stdout);
return 0;
}使用-ltermcap进行编译
https://stackoverflow.com/questions/51785373
复制相似问题