linux终端属性设置,设置终端控制属性(ubuntu的命令终端显示属性)

#include

#include

#include

#include

#include

int main(void)

{

#if 0

int n = 10;

while(1)

{

if((n--) == 0)

{

printf("over n=%d\n", n);

break;

}

printf("n=%d\n", n);

}

#endif

unsigned char buf[1024];

bzero(buf, 1024);

read(0, buf, 1024);

printf("buf:%s\n", buf);

#if 1

//终端属性描述结构体

struct termios oldattr, newattr;

//获取当前终端的属性

tcgetattr(0, &oldattr);

//将newattr设置为原始属性

cfmakeraw(&newattr);

//将终端设置为原始属性

tcsetattr(0, TCSANOW, &newattr);

while(1)

{

bzero(buf, 1024);

read(0, buf, 1024);

printf("%u\t%u\t%u\t%u\n", buf[0], buf[1], buf[2],buf[3]);

}

//将终端恢复原来的属性

tcsetattr(0, TCSANOW, &oldattr);

sleep(1);

bzero(buf, 3);

read(0, buf, 3);

printf("%c\t%c\t%c\n", buf[0], buf[1], buf[2]);

#endif

#if 0

//终端属性描述结构体

struct termios oldattr, newattr;

//获取当前终端的属性

tcgetattr(0, &oldattr);

//将newattr设置为原始属性

cfmakeraw(&newattr);

//将终端设置为原始属性

tcsetattr(0, TCSANOW, &newattr);

bzero(buf, 1024);

read(0, buf, 1024);

printf("%c\t%c\t%c\t%c\n", buf[0], buf[1], buf[2], buf[3]);

//将终端恢复原来的属性

tcsetattr(0, TCSANOW, &oldattr);

sleep(1);

bzero(buf, 1024);

read(0, buf, 1024);

printf("%c\t%c\t%c\t%c\n", buf[0], buf[1], buf[2], buf[3]);

#endif

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值