我正在学习用 C 语言编程,并且希望能够在我的代码运行时在终端中键入字符,而无需按 return。我的程序可以运行,但是当我调用 initscr()
时,屏幕被清空 - 即使在调用 filter()
之后也是如此。 filter
的文档建议它应该禁用清除 - 但我不是这种情况。
#include <stdio.h>
#include <curses.h>
#include <term.h>
int main(void) {
int ch;
filter();
initscr();
cbreak();
noecho();
keypad(stdscr, TRUE);
while((ch = getch()) != EOF);
endwin();
return 0;
}
为什么上面的代码仍然会清除屏幕,可以做些什么来解决这个问题?
如果有帮助,我正在使用 Debian Lenny(稳定版)和 gnome-terminal。
最佳答案
由于以下原因之一,您会在 curses 应用程序中看到您的屏幕被清除:
在后一种情况下,您可以通过将 enter_ca_mode
和 exit_ca_mode
指针重置为 NULL as done in dialog
来抑制 ncurses 中的备用屏幕功能.更好的是,选择一个可以满足您需要的终端描述。
进一步阅读:
- Why doesn't the screen clear when running vi? (xterm 常见问题解答)
关于c - 如何在不清除屏幕的情况下使用 getch from curses?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4772061/