0

Here is my code:

#include <ncurses.h>
#include <string.h>
int main() {
    char str[120];
    char c;
    while (1) {
        printf("%s", ">");
        scanf("%s", str);
        if (!strcmp(str, "open")) {
            initscr();
            c=getch();
            endwin();
            printf("from curses window %c\n",c);
        }
        printf("%s\n", str);
    }
    return 0;
}

I have a while(1) loop that always prints whatever it gets from screen.

If you input "open", it will open a curses window, and get a char. After that it will exit the curses window (endwin()), and should still be in the while(1) loop.

But my problem is that after calling endwin() it won't go back to the normal printf()/scanf() loop.

Kev
  • 118,037
  • 53
  • 300
  • 385
bill
  • 1
  • This might help: http://stackoverflow.com/questions/4772061/curses-library-c-getch-without-clearing-screen – Kev Dec 01 '11 at 18:37

1 Answers1

0
#include <stdio.h>
#include <curses.h>
#include <term.h>
#include <string.h>
#include <stdlib.h>

int main() {
    char str[120];
    char c;
    FILE *file_id;
    while (1) {
        printf("%s", ">");
        scanf("%s", str);
        if (!strcmp(str, "open")) {
            file_id = fopen("/dev/tty", "r+");
            SCREEN *termref = newterm(NULL, file_id, file_id);
            //cbreak();
            echo();
            keypad(stdscr, TRUE);
            getstr(str);
            delscreen(termref);
            printf("from curses window %s\n", str);
        }
        printf("%s\n", str);
    }
    return 0;
}

now the source code upgrade to this, and still have two problem

1, after open and close the term once, it can back to the normal loop, but when I press enter, the promt will not align on the left side, it will be like this,

user@linux>
           user@linux>
                      user@linux>

2, i can type in "open" again , to open a new term again , but the new term is still in the same localtion as the term created when i inputted the "open" in the first time, actually , everytime i input open , a term will be created at the same place , that means the command behind first open will disapear.

bill
  • 1