18、终端编程:termios 结构与 terminfo 功能详解

终端编程:termios 结构与 terminfo 功能详解

1. 终端设置与基本操作

当终端设置为立即读取字符后,可再次运行程序 menu1 ,它应能按预期工作。为改进密码检查功能,可在提示输入密码前关闭回显,使用命令 stty -echo ,之后记得用 stty echo 恢复回显。

终端速度由 termios 结构操控,输入和输出速度分开处理,相关函数原型如下:

#include <termios.h>
speed_t cfgetispeed(const struct termios *);
speed_t cfgetospeed(const struct termios *);
int cfsetispeed(struct termios *, speed_t speed);
int cfsetospeed(struct termios *, speed_t speed);

设置新速度步骤:
1. 使用 tcgetattr 读取当前设置。
2. 用上述函数之一设置速度。
3. 使用 tcsetattr 写回 termios 结构。

速度取值如下表:
|速度常量|含义|
| ---- | ---- |
|B0|挂断终端|
|B1200|1200 波特|
|B2400|2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值