简体   繁体   English

Ccurses程序结束后如何使屏幕恢复正常

[英]C How to return screen to normal after curses program ends

I'm still new to C and ncurses.我还是 C 和 ncurses 的新手。 I was asked to do an assignment that involved making a multithreaded pong game.我被要求做一个涉及制作多线程乒乓球游戏的任务。 The game runs fine and ends with the correct lossing conditions but upon termination my terminal is all messed up.游戏运行良好,并以正确的失败条件结束,但在终止时我的终端全乱了。 I get no echo, so I have to type stty echo to get that back, even then the terminal behaves strangely.我没有得到回声,所以我必须输入stty echo才能得到它,即使终端表现得很奇怪。

My end function is the following:我的最终功能如下:

void wrap_up(){

    curs_set(1);
    clear();
    endwin();
    refresh();
}

Here is a screenshot.这是一个屏幕截图。 How do I fix it?我如何解决它?

在此处输入图像描述

Remove refresh after endwin. 在endwin之后删除刷新。 Calling refresh after endwin causes the program to go back into the curses mode. 在endwin之后调用刷新会导致程序返回到curses模式。

Well, it depends on how you want to implement it. 嗯,这取决于你想要如何实现它。 To make it portable you might want to implement compiling directives to clear the screen depending on what OS you're working on. 为了使其可移植,您可能希望实现编译指令以根据您正在使用的操作系统清除屏幕。

Eg: 例如:

void Refresh(){
#ifdef WIN_32_OS
  system("cls");
#elif LINUX_OS
  system("clear");
#else // (DOS, for example)
  system("Another command");
#endif
}

So in the compiling time you can use something like that: 所以在编译时你可以使用类似的东西:

bash2.2$ gcc -c -DLINUX_OS code.c -o code bash2.2 $ gcc -c -DLINUX_OS code.c -o code

只需运行“重置”cmd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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