From 33c03cf6fcfe066784b5b9f5cd9755cf9343efc5 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Sat, 26 Nov 2016 18:40:50 +0100 Subject: [PATCH] Optimized the terminal clear screen --- test/opti-move.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/opti-move.cpp b/test/opti-move.cpp index 8e693644..97aac4be 100644 --- a/test/opti-move.cpp +++ b/test/opti-move.cpp @@ -9,7 +9,7 @@ static FVTerm* terminal; // function prototype -void keyPressed(); +bool keyPressed(); void term_boundaries (int&, int&); void move (int, int, int, int); @@ -17,18 +17,25 @@ void move (int, int, int, int); //---------------------------------------------------------------------- // functions //---------------------------------------------------------------------- -void keyPressed() +bool keyPressed() { // Waiting for keypress struct termios save, t; + bool ret; std::cout << "\nPress any key to continue..."; fflush(stdout); tcgetattr (STDIN_FILENO, &save); t = save; t.c_lflag &= uInt(~(ICANON | ECHO)); tcsetattr (STDIN_FILENO, TCSANOW, &t); - getchar(); + + if ( std::getchar() != EOF ) + ret = true; + else + ret = false; + tcsetattr (STDIN_FILENO, TCSADRAIN, &save); + return ret; } //----------------------------------------------------------------------