简体   繁体   English

ncurses基本示例-在调试中,我得到:“打开终端时出错:未知。”

[英]ncurses basic example - in debug i get: “Error opening terminal: unknown.”

doing some basic examples on ncurses libreries, I get some issues. 做一些关于ncurses自由的基本示例,我遇到了一些问题。

Actually, I don't get what I expect (message printed), and going in debug, from eclipse, I get (in console area) "Error opening terminal: unknown." 实际上,我没有得到我所期望的(消息已打印),并且从Eclipse中进入调试阶段,我得到了(在控制台区域)“打开终端时出错:未知。”

Follows code: 遵循代码:

#include <unistd.h>
#include <stdlib.h>
#include <ncurses.h>


int main() {

    initscr();

    move(5,15);
    printw("%s", "Hello world!");
    refresh();

    endwin();
    exit(EXIT_SUCCESS);
}

Compiler options, as provided in Eclipse console at "Build project" command: Eclipse控制台中“ Build project”命令中提供的编译器选项:

make all 
Building file: ../source/Curses_01.c
Invoking: GCC C Compiler
gcc -Incurses -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"source/Curses_01.d"     -MT"source/Curses_01.d" -o"source/Curses_01.o" "../source/Curses_01.c"
Finished building: ../source/Curses_01.c

Building target: Curses_01
Invoking: GCC C Linker
gcc  -o"Curses_01"  ./source/Curses_01.o   -lcurses
Finished building target: Curses_01

Thanks everybody in advance! 提前谢谢大家!

You do get the string printed. 您确实得到了打印的字符串。 The problem is that the program exits immediately. 问题是程序立即退出。 This will clear the screen and restore it to its previous state. 这将清除屏幕并将其恢复到以前的状态。 This happens very fast, of course, so you don't get to see anything. 当然,这发生得非常快,因此您什么也看不到。

The solution is to wait for a keypress before exiting. 解决方案是在退出前等待按键。 You can do this with getch() : 您可以使用getch()完成此操作:

/* ... */
refresh();
getch();
endwin();
exit(EXIT_SUCCESS);

The Eclipse problem arises due to the terminal presented by Eclipse to the application. 由于Eclipse向应用程序提供了终端,因此出现了Eclipse问题。 NCurses doesn't recognize it. NCurses无法识别它。 I don't use Eclipse, so I don't know exactly how to do this, but you should search for some setting that allows you to run the application inside a full terminal (like in xterm, Konsole, Gnome Terminal, etc.) 我不使用Eclipse,所以我不确切地知道该怎么做,但是您应该搜索一些设置,以使您可以在完整的终端中运行应用程序(例如xterm,Konsole,Gnome Terminal等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM