术语“cl"命令不清除屏幕 [英] Termcap "cl" command doesn't clear screen

查看:51
本文介绍了术语“cl"命令不清除屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让 termcap 的cl"命令起作用,但终端转义码可以.

I can't seem to get termcap's "cl" command to work, but the terminal escape code does.

例如:

#include <termcap.h>
#include <stdio.h>

int main()
{
    tputs(tgetstr("cl", NULL), 1, putchar);
}

这不会改变终端.但是当我跑步时:

This doesn't change the terminal. But when I run:

#include <stdio.h>

int main()
{
    printf("\e[2J");
}

或者如果我调用 echo `tput cl`终端清零.

or if I call echo `tput cl` The terminal is cleared.

为什么会这样?termcap 不应该给出相同的转义码吗?

Why does this happen? Shouldn't termcap give that same escape code?

固定书写字符

这是因为我在调用 tgetstr() 之前没有调用 tgetent().谢谢各位!

It's because i didn't call tgetent() before calling tgetstr(). Thanks guys!

推荐答案

在用tgetstr()查询之前,需要用tgetent()找到用户终端的描述代码>:

Before interrogating with tgetstr(), you need to find the description of the user's terminal with 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

这篇关于术语“cl"命令不清除屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆