简体   繁体   中英

How can I end ncurses without ending the C++ program?

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):

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

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

This program works correctly on my system (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".

As was mentioned in comments, if boxmessage() uses ncurses, it's not going to work after you call 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.

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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