曲径通幽论坛

标题: tputs() [打印本页]

作者: beyes    时间: 2009-3-12 20:12
标题: tputs()
tputs

Purpose

Outputs a string with padding information.

Library

Curses Library (libcurses.a)

Syntax

#include <curses.h>
#include <term.h>
tputs(String, LinesAffected, PutcLikeSub)
char *String;
int LinesAffected;
int (*PutcLikeSub) ();

Description
The tputs subroutine outputs astring with padding information applied. String must be a terminfo string variable or the return value from tparm, tgetstr, tigetstr, or tgoto subroutines.

Parameters

LinesAffected  Specifies the number of lines affected, or specifies 1 if not applicable.
PutcLikeSub  Specifies a putchar-like subroutine through which the characters are passed one at a time.
String  Specifies the string to which to add padding information.

Examples


作者: beyes    时间: 2009-3-12 20:53
函数名
tputs
用途
输出一个有填充信息的字符串

Curses Library (libcurses.a)
语法
#include <curses.h>
#include <term.h> 
tputs(String, LinesAffected, PutcLikeSub)
char *String;
int LinesAffected;
int (*PutcLikeSub) ();
描述
tputs() 函数输出一个含有填充信息的字符串。参数 String 必须是一个 terminfo 字符串变量或者是由 tparm(), tgetstr(), tigetstr() 函数的返回值.
参数
LinesAffected : 指定所影响到的行的数目,如果不用一般就指定为 1
PutcLikeSub : 这是一个类似于 putchar 的函数,通过这个函数字符可以一次性的被传递
String : 指定一个附加有填充信息的字符串
举例
1、清屏;这里使用类 putchar() 函数,如 my_putchar() :
int my_putchar();
tputs(clear_screen, 1, my_putchar);
2、输出把光标移动到坐标 x=40,y=18 处的转义序列 :
int my_putchar();
tptus(tparm(cursor_address, 18, 40), 1, my_putchar);

测试代码
#include <stdio.h>
#include <term.h>
#include <curses.h>
#include <stdlib.h>

int main()
{
        int nrows, ncolumns;
        char *clear;
        char *cursor;

        setupterm(NULL, fileno(stdout), (int *)0); /*需要设置当前终端*/
        nrows = tigetnum("lines");               /*得到当前终端窗口尺寸中的行(可以容纳几行)*/
        ncolumns = tigetnum("cols");            /*得到当前终端窗口尺寸中的列(可以容纳几列)*/
        printf("This termianl has %d columns and %d rows\\n", ncolumns, nrows);

        cursor = tigetstr("cup");  /*得到终端的光标位置转义序列*/
        clear = tigetstr("clear");  /*得到终端的清屏动作转义序列*/

        tputs(clear, 1, putchar);  /*进行清屏*/
        tputs(tparm(cursor, 4, 10), 1, putchar); /*需要在4行10列处输出(填充掉之前空间内容<padding information>*/
        printf("hello world\\n"); /*在终端窗口的4行10列位置处打印字符串*/

        exit(0);
}
运行及输出
          hello world
[root@localhost C]#
可见,清屏后,输出位置定位在 (4,10) 处,然后打印出 hello world 字符串。




欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2