曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 4874|回复: 1
打印 上一主题 下一主题

tputs()

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2009-3-12 20:12:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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

      To output the clear screen sequence using the user-defined putchar-like subroutine my_putchar,  enter:
      int_my_putchar();
      tputs(clear_screen, 1 ,my_putchar);

      To output the escape sequence used to move the cursor to the coordinates x=40, y=18 through the user-defined putchar-like subroutine my_putchar, enter:
      int_my_putchar();
      tputs(tparm(cursor_address, 18, 40), 1, my_putchar);

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
沙发
 楼主| 发表于 2009-3-12 20:53:59 | 只看该作者
函数名
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 字符串。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-12 03:57 , Processed in 0.073475 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表