2011-12-01 73 views
0

後,這裏是我的代碼:如何回到正常模式關閉的詛咒窗口

#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; 
} 

我有一個while(1)循環,始終打印不管它從屏幕獲取。

如果輸入「open」,它會打開一個curses窗口,並得到一個char。之後,它將退出詛咒窗口(endwin()),並應該仍在while(1)循環中。

但我的問題是,在撥打endwin()後,它不會回到正常的printf()/scanf()循環。

+0

這可能有所幫助:http://stackoverflow.com/questions/4772061/curses-library-c-getch-without-clearing-screen – Kev

回答

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; 
} 

現在的源代碼升級到這一點,還有兩個問題

1,打開後,一旦關閉項,就可以恢復到正常循環,但是當我按下回車,PROMT不會在左邊對齊,這將是這個樣子,

[email protected]> 
      [email protected]> 
         [email protected]> 

2,我可以鍵入「打開」了,再次打開了一個新名詞,但新學期仍然在同一當前位置爲當我第一次輸入「開放」時創建的術語,實際上,每次我都會使用 輸入開放,一個術語將在同一個地方創建,這意味着首先打開的命令將消失。