运行终端程序时阻止终端输入 [英] Block terminal input while running a terminal program
本文介绍了运行终端程序时阻止终端输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在终端程序运行时按 Enter 键时,会添加一个新行.我怎样才能禁用它?我不想使用 ncurses.我在 Ubuntu 上.
When I press enter while my terminal program runs, a new line is added. How can I disable this? I don't want to use ncurses. I am on Ubuntu.
推荐答案
按照 nm 的提示,我找到了 this 并想出了这个:
Following up n.m's hint, I found this and came up with this:
static struct termios t;
tcgetattr( STDIN_FILENO, &t);
t.c_lflag &= ~ECHO;
tcsetattr( STDIN_FILENO, TCSANOW, &t);
这似乎阻止了终端的所有输入.
This seems to block all input to the terminal.
这篇关于运行终端程序时阻止终端输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文