Ncurses CTRL + s 挂起 getch()
Ncurses CTRL + s hangs getch()
为什么在这个简单的程序中:
#include <curses.h>
#include <iostream>
int main() {
initscr();
keypad(stdscr, TRUE);
timeout(-1);
int c = getch();
std::cout << c << std::endl;
endwin();
}
按 ctrl + s 挂起?
我相信您正在经历 XOFF/XON flow control。 CtrlS为XOFF,停止输出直到CtrlQ (XON) 被发送。您可以通过键入 CtrlQ.
来继续您的程序
这不是您的代码的问题。它发生在终端级别。
当您使用 initscr
, the terminal is in cooked mode, which honors XON/XOFF. In the curses manual pages, that is referred to as "flow control characters"; POSIX 启动 curses 时,将其称为 "output control":
IXON
Enable start/stop output control.
如果您调用 raw
,则 XON/XOFF 关闭 ,您可以使用 控制S
:
#include <curses.h>
#include <iostream>
int main() {
initscr();
raw(); // possibly what you intended
keypad(stdscr, TRUE);
timeout(-1);
int c = getch();
std::cout << c << std::endl;
endwin();
}
您的应用程序可以调用 tcgetattr
来确定是否设置了基础 XON/XOFF 模式,但这无助于确定 curses 是否设置了原始模式:
- curses 总是将终端设置为原始模式,
- curses 为您的应用程序模拟 cooked/raw 模式,并且
- curses 没有您的应用程序可以调用以查找当前状态的函数。
为什么在这个简单的程序中:
#include <curses.h>
#include <iostream>
int main() {
initscr();
keypad(stdscr, TRUE);
timeout(-1);
int c = getch();
std::cout << c << std::endl;
endwin();
}
按 ctrl + s 挂起?
我相信您正在经历 XOFF/XON flow control。 CtrlS为XOFF,停止输出直到CtrlQ (XON) 被发送。您可以通过键入 CtrlQ.
来继续您的程序这不是您的代码的问题。它发生在终端级别。
当您使用 initscr
, the terminal is in cooked mode, which honors XON/XOFF. In the curses manual pages, that is referred to as "flow control characters"; POSIX 启动 curses 时,将其称为 "output control":
IXON
Enable start/stop output control.
如果您调用 raw
,则 XON/XOFF 关闭 ,您可以使用 控制S
:
#include <curses.h>
#include <iostream>
int main() {
initscr();
raw(); // possibly what you intended
keypad(stdscr, TRUE);
timeout(-1);
int c = getch();
std::cout << c << std::endl;
endwin();
}
您的应用程序可以调用 tcgetattr
来确定是否设置了基础 XON/XOFF 模式,但这无助于确定 curses 是否设置了原始模式:
- curses 总是将终端设置为原始模式,
- curses 为您的应用程序模拟 cooked/raw 模式,并且
- curses 没有您的应用程序可以调用以查找当前状态的函数。