如何在不结束C ++程序的情况下结束ncurses?

时间:2022-09-10 23:26:59

I've been trying to make an ncurses program that will end the ncurses mode at a certain point, and resume in normal terminal mode, but still keeping the program running. Is it possible? endwin(); ends the program. Here is my code (don't worry about the functions, I made them before):

我一直在尝试制作一个ncurses程序,它将在某一点结束ncurses模式,并在正常的终端模式下恢复,但仍然保持程序运行。可能吗? endwin();结束程序。这是我的代码(不要担心功能,我之前做过):

clear();
refresh();
endwin();
boxmessage("STEP 1");
consolewrite("Removing Popularity Contest...");
std::vector<std::string> removepak;
removepak.push_back("popularity-contest");
removepackages(removepak);

1 个解决方案

#1


4  

endwin() isn't terminating your program; something else must be doing so.

endwin()不会终止你的程序;别的东西必须这样做。

This program works correctly on my system (Ubuntu 11.04, g++ 4.5.2):

这个程序在我的系统上正常工作(Ubuntu 11.04,g ++ 4.5.2):

#include <curses.h>
#include <unistd.h>
#include <iostream>
int main() {
    initscr();
    mvaddstr(10, 10, "Hello, world");
    refresh();
    sleep(4);
    endwin();
    std::cout << "DONE\n";
}

It clears the screen, prints "Hello, world" at the expected position, sleeps for 4 seconds, then restores the screen and prints "DONE".

它清除屏幕,在预期位置打印“Hello,world”,睡眠4秒钟,然后恢复屏幕并打印“DONE”。

As was mentioned in comments, if boxmessage() uses ncurses, it's not going to work after you call endwin().

正如在评论中提到的,如果boxmessage()使用ncurses,那么在调用endwin()之后它就无法工作。

Try adding some code after endwin() that creates and writes to a file, just to verify that your program doesn't die right there.

尝试在创建和写入文件的endwin()之后添加一些代码,只是为了验证您的程序是否在那里死亡。

Update (nearly 16 months later), quoting the OP's most recent comment:

更新(近16个月后),引用OP的最新评论:

OK, I found the bug. It was just because I made a series of buttons, then I did the 'case: x' part, and I just didn't write the integer that calls the function correctly. Thanks for trying to help!

好的,我发现了这个bug。这只是因为我制作了一系列按钮,然后我做了'case:x'部分,我只是没有写出正确调用函数的整数。感谢您的帮助!

#1


4  

endwin() isn't terminating your program; something else must be doing so.

endwin()不会终止你的程序;别的东西必须这样做。

This program works correctly on my system (Ubuntu 11.04, g++ 4.5.2):

这个程序在我的系统上正常工作(Ubuntu 11.04,g ++ 4.5.2):

#include <curses.h>
#include <unistd.h>
#include <iostream>
int main() {
    initscr();
    mvaddstr(10, 10, "Hello, world");
    refresh();
    sleep(4);
    endwin();
    std::cout << "DONE\n";
}

It clears the screen, prints "Hello, world" at the expected position, sleeps for 4 seconds, then restores the screen and prints "DONE".

它清除屏幕,在预期位置打印“Hello,world”,睡眠4秒钟,然后恢复屏幕并打印“DONE”。

As was mentioned in comments, if boxmessage() uses ncurses, it's not going to work after you call endwin().

正如在评论中提到的,如果boxmessage()使用ncurses,那么在调用endwin()之后它就无法工作。

Try adding some code after endwin() that creates and writes to a file, just to verify that your program doesn't die right there.

尝试在创建和写入文件的endwin()之后添加一些代码,只是为了验证您的程序是否在那里死亡。

Update (nearly 16 months later), quoting the OP's most recent comment:

更新(近16个月后),引用OP的最新评论:

OK, I found the bug. It was just because I made a series of buttons, then I did the 'case: x' part, and I just didn't write the integer that calls the function correctly. Thanks for trying to help!

好的,我发现了这个bug。这只是因为我制作了一系列按钮,然后我做了'case:x'部分,我只是没有写出正确调用函数的整数。感谢您的帮助!