【发布时间】:2013-11-03 16:23:30
【问题描述】:
问题一:termios_p->c_oflag中的OFILL标志是干什么用的。
文档是这样说的:
延迟发送填充字符,而不是使用定时延迟。
为了解决这个问题,我创建了这个小测试程序:
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <termios.h>
int main(int argc, char *argv[])
{
char c;
int res;
struct termios termios_old, termios_new;
res = tcgetattr(0, &termios_old);
assert(res == 0);
termios_new = termios_old;
// Setup the terminal in raw mode
termios_new.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP |
INLCR | IGNCR | ICRNL | IXON);
termios_new.c_oflag &= ~OPOST;
termios_new.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
termios_new.c_cflag &= ~(CSIZE | PARENB);
termios_new.c_cflag |= CS8;
// Add the flag I'm trying to understand
termios_new.c_oflag |= OFILL; // What is this flag used for?
res = tcsetattr(0, TCSANOW, &termios_new);
assert(res == 0);
while (1) {
read(0, &c, 1);
printf("0x%x %d\r\n", (int)c, (int)c);
if (c == 'q')
break;
}
tcsetattr(0, TCSANOW, &termios_old);
return 0;
}
当我运行程序时,如果设置或未设置标志,我看不到任何差异......我希望这个标志可以以某种方式更容易检测是否按下了 ESC 键。
在上面的程序中,如果我按下Left-Arrow-key 并且如果我按下序列:ESC[D,我会看到完全相同的输出。
问题2:我应该如何检测用户是否按下了ESC按钮以及我应该如何检测用户是否按下了`左箭头按钮
由于这是学习终端 IO 系统如何工作的练习,所以我不想使用任何库。
【问题讨论】:
-
我认为您可能会将 termios 的延迟与您的终端添加延迟来进行字符转义混淆。