===============================================================================
* 正规 (canonical) 模式: 终端输入以行处理. 终端驱动程序提供行编辑能力.
* 非正规模式: 输入字符不以行处理.
===============================================================================
===============================================================================
* 非正规模式
* 关闭回显
* 每次一个字节 (c_cc [VMIN] = 1, c_cc [VTIME] = 0)
===============================================================================
===============================================================================
* 非正规模式
* 关闭回显
* 禁止 CR 到 NL 的映射 (ICRNL), 输入奇偶校验 (INPCK), 输入第 8 位的截取 (ISTRIP),
以及输出流控制 (IXON)
* 8 位字符 (CS8), 奇偶校验被禁止 (PARENB)
* 禁止所有的输出处理 (OPOST)
* 每次一个字节 (c_cc [VMIN] = 1, c_cc [VTIME] = 0)
===============================================================================
===============================================================================
#include <termios.h>
#include <unistd.h>
int tcgetattr (int fd, struct termios *termios_p);
int tcsetattr (int fd, int optional_actions, struct termios *termios_p);
-------------------------------------------------------------------------------
struct termios {
tcflag_t c_iflag; /* input modes */
tcflag_t c_oflag; /* output modes */
tcflag_t c_cflag; /* control modes */
tcflag_t c_lflag; /* local modes */
cc_t c_cc [NCCS]; /* control chars */
}
-------------------------------------------------------------------------------
* c_?flag 包含大量可控制的模式选项.
* c_cc 用来修改终端的特殊字符映射.
* c_cc 还可用来设置系统在什么情况下返回数据:
o 接收到指定数量的数据, c_cc [VMIN] 决定.
o 或者给定时间之后, c_cc [VTIME] 决定.
===============================================================================
===============================================================================
#include <termios.h>
#include <unistd.h>
speed_t cfgetospeed (struct termios *termios_p);
speed_t cfgetispeed (struct termios *termios_p);
int cfsetospeed (struct termios *termios_p, speed_t speed);
int cfsetispeed (struct termios *termios_p, speed_t speed);
===============================================================================
===============================================================================
#include <termios.h>
#include <unistd.h>
int tcdrain (int fd);
int tcflush (int fd, int queue_selector);
int tcflow (int fd, int action);
int tcsendbreak (int fd, int duration);
===============================================================================
===============================================================================
#include <termios.h>
#include <unistd.h>
pid_t tcgetpgrp (int fd);
int tcsetpgrp (int fd, pid_t pgrpid);
===============================================================================
===============================================================================
cfmakeraw 如下设置终端属性:
termios_p->c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON);
termios_p->c_oflag &= ~OPOST;
termios_p->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
termios_p->c_cflag &= ~(CSIZE | PARENB);
termios_p->c_cflag |= CS8;
===============================================================================
===============================================================================
#include <stdio.h>
char *ctermid (char *s); /* 返回控制终端名称 */
-------------------------------------------------------------------------------
#include <unistd.h>
int isatty (int desc); /* 判断描述符是否为终端 */
char *ttyname (int desc); /* 返回终端名称 */
===============================================================================
===============================================================================
* 利用 ioctl 的 TIOCGWINSZ 和 TIOCSWINSZ 命令可获得或设置终端窗口.
* 终端窗口改变时, 前台进程组中的进程将接收到 SIGWINCH 消息.
* 这一消息对伪终端应用程序很有意义.
===============================================================================
![]()