Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

linux

ncurses

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);
like image 323
MiJyn Avatar asked Dec 04 '11 23:12

MiJyn


1 Answers

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!

like image 67
Keith Thompson Avatar answered Sep 28 '22 22:09

Keith Thompson