终端编程: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
超级会员免费看
订阅专栏 解锁全文
4

被折叠的 条评论
为什么被折叠?



