top/contents search
旧的 termcap 库例程及其后来的“terminfo”替代品,包含一个设备相关的字符串数据库,这些字符串需要被“打印”以达到各种目的。程序首先加载当前使用的终端的描述(通常由环境变量TERM指定),然后获取它将需要的各种控制字符串和其他参数,最后根据需要打印这些字符串。移动光标时,tgoto函数负责使用设备相关的cm(“光标移动”)字符串中描述的任何设备相关的编码方案来编码所需的行号和列号。

这是一个最小的示例,省略了错误检查和其他细微之处,但应该能帮助您入门。
#include <stdio.h>
#include <stdlib.h>
#include <termcap.h>

int main()
{
	char buf[1024];
	char buf2[30];
	char *ap = buf2;
	char *clearstr, *gotostr, *standstr, *stendstr;

	tgetent(buf, getenv("TERM"));

	clearstr = tgetstr("cl", &ap);
	gotostr = tgetstr("cm", &ap);
	standstr = tgetstr("so", &ap);
	stendstr = tgetstr("se", &ap);

	fputs(clearstr, stdout);
	fputs(tgoto(gotostr, 20, 10), stdout);
	printf("Hello, ");
	fputs(standstr, stdout);
	printf("world");
	fputs(stendstr, stdout);
	putchar('!');
}

返回


contents search
关于此 FAQ 列表   关于 Eskimo   搜索   反馈   版权

Eskimo North 托管