Skip to content

Commit 33c03cf

Browse files
committed
Optimized the terminal clear screen
1 parent 1895dc0 commit 33c03cf

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

test/opti-move.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,33 @@
99
static FVTerm* terminal;
1010

1111
// function prototype
12-
void keyPressed();
12+
bool keyPressed();
1313
void term_boundaries (int&, int&);
1414
void move (int, int, int, int);
1515

1616

1717
//----------------------------------------------------------------------
1818
// functions
1919
//----------------------------------------------------------------------
20-
void keyPressed()
20+
bool keyPressed()
2121
{
2222
// Waiting for keypress
2323
struct termios save, t;
24+
bool ret;
2425
std::cout << "\nPress any key to continue...";
2526
fflush(stdout);
2627
tcgetattr (STDIN_FILENO, &save);
2728
t = save;
2829
t.c_lflag &= uInt(~(ICANON | ECHO));
2930
tcsetattr (STDIN_FILENO, TCSANOW, &t);
30-
getchar();
31+
32+
if ( std::getchar() != EOF )
33+
ret = true;
34+
else
35+
ret = false;
36+
3137
tcsetattr (STDIN_FILENO, TCSADRAIN, &save);
38+
return ret;
3239
}
3340

3441
//----------------------------------------------------------------------

0 commit comments

Comments
 (0)