terminfo 能力資料庫描述各終端機功能與調用序列#include <stdlib.h>
#include <stdio.h>
#include <term.h>
#include <curses.h>
#define NUMCAPS 3
int main(void) {
char *boolcaps[] = {"am", "bce", "km"};
char *numcaps[] = {"cols", "lines", "colors"};
char *strcaps[] = {"cup", "flash", "hpa"};
int retval;
char *buf;
if (setupterm(NULL, fileno(stdin), NULL) != OK) {
perror("setupterm");
exit(EXIT_FAILURE);
}
for (int j = 0; j < NUMCAPS; j++) {
retval = tigetflag(boolcaps[j]);
printf("%s %s\n", boolcaps[j], retval ? "supported" : "unsupported");
}
for (int j = 0; j < NUMCAPS; j++) {
retval = tigetnum(numcaps[j]);
printf("%s %s%d\n", numcaps[j], retval == -1 ? "unsupported: " : "=", retval);
}
for (int j = 0; j < NUMCAPS; j++) {
buf = tigetstr(strcaps[j]);
printf("%s %s\n", strcaps[j], buf ? "supported" : "unsupported");
}
return 0;
}
gcc test.c -o test -lcurses
./test
需連結 libcurses。程式查詢布林、數值、字串三類終端機能力並輸出結果。