c - 如何在不清除屏幕的情况下使用 getch from curses?

标签 c ncurses curses

我正在学习用 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 应用程序中看到您的屏幕被清除:

  • 你的程序调用initscr (清除屏幕)或 newterm无需先调用 filter , 或
  • 终端初始化清除屏幕(或通过切换到备用屏幕使其看起来像清除)。

在后一种情况下,您可以通过将 enter_ca_modeexit_ca_mode 指针重置为 NULL as done in dialog 来抑制 ncurses 中的备用屏幕功能.更好的是,选择一个可以满足您需要的终端描述。

进一步阅读:

关于c - 如何在不清除屏幕的情况下使用 getch from curses?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4772061/

相关文章:

c - 如何在 C 程序中将 shell 变量作为命令行参数传递

c - 如何用 ncurses 检测大写锁定?

C 编程 ncurses 输入验证

python - 在 Python 中格式化列表的输出

Curses 库退格问题

python celery - ImportError : No module named _curses - while attempting to run manage. py celeryev

c - 无法将 C 程序变量绑定(bind)到 SQL Server 中的日期时间类型列

c - 参数是如何加载到 $esp 中的?

c - doxygen 忽略文件的特殊命令

c - 在 ncurses 中定义新颜色