gpt4 book ai didi

c - termios.h 如何使用位掩码来确定终端应该是什么模式?

转载 作者:行者123 更新时间:2023-11-30 16:33:37 25 4
gpt4 key购买 nike

基本上,如果我写:

struct termios raw;
tcgetattr(STDIN_FILENO, &raw);
raw.c_lflag &= ~(ECHO);
tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw);

为了不显示用户输入,c_lflag 中的一项更改如何允许 tcsetattr() 按预期工作?

最佳答案

您可以禁用 ECHO 以使输入不回显到输出,如下所示:

toptions.c_lflag &= ~(ECHO);

if (tcsetattr(fd, TCSANOW, &toptions) != 0)
{
cout << "ERROR: " << errno << " from tcsetattr" <<endl;
exit(1);
}

ECHO 定义为:

ECHO in c_lflag controls whether input is immediately re-echoed as output. It is independent of ICANON, although they are often turned on and off together. When passwd prompts for your password, your terminal is in canonical mode, but ECHO is disabled.

关于c - termios.h 如何使用位掩码来确定终端应该是什么模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49685612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com