1

Im trying to edit a program that capture user input. My intention is to add a function counting to a certain time. When it meet a timeout, a popup should be displayed. After that, the user should see back its previous shell/display. My problem is:

If the popup appear while the user are running vi, the display in that vi mode are hidden after the popup are destroyed.

Expectation: the user should have the same display as before the popup

before popup Before the popup appear

after popup After the popup destroyed

If the user are writing in a shell, it does not display the bash name (I do not know what its called. eg. fikrie@fikrie-VirtualBox:~/mysoftware/src$).

Expectation: the user should see the same display as before.

does not display bash name at the top line, the command (id) is displayed without bash name. I need to make the display same as the third line.

Im writing the code in C language and I'm using cdk library(ncurses) to do the popup. This is the function that create the popup.

int call_warning(struct tm *warning_display)
{
    char *mesg[4];
    WINDOW *cursesWin;
    CDKSCREEN *cdkscreen;
    char *buttons[1]  = { "[ OK ]" };
    char enddatetime[1024];

    strftime(enddatetime, sizeof(enddatetime), "%d-%m-%Y %I:%M:%S%p", warning_display);

    mesg[0] = "<C>----------------------";
    mesg[1] = "<C>Your timeout is near";
    mesg[2] = enddatetime;
    mesg[3] = "<C>----------------------";

    //I have tried using def_shell_mode() here
    cursesWin = initscr();
    cdkscreen = initCDKScreen(cursesWin);
    initCDKColor();

    while (1) {
            popupDialogWithColor(cdkscreen, mesg, 4, buttons, 1, "</2>");
            destroyCDKScreen(cdkscreen);
            werase(cursesWin);
            wrefresh(cursesWin);
            endCDK();
            endwin();
            break;
    }
    //I tried using reset_shell_mode() here and removing system("clear");
    system("clear"); //tried using refresh() as well. Didnt do the job
    return 0;
}

From what i read in the manual guide, the def_shell_mode() will save the prior terminal settings so they can be restored during the call to endwin(). I tested using that but it doesnt solve my problem. I did google on how to clear screen using C. From the result, its either use curse or termios. I dont think termios is a good approach because I want to let the user continue its previous session and not making a new one. So my only option is curses. Is there any function in ncurses that can do this?

EDIT: After a few days trying, I found out CDK is the one causing problem. So I change my code to use curses function instead. The idea to do it is here.

How do you clear console screen in C? How to clear screen from simple C program?

Community
  • 1
  • 1
Mohd Fikrie
  • 197
  • 4
  • 21
  • Terminal-settings do not include the contents of the screen (they refer to settings which you can manipulate with `stty`). There is no portable way to restore the screen contents. – Thomas Dickey Apr 14 '15 at 09:17
  • @ThomasDickey. Thank you. I will put an update here if found anything helpful from stty. – Mohd Fikrie Apr 14 '15 at 09:23

0 Answers0